May 3, 2011

Simple web server load testing

I recently ran into ab, which is an Apache HTTP server benchmarking tool. The following is an invocation where I'm running a load test on a local tomcat instance which is using 1000 requests with 10 concurrent threads.

mike@shiner $ ab -n 1000 -c 10 http://localhost:8080/test-ui/
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 localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache-Coyote/1.1
Server Hostname:        localhost
Server Port:            8080

Document Path:          /test-ui/
Document Length:        7891 bytes

Concurrency Level:      10
Time taken for tests:   13.262 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      8054000 bytes
HTML transferred:       7891000 bytes
Requests per second:    75.40 [#/sec] (mean)
Time per request:       132.624 [ms] (mean)
Time per request:       13.262 [ms] (mean, across all concurrent requests)
Transfer rate:          593.05 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.6      0      12
Processing:     5  132 349.6     28    3087
Waiting:        5  130 349.4     26    3087
Total:          5  132 349.7     28    3087

Percentage of the requests served within a certain time (ms)
  50%     28
  66%     84
  75%    145
  80%    168
  90%    264
  95%    376
  98%   1450
  99%   2412
 100%   3087 (longest request)

The tool has a lot of really great features and I'll try to exemplify some of them here. The following shows how you can change the User-Agent to a variant of Internet Explorer (thanks goes to www.useragentstring.com for the value). I've also set the verbosity level to 4 so I can verify the 'User-Agent' value is set as intended. I've excluded the output for brevity.

mike@shiner $ ab  -v 4 -H "User-Agent: Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)"   http://localhost:8080/test-ui/

Next is an example where I set the value of a cookie. I run into situations where I need to evaluate code for cell testing. It happens to be that our cell testing code is dependent on cookie values.

mike@shiner $ ab -n 1000 -c 10 -C "cellNum=10"  http://localhost:8080/test-ui/

The following is an example of setting the -G flag, which will output a file named 'perf.out' which can be used with GnuPlot. The file doesn't have to be used with just GnuPlot. It can also be used with IDL, Mathematica, Igor, and Excel.

mike@shiner $ ab -n 1000 -c 10 -G perf.out http://localhost:8080/test-ui/