Bookmark and Share

Thursday, July 16, 2009

Quick and Dirty Performance Testing With Apache Bench

If you need a quick and dirty way to throw some load onto a load balancer/ADC or web server, Apache comes with a great tool called Apache Bench.  Since it's an HTTP client, it will of course work with any server, not just Apache-based servers.

Typically, Apache Bench (ab) is installed with the base Apache install, from at least Apache 1.3 on.  This includes when Apache is installed on Windows.

You can check all of the available options on the ab documentation page, but here's a (very) quick reference to using it.

Two of the most important options are "-n" for the number of total connections, and "-c" for how many concurrent connections are done at the same time.

For instance, using the option "-n 1000″ will do 1,000 requests, one at a time, to a target URL.

ab -n 1000 http://website.com/

One at a time is rarely an effective test, so it's best to use the "-c" option to specify a high number of concurrent connections, such as 100.

ab -n 1000 -c 100 http://website.com/

If you use concurrency, ab will split the total number of requests up amongst the concurrent settings.  For instance, using the option "-n 1000″ will do 1,000 connections, but "-n 2000 -c 100″ will only do 20 requests from 100 different connections (2,000 / 100 = 20).  So it's best to use a much larger number of total connections if you're doing concurrency.

ab -n 100000 -c 100 http://website.com/

When ab is finished running, it will spit out a performance report, including such info as the time taken for tests, requests per second, wait time, etc.

Finished 1000 requests

Server Software: Apache/2.2.9
Server Hostname: localhost
Server Port: 80

Document Path: /
Document Length: 45 bytes

Concurrency Level: 10
Time taken for tests: 0.427 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 320640 bytes
HTML transferred: 45090 bytes
Requests per second: 2341.45 [#/sec] (mean)
Time per request: 4.271 [ms] (mean)
Time per request: 0.427 [ms] (mean, across all concurrent requests)
Transfer rate: 733.17 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 0.4 2 3
Processing: 0 2 0.5 2 7
Waiting: 0 2 0.5 2 6
Total: 0 4 0.7 4 8

Percentage of the requests served within a certain time (ms)
50% 4
66% 4
75% 5
80% 5
90% 5
95% 5
98% 5
99% 5
100% 8 (longest request)

The ab utility defaults to one request per TCP connection (KeepAlive turned off).  If you want to use KeepAlive, where multiple requests are made through a TCP connection, use the "-K" option, open up as many TCP connections as you specify in concurrency ("-c") and make the total number of quests through those few open TCP connections.

The utility is a simple but power tool for testing load balancers and web servers.  It doesn't tend to reflect real-world usage, but it can be useful for baseline testing and troubleshooting.  I've found it quite useful over the years.

No comments:

More Magazines