Closed Abhijeet104 closed 4 years ago
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord
Was unable to open discord site. so had to post it here.
can confirm, the invite seems to have expired.
Welcome @Abhijeet104!
Both are relatively fast/equal when it comes to local benchmarking because you will hit your OS limit relatively soon. You have to watch out that your benchmarking tool does not use more CPU than your Go process.
The biggest difference between Fiber and net/http is the memory allocation, Fasthttp uses a worker pool with efficient parsing methods where net/http spawns a new go routine and allocates memory on each connection.
This difference is clearly visible with the techempower benchmarks where they use a Switched 10-gigabit ethernet pipe on a separate machine for benchmarking to replicate a real-world environment.
64 conns
fiber : TotalAlloc = 2 MiB Sys = 12 MiB NumGC = 0
net/http: TotalAlloc = 1599 MiB Sys = 17 MiB NumGC = 229
// fiber
Running 10s test @ http://192.168.1.131:3000
6 threads and 64 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 424.00us 160.78us 12.82ms 82.37%
Req/Sec 23.03k 825.05 27.99k 72.73%
1386015 requests in 10.10s, 202.24MB read
Requests/sec: 137229.86
Transfer/sec: 20.02MB
// net/http
Running 10s test @ http://192.168.1.131:3001
6 threads and 64 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 515.06us 302.11us 10.19ms 88.70%
Req/Sec 19.95k 0.87k 23.85k 70.91%
1200295 requests in 10.10s, 154.53MB read
Requests/sec: 118842.31
Transfer/sec: 15.30MB
2500 conns
fiber : TotalAlloc = 13 MiB Sys = 30 MiB NumGC = 3
net/http: TotalAlloc = 2652 MiB Sys = 46 MiB NumGC = 829
// fiber
Running 20s test @ http://192.168.1.131:3000
6 threads and 2500 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 7.84ms 22.06ms 989.74ms 98.33%
Req/Sec 33.61k 16.54k 66.85k 59.90%
3344237 requests in 20.04s, 440.13MB read
Requests/sec: 166855.80
Transfer/sec: 21.96MB
// net/http
Running 20s test @ http://192.168.1.131:3001
6 threads and 2500 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 8.25ms 5.20ms 330.37ms 95.68%
Req/Sec 20.76k 8.05k 47.92k 44.25%
2478725 requests in 20.01s, 347.49MB read
Socket errors: connect 1481, read 0, write 0, timeout 0
Requests/sec: 123852.68
Transfer/sec: 17.36MB
So in a real-world scenario, your net/http server could run out of memory on high loads and be throttled. Where Fiber will keep serving requests because of the low memory footprint, this is exactly where Fasthttp was designed for.
PS: our discord invite link seems to be valid, could you try https://discord.gg/bSnH7db?
> bombardier -c 245 127.0.0.1:3000
Bombarding http://127.0.0.1:3000 for 10s using 245 connection(s)
[==========================================================================] 10s
Done!
Statistics Avg Stdev Max
Reqs/sec 132211.02 8799.84 155085.90
Latency 1.85ms 152.64us 16.53ms
HTTP codes:
1xx - 0, 2xx - 1322000, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 24.84MB/s
2020/10/04 22:40:59 Alloc = 3 MiB TotalAlloc = 3 MiB Sys = 69 MiB NumGC = 0
> bombardier -c 245 127.0.0.1:3002
Bombarding http://127.0.0.1:3002 for 10s using 245 connection(s)
[==========================================================================] 10s
Done!
Statistics Avg Stdev Max
Reqs/sec 119381.83 17016.99 153692.31
Latency 2.05ms 344.36us 36.02ms
HTTP codes:
1xx - 0, 2xx - 1193836, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 22.43MB/s
2020/10/04 22:42:04 Alloc = 5 MiB TotalAlloc = 1602 MiB Sys = 70 MiB NumGC = 542
🙇🏻♀️
Default net/http gives me 16k TPS with 100% success, but fiber fails(~98% success) at 10k TPS for normal Hello World API Calls. How some of the benchmarks show it as better than http/net? 🤔
Code snippet Optional
Tested above code with sample code from fiber's git read me section. Tested using vegeta for 1m, with above rate, on same machine MAC book pro(16GB RAM, 12 cores)