Performance Benchmark a Web Server Using Apache ab

Apache Benchmark

ApacheBench (ab) – Apache Benchmark – is a single-threaded command line tool for measuring the performance of a HTTP web server. It gives you an impression of how many requests per second your server is capable of serving. Like Apache Web Server itself, it’s free, open source software and distributed under the terms of the Apache License. In this tutorial we will see how a server performs under load. The tutorial assumes that you have already installed Apache Benchmark which is by default installed on a MAC OS X. On linux you can install Apache Benchmark using  sudo aptitude install apache2-utils.

Running Apache Benchmark

This will run 400 requests in total with 100 concurrent requests to domain example.com.

ab -n 400 -c 100 -H "Accept-Encoding: gzip,deflate" http://example.com/
  •  You can increase the total number of requests. The number of requests should not exceed the number of concurrent requests.
  • With the -H option you can specify any header information you want to pass.
    • “Accept-Encoding: gzip, deflate” mimics the requests that a typical browser will send.
  • The -n option equals the total number of requests
  • The -c option equals the concurrent requests

Sample output

ab -q -k -n 400 -c 100 -g out.data -H "Accept-Encoding: gzip,deflate" http://example.com/ 
This is ApacheBench, Version 2.3 <$Revision: 1554214 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking example.com (be patient).....done


Server Software:        example.com
Server Hostname:        example.com
Server Port:            80

Document Path:          /
Document Length:        5094 bytes

Concurrency Level:      100
Time taken for tests:   1.973 seconds
Complete requests:      400
Failed requests:        0
Keep-Alive requests:    400
Total transferred:      2158000 bytes
HTML transferred:       2037600 bytes
Requests per second:    202.76 [#/sec] (mean)
Time per request:       493.183 [ms] (mean)
Time per request:       4.932 [ms] (mean, across all concurrent requests)
Transfer rate:          1068.28 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  103 326.9      0    1319
Processing:   102  151 130.5    118    1172
Waiting:      102  150 130.5    118    1172
Total:        102  253 412.2    120    1971

Percentage of the requests served within a certain time (ms)
  50%    120
  66%    125
  75%    151
  80%    181
  90%    256
  95%   1417
  98%   1914
  99%   1960
 100%   1971 (longest request)

Repeat above command 3-5 times and save the best reading.

Analysing the output

Couple of important observations:

  • The most important thing to take from this is the “requests per second”. This tells us how many requests per second our server can handle. In this case we can handle 202.76 requests per second which is ok if we know that our server has 512 MB of RAM and an average CPU.
  • “Failed requests” is zero, which is good. This means that our server can handle 400 request with 100 concurrent in 1.973 seconds. If you are seeing failed requests here then you know that your server is not able to handle the concurrent requests.
  • “Time per request” means how many milliseconds it takes to complete one request. In our case we can server a resource in 493.183 ms.
Every time you make changes to your server you can load test your server with apache benchmark to see if those changes have any affect.

Plotting the outcome

You can generate graph data with apache benchmark, more on this in the following tutorial: Using Gnuplot to plot Apache Benchmark data. Here’s an example graph:

References

You may also like...