Why does a simple Thin server stop responding at 16500 requests when benchmarking?
I'll add the solution here for claritys sake. The correct solution for managing to do high frequency tests with ab on os X is to change the 'net.inet.tcp.msl' setting from 15000ms to 1000ms. This should only be done on development boxes.
sudo sysctl -w net.inet.tcp.msl=1000 # this is only good for local development
This answer was found after the good detective work performed in the comments here and comes from an answer to a very similar question here's the answer: https://stackoverflow.com/a/6699135/155031
ab' program freezes after lots of requests, why?
It sounds like you are running out of ephemeral ports. To check, use the netstat
command and look for several thousand ports in the TIME_WAIT
state.
On Mac OS X the default ephemeral port range is 49152 to 65535, for a total of 16384 ports. You can check this with the sysctl
command:
$ sysctl net.inet.ip.portrange.first net.inet.ip.portrange.last
net.inet.ip.portrange.first: 49152
net.inet.ip.portrange.last: 65535
Once you run out of ephemeral ports, you will normally need to wait until the TIME_WAIT
state expires (2 * maximum segment lifetime) until you can reuse a particular port number. You can double the number of ports by changing the range to start at 32768, which is the default on Linux and Solaris. (The maximum port number is 65535 so you cannot increase the high end.)
$ sudo sysctl -w net.inet.ip.portrange.first=32768
net.inet.ip.portrange.first: 49152 -> 32768
Note that the official range designated by IANA is 49152 to 65535, and some firewalls may assume that dynamically assigned ports fall within that range. You may need to reconfigure your firewall in order to make use of a larger range outside of your local network.
It is also possible to reduce the maximum segment lifetime (sysctl net.inet.tcp.msl
on Mac OS X), which controls the duration of the TIME_WAIT
state, but this is dangerous as it could cause older connections to get mixed up with newer ones that are using the same port number. There are also some tricks involving binding to specific ports with the SO_REUSEADDR
option, or closing with the SO_LINGER
option, but those also could cause old and new connections to be mixed up, so are generally considered to be bad ideas.
ab is erroring out with apr_socket_recv: Connection refused (61)
I found using 127.0.0.1 rather than localhost worked:
ab -n 10 -c 1 http://127.0.0.1:8090/
Update:
May have been a bug in ab: https://groups.google.com/forum/#!msg/nodejs/TZU5H7MdoII/yivu0d4LMaAJ
Related Topics
Undefined Method Pluralize for Main:Object
Create a Tempfile Without Opening It in Ruby
Rails Script Segmentation Fault with Rvm
Graphql::Client::Dynamicqueryerror Expected Definition to Be Assigned to a Static Constant
How to Use Us-Style Dates in Rails Using Ruby 1.9
Is Subclassing a User Model Really Bad to Do in Rails
Troubles with Ruby-2.X Installation Using Rvm
Why Does Hash.New({}) Hide Hash Members
How to Handle Utf-8 Email Headers (Like Subject:) Using Ruby
How to Find All Modules and Classes Within a Module, Recursively
Commonmarker Gem Cannot Be Installed (Needed for Jekyll) MACos
Why Would You Use a !! Operator
Rails: Undefined Method 'Truncate' in Model
Extending a Class Method in a Module
Install Ruby 2.2 on MAC Osx Catalina with Ruby-Install