Skip to content

Commit a5c9a4e

Browse files
committed
chore: cleanup
1 parent f2f9bc9 commit a5c9a4e

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ run:
1111
export LOG_LEVEL=INFO && make build && ./bin/numero
1212

1313
format:
14-
golines -w .
14+
golines -w .
15+
16+
bench:
17+
go run benchmark/main.go

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77

88
`numero` is software for parsing and evaluating mathematical expressions. It is available as a library and as a web service.
99

10-
## motivation
11-
12-
This project started as an exercise in doing some recreational programming. I always knew about the [shunting yard algorithm](https://en.wikipedia.org/wiki/Shunting_yard_algorithm) but never really got to implement it. Lately, I've been writing a lot of code in Go and decided to just do this.
13-
1410
## usage
1511

1612
The library can be used as follows.
@@ -59,6 +55,7 @@ curl --request POST \
5955
## documentation
6056

6157
**Supported functions**
58+
6259
- `sin`
6360
- `cos`
6461
- `tan`
@@ -69,6 +66,7 @@ curl --request POST \
6966
- `min`
7067

7168
**Supported operators**
69+
7270
- `+`
7371
- `-`
7472
- `*`
@@ -95,6 +93,25 @@ Response body:
9593
}
9694
```
9795

96+
### benchmarks
97+
98+
This runs a load test for 20 seconds. The test can be found [here](./benchmark/main.go). The tests were run on a 2021 Macbook Pro with an M1 chip.
99+
100+
```bash
101+
make bench
102+
```
103+
| metric | value |
104+
|---------------|---------|
105+
| total requests| 30878 |
106+
| successful requests| 30878|
107+
| failed requests | 688 |
108+
| connection errors| 688 |
109+
| invalid responses| 0 |
110+
| average latency | 1.02 ms|
111+
| min latency | 0.06 ms|
112+
| max latency | 36.12 ms|
113+
| requests/second | 1543|
114+
98115
## contributing
99116

100117
I am happy to accept pull requests. No hard rules.
@@ -113,6 +130,10 @@ make test
113130
make run-dev
114131
```
115132

133+
## motivation
134+
135+
This project started as an exercise in doing some recreational programming. I always knew about the [shunting yard algorithm](https://en.wikipedia.org/wiki/Shunting_yard_algorithm) but never really got to implement it. Lately, I've been writing a lot of code in Go and decided to just do this.
136+
116137
## acknowledgements
117138

118139
created by Vivek Nathani ([@viveknathani_](https://twitter.com/viveknathani_)), licensed under the [MIT License](./LICENSE).

benchmark/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ func main() {
170170
BaseURL: *baseURL,
171171
}
172172

173-
fmt.Printf("starting benchmark with %d concurrent users for %v\n", config.NumConcurrent, config.Duration)
174-
fmt.Printf("target URL: %s\n\n", config.BaseURL)
173+
fmt.Printf("running benchmark for %v\n", config.Duration)
175174

176175
stats := runBenchmark(config)
177176

main.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,38 +52,35 @@ func main() {
5252
nlog.Info("hello from numero!")
5353

5454
PORT := "8084"
55-
// Configure Fiber with optimized settings
55+
5656
app := fiber.New(fiber.Config{
57-
Prefork: true, // Uses multiple processes
58-
ServerHeader: "Numero",
57+
Prefork: true,
58+
ServerHeader: "numero",
5959
ReadTimeout: 5 * time.Second,
6060
WriteTimeout: 5 * time.Second,
6161
IdleTimeout: 10 * time.Second,
62-
BodyLimit: 4 * 1024, // 4KB - adjust based on your needs
63-
Concurrency: 256 * 1024, // Max concurrent connections
62+
BodyLimit: 4 * 1024,
63+
Concurrency: 256 * 1024,
6464
})
6565

66-
// Add middlewares
6766
app.Use(recover.New())
67+
6868
app.Use(compress.New(compress.Config{
6969
Level: compress.LevelBestSpeed,
7070
}))
71+
7172
app.Use(cors.New(cors.Config{
7273
AllowOrigins: "*",
7374
}))
7475

75-
// Serve README.md as HTML at root
7676
app.Get("/", func(c *fiber.Ctx) error {
77-
// Read README.md
7877
md, err := os.ReadFile("README.md")
7978
if err != nil {
8079
return sendStandardResponse(c, fiber.StatusInternalServerError, nil, "failed to read README.md")
8180
}
8281

83-
// Convert markdown to HTML
8482
html := markdown.ToHTML(md, nil, nil)
8583

86-
// Add basic styling with HTML template
8784
template := `<!DOCTYPE html>
8885
<html>
8986
<head>
@@ -117,11 +114,9 @@ func main() {
117114
})
118115

119116
app.Post("/api/v1/eval", func(c *fiber.Ctx) error {
120-
// Get request object from pool
121117
req := evalPool.Get().(*EvalRequest)
122118
defer evalPool.Put(req)
123119

124-
// Reset request fields
125120
req.Expression = ""
126121
req.Variables = nil
127122

0 commit comments

Comments
 (0)