Recipe 11.2 Benchmarking Apache with ab
You want to benchmark changes that you are making to verify that they are in fact making a difference in performance.
Use ab (Apache bench), which you will find in the bin directory of your Apache installation:
ab -n 1000 -c 10 http://www.example.com/test.html
is a command-line utility that comes with Apache and lets you do very basic performance testing of your server. It is
The arguments given in the previous example tell
to request the resource
Other arguments that may be specified can be seen by running ab with the -h flag. Of particular interest is the -k flag, which enables keepalive mode. See the following keepalive recipe for additional details on this matter.
There are a few things to note about ab when using it to evaluate performance.
You should probably not run the web server and ab on the same machine, as this will introduce more uncertainty into the measurement. With both ab and the web server itself consuming system resources, you will receive significantly slower performance than if you were to run ab on some other machine, accessing the server over the network. However, also be aware that running ab on another machine will introduce network latency, which is not present when running it on the same machine as the server.
Finally, there are many factors that can affect performance of the server, and you will not get the same
Finally, you need to understand that, while ab gives you a good idea of whether certain changes have improved performance, it does not give a good simulation of actual users. Actual users don't simply fetch the same resource repeatedly, but they obtain a variety of different resources from various places on your site. Thus, actual site usage conditions may produce different performance issues than those revealed by ab .
Recipe 11.3 Tuning Keepalive Settings
You want to tune the keepalive-
KeepAlive On MaxKeepAliveRequests 0 KeepAliveTimeout 15
The default behavior of HTTP is for each document to be
In addition to turning keepalive on, using the KeepAlive directive, there are two directives that allow you to adjust the way that it is done.
The first of these, MaxKeepAliveRequests , indicates how many keepalive requests should be permitted over a single connection. There is no reason to have this number set low. The default value for this directive is 100, and this seems to work pretty well for most sites. Setting this value to 0 means that an unlimited number of requests will be permitted over a single connection. This might allow users to load all of their content from your site over a single connection, depending on the value of KeepAliveTimeout and how quickly they went through the site.
indicates how long a particular connection will be held
You should also be aware that if users load a resource from your site and then go away, Apache will still maintain that open connection for them for KeepAliveTimeout seconds, which makes that child process unable to serve any other requests during that time. Therefore, setting KeepAliveTimeout too high is just as undesirable as setting it too low.
In the event that KeepAliveTimeout is set too high, you will see ( i.e ., with the server-status handler -see Recipe 11.4) that a significant number of processes are in keepalive mode, but are inactive. Over time, this number will continue to grow, as more child processes are spawned to take the place of child processes that are in this state.
too low will result in conditions similar to having
turned off entirely, when a single client will require many connections over the course of a brief visit. This is less easy to detect than the
Since the length of time that any given