You are viewing chrismiles

Previous Entry | Next Entry

Variable requests for Apache Bench (ab)

venture, dean
I've been using ab (ApacheBench - comes with Apache httpd) lately to do some performance benchmarking of our internal web services at work. It is nice & simple to use, but unfortunately it is limited to only requesting the same URL over and over. For some services, such as a search engine that normally receives different query parameters with every request, this does not really represent reality.

I have created a patch for ab that gives it a new option (-R). This allows you to specify a file and ab will append lines from the file to the base URL for every request, in the order they are read from the file. If ab reaches the end of the file before the test is finished it will return to the first line and repeat them all.

An example explains this better.

Out of the box you may use ab to benchmark the speed of your site's search:
$ ab -n 5000 http://www.something/search?q=ipod

This will cause ab to send 5000 requests to the specified URL. Handy, but it is testing the same query over & over, which is not what the site would see in practice.

Instead, you could use the -R patch, by first creating a file (let's call it requests.txt) containing something like:
ipod
apple+iphone
apple+ipod
dvd+player

and running ab with:
$ ab -n 5000 -R requests.txt http://www.something/search?q=

As ab constructs a query it will fetch the next line from requests.txt and append it to the base URL and that becomes the query to use for that request. In this example it would query the URLs:
http://www.something/search?q=ipod
http://www.something/search?q=apple+iphone
http://www.something/search?q=apple+ipod
http://www.something/search?q=dvd+player
http://www.something/search?q=ipod
http://www.something/search?q=apple+iphone
http://www.something/search?q=dvd+player

and so on.

This is much more useful, at least for the types of benchmarks I want to do.

You can find the ab patch here.

Latest Month

March 2009
S M T W T F S
1234567
891011121314
15161718192021
22232425262728
293031    
Powered by LiveJournal.com
Designed by Tiffany Chow