Skip to content

Instantly share code, notes, and snippets.

@kutata
Last active May 20, 2019 08:12
Show Gist options
  • Save kutata/ed59a2f7135bd6d2fb2b4b7557b3d389 to your computer and use it in GitHub Desktop.
Save kutata/ed59a2f7135bd6d2fb2b4b7557b3d389 to your computer and use it in GitHub Desktop.
testing
In short, you're running out of ports.
The default ephemeral port range on osx is 49152-65535, which is only 16,383 ports.
Since each ab request is http/1.0 (without keepalive in your first examples), each
new request takes another port.
As each port is used, it get's put into a queue where it waits for the tcp
"Maximum Segment Lifetime", which is configured to be 15 seconds on osx. So if you
use more than 16,383 ports in 15 seconds, you're effectively going to get throttled
by the OS on further connections. Depending on which process runs out of ports first,
you will get connection errors from the server, or hangs from ab.
You can mitigate this by using an http/1.1 capable load generator like wrk, or using
the keepalive (-k) option for ab, so that connections are reused based on the tool's
concurrency settings.
Now, the server code you're benchmarking does so little, that the load generator is
being taxed just as much as the sever itself, with the local os and network stack
likely making a good contribution. If you want to benchmark an http server, it's better
to do some meaningful work from multiple clients not running on the same machine.
-- from stackoverflow JimB's answer
https://stackoverflow.com/questions/30352725/why-is-my-hello-world-go-server-getting-crushed-by-apachebench
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment