Celebrazio Net



Contact Us

Web Server Performance Testing with Apache Bench

November, 2009

It's installed with the most popular web server software on the Internet, still most webmasters don't even know it exists, or how it can benefit them. Introducing Apache Bench. Use it to load test your site, to send even a small number of queries to generate performance diagnostics against your site, or to test a variety of ways of serving.

Apache Bench: powerful, little-known web tool

  • Run Apache Bench against yourself (localhost). This eliminates network issues from the performance equation.
  • Use apache bench to test different code configurations. Try a test with Feature A enabled, and another test with it disabled.
  • Use Apache Bench at different hours of the day. Does your performance degrade during peak traffic? Maybe it's time to upgrade hardware or find a new ISP.
  • Run apache bench from a remote machine to test performance back to it. If you have a remote machine available, or can find one, find out where your server performance is hurting: connect (network), or processing (after connect).

Apache Bench Source Page: Apache HTTP Server home

Example of using Apache bench with concurrency of 3 (3 processes), and time of 5 minutes (300 seconds):

user@system-80% ab -c 3 -t 300
 "http://abc.mysite.net/file_path1/path2/other/filename.html"
This is ApacheBench, Version 1.3d <$Revision: 1.67 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/

Benchmarking abc.mysite.net (be patient)
Finished 3248 requests
Server Software:        Apache/1.3.27
Server Hostname:        abc.mysite.net
Server Port:            80

Document Path:          file_path1/path2/other/filename.html
Document Length:        1043 bytes

Concurrency Level:      3
Time taken for tests:   300.045 seconds
Complete requests:      3248
Failed requests:        2761
   (Connect: 0, Length: 2761, Exceptions: 0)
Broken pipe errors:     0
Total transferred:      3905103 bytes
HTML transferred:       3391761 bytes
Requests per second:    10.83 [#/sec] (mean)
Time per request:       277.14 [ms] (mean)
Time per request:       92.38 [ms] (mean, across all concurrent requests)
Transfer rate:          13.02 [Kbytes/sec] received

Connnection Times (ms)
              min  mean[+/-sd] median   max
Connect:      115   121  117.3    116  3114
Processing:   146   155   78.7    148  3147
Waiting:      141   155   78.7    148  3146
Total:        258   276  141.1    265  3263

Percentage of the requests served within a certain time (ms)
  50%    265
  66%    267
  75%    269
  80%    272
  90%    283
  95%    288
  98%    316
  99%    349
 100%   3263 (last request)
user@system-81%

In the above example, if the server returns dynamic content, the file size may be different from one request to another. One difference, for example, is ads on the page - they vary per request and have different byte size. When this happens, Apache bench notes it as "Failed request" for Length (byte size) being different. Tests against static and then dynamic content show this anomaly, which we can ignore. The ab queries against static pages don't return any of these failures for length.

In the next example, as you can see, the program name is often the default /usr/local/apache/bin/ab but may vary depending on your installation. In Apache2 installations, the new name is ab2.

user@system-81% ab  -V                            5:05PM /usr/local/apache/bin
This is ApacheBench, Version 1.3d <$Revision: 1.67 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/

user@system-82% ab --help                         5:05PM /usr/local/apache/bin
ab: invalid option -- -
ab: invalid option `?'
Usage: ab [options] [http://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make
    -t timelimit    Seconds to max. wait for responses
    -p postfile     File containg data to POST
    -T content-type Content-type header for POSTing
    -v verbosity    How much troubleshooting info to print
    -w              Print out results in HTML tables
    -i              Use HEAD instead of GET
    -x attributes   String to insert as table attributes
    -y attributes   String to insert as tr attributes
    -z attributes   String to insert as td or th attributes
    -C attribute    Add cookie, eg. 'Apache=1234' (repeatable)
    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: zop'
                    Inserted after all normal header lines. (repeatable)
    -A attribute    Add Basic WWW Authentication, the attributes
                    are a colon separated username and password.
    -P attribute    Add Basic Proxy Authentication, the attributes
                    are a colon separated username and password.
    -X proxy:port   Proxyserver and port number to use
    -V              Print version number and exit
    -k              Use HTTP KeepAlive feature
    -d              Do not show percentiles served table.
    -S              Do not show confidence estimators and warnings.
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -h              Display usage information (this message)
user@system-83%

Want to know how much those Server-Side includes are costing your site in performance? Want to know how fast your mirror site is serving? Want to know what performance effects the new architecture is having on your web site? These are all questions that Apache Bench can answer. Caution: Don't use Apache Bench to throw spurious traffic, and never overstep the bounds of courtesy when throwing traffic at other sites!





1998-2024 Celebrazio.net