If you’ve ever needed to benchmark (or load test) a webserver, you’ll be familiar with Apache Benchmark (ab), a brilliant tool that will hammer your webserver with lots of concurrent requests and give you statistics, histograms and and graphs—everything apart from how hot the server got! This is useful to determine when things like the network and webserver processes hit some limit or other, but for a modern web application it is of limited use, because more than likely you’ll end up requesting a cached page over and over again.
Chris Miles (possibly an old blog, as there haven’t been any posts since 2009) wrote a patch which allows ab to take a list of request suffixes generated in advance, cycling through them repeatedly while it does its thing. This means that, if you can generate a long enough list, you can really stress every part of your web app without having to write a custom load-testing script. It’s one of those things that I wish I’d found a long time ago. It would have saved me many lines of code.
I’m mentioning it here because Chris’s patch is for Apache 2.2.4, which is now a little long in the tooth, so the chances are that your machine is running something quite a bit more recent. As time goes on, the code base will drift away from the patch, making it increasingly difficult to apply. Happily the older version is still available, and the distribution can be used to build a much-improved version of ab.
For the impatient
If you can’t be bothered messing around with building things, I present for your convenience a statically linked ab binary for 64-bit Linux compiled against the Apache 2.2.4 distribution with Chris’s patch. There; now you can stop reading and get to work (unless you need SSL — in which case, read on).
For the control freak
If you really want to build it yourself (or maybe you have your own special patches), here’s what you do:
- Download Apache HTTPD 2.2.4 from Apache’s archive site
- Unpack the tar file and cd into it
- Apply Chris’s patch, or just download the patched file and drop it in place
- ./configure –with-included-apr –enable-static-ab –enable-ssl (the first option will ignore the more recent copy of apr that’ll be on your machine already, and the second will build a static binary—well, not completely static, but good enough to be independent)
- make (you can specify -jn where n is the number of processor cores you have; this will speed up the build a lot)
Your lovely new ab binary is now waiting for you in the ‘support’ directory.
I do hope this helped you out, and would love to get a comment or two if it did 🙂
inw
The search engines will love you all the more if you mention what platform your binary is for :).
flup
Oops, good point, thanks! Updated 🙂
shahzaib.cb
What if someone sending 1000 concurrent requests to our server by using ab tool just to make our server down ? How can i stop this attack ?
TheGingerDog
Thanks for the binary – just what this lazy man was after (seems to work fine on Debian Jessie)
Jff Frm
Thanks for the guide, I used this to port the patch to httpd 2.4.43 w/ ssl support
https://github.com/j3ffrw/httpd/tree/cache_buster/2.4/alpine