I’ve been knee deep in performance and scalability for some time now, and have used and learned of many useful tools and techniques to help out. One of my favorite command line tools for seeing how well a single Apache server is churning out pages in development comes stock on Ubuntu, and Mac OS X: Apache Benchmark.
A simple performance test against the homepage of one of my client site’s using AB at the command line:
ab -t5 -n100 http://www.teamgzfs.com/
The results:
This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.teamgzfs.com (be patient) Finished 664 requests Server Software: Apache/2.2.8 Server Hostname: www.teamgzfs.com Server Port: 80 Document Path: / Document Length: 306 bytes Concurrency Level: 100 Time taken for tests: 5.054 seconds Complete requests: 664 Failed requests: 0 Write errors: 0 Total transferred: 465003 bytes HTML transferred: 205326 bytes Requests per second: 131.38 [#/sec] (mean) Time per request: 761.143 [ms] (mean) Time per request: 7.611 [ms] (mean, across all concurrent requests) Transfer rate: 89.85 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 38 78 48.7 64 994 Processing: 114 540 226.2 493 1690 Waiting: 114 531 205.6 493 1485 Total: 191 618 236.0 558 1808 Percentage of the requests served within a certain time (ms) 50% 558 66% 587 75% 598 80% 617 90% 845 95% 1163 98% 1402 99% 1746 100% 1808 (longest request)
There is quite a bit of useful information here that can help you tune your code and server. It’s important to note however, that when working on a larger site, that expects quite a bit more traffic, you might want to investigate some more thorough solutions outside of just a single machine and ab. It is, however, a nice starting point into useful information.
One rather funny pitfall you can run into however, is if the host you are sending requests to is smartly secured – these types of tests become a bit useless, as they may have security settings to limit or delay requests – providing you with timeouts and/or inaccurate information. Best to run these types of things in a semi-developmental mode with those types of security settings turned down, and rely on bigger guns or fleets of boxes and scripts to hit a production secure site.
In addition to hitting just a landing page, you can use AB to send COOKIE or POST data too! This is very useful if you want to see how pages perform but need credentials to get in first. This is a little trickier to do using the -c, -T, -p, and -v flags. I noticed there are under-useful resources online to figuring it out with AB, so it would seem worthwhile to write it – as it took me some trickery to figuring it out as well:
Sending POST data to a login form:
First we create a file that contains our URL encoded post data. Note, AB expects the values to be URL encoded, but not the equal (=) or ampersands (&).
post_data.txt
username=foo%40bar.com&password=foobar
Capturing a cookie:
Here, we use the verbosity (-v) flag so we can see the response headers that come back — many sites will send back a cookie once authenticated, we’ll want to capture that cookie here. Though, some sites will not require it, I demonstrate it for the sake of example:
ab -v4 -n1 -T 'application/x-www-form-urlencoded' -p post_data.txt http://www.foobar.com/login
The returned response header will fly by quick, you’re looking for something like the following:
Set-cookie somesession=somerandomsessiondata...;
The session data may come back encrypted, unencrypted, a serialization, or just a number. That varies by site. The point here is you have a key/value pair for the cookie. All you need is the part up to the semi-colon ( not including the semi-colon ). Copy that “key=val” string, and use it when hitting other pages on the site you are testing, ie:
Using a cookie to test a page that requires a cookie:
ab -t10 -n100 -c 'somessession=somerandomsessiondata' http://www.foobar.com/login_required_page
This can become a lot of fun once you get the hang of it. Now you have the know how, go enjoy creating an arsenal of these scripts and start performance tuning your sites – or script hacking your favorite social network ( or obnoxious Blizzard clan website hahaha… drum roll for D3 – 2010? Please???! ).

Digg
Disqus
Facebook
Flickr
LinkedIn
MySpace
oDesk Profile
Twitter
YouTube!
February 5th, 2010 at 4:46 pm
Thanks you for you post, I gave me a very good start.
BTW, my question is if I have more than one key pair value cookies.
How is the commamnd should look like
c 'key1=val1' -c 'key2=val2' or -c 'key1=val1;key2=val2' ?
February 22nd, 2010 at 1:14 am
To pass multiple cookies, use multiple -c flags – as in your first example: “-c 'key1=val1' -c'key2=val2″
September 11th, 2010 at 11:00 pm
Benchmark Testing: Benchmark testing is a performance test which subjects the system to varying workloads to measure and evaluate the performance behaviors and ability of the system to continue to function properly under these different workloads.http://www.freecomputerrepairservices.com/software/common-computer-performance-testing-softwares.html
September 12th, 2010 at 3:00 am
Benchmark Testing: Benchmark testing is a performance test which subjects the system to varying workloads to measure and evaluate the performance behaviors and ability of the system to continue to function properly under these different workloads.http://www.freecomputerrepairs…
December 21st, 2011 at 3:14 am
Hi i tried to execute
ab -t10 -n100 -c ‘somessession=somerandomsessiondata’ http://www.foobar.com/login_required_page command but i got error as below
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking http://www.getsetmobile.com (be patient)…
Server timed out.
IF i run with simple query it working fine only for above query i got error . Ple help me out
December 21st, 2011 at 3:16 am
Hi i tried to execute
ab -t10 -n100 -c ‘somessession=somerandomsessiondata’ http://www.foobar.com/login_required_page command by using othere dummy site but i got error as below
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Server timed out.
IF i run with simple query it working fine only for above query i got error . Ple help me out