Benchmarking a website's performance with ab

You can benchmark a website's performance using the AppleBench utility which is a tool available on Mac OS X and Linux systems. The tool was originally developed to test Apache web servers, but can be used to test web servers running any web server software. The tool will report the web server software that is in use on the server being tested in a "Server Software" line in the output from the tool.

On an OS X system, you can run it from a Terminal window; the Terminal application is found in the /Applications/Utilities directory by using the ab command (man page) command. To test a web site, e.g., example.com, you can issue a command in the form ab http://example.com.

$ ab http://example.com/
This is ApacheBench, Version 2.3 <$Revision: 1663405 $>
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:        ECS
Server Hostname:        example.com
Server Port:            80

Document Path:          /
Document Length:        1270 bytes

Concurrency Level:      1
Time taken for tests:   0.042 seconds
Complete requests:      1
Failed requests:        0
Total transferred:      1622 bytes
HTML transferred:       1270 bytes
Requests per second:    23.96 [#/sec] (mean)
Time per request:       41.744 [ms] (mean)
Time per request:       41.744 [ms] (mean, across all concurrent requests)
Transfer rate:          37.95 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       19   19   0.0     19      19
Processing:    23   23   0.0     23      23
Waiting:       21   21   0.0     21      21
Total:         42   42   0.0     42      42
$

In the example above, I used http://example.com/. If I had not included the forward slash at the end of the URL, I would have seen an "invalid URL" message followed by usage information for the command. So, if you aren't specifying a specific web page, but only the domain name, be sure to put the slash at the end of the URL.

$ ab http://example.com
ab: invalid URL

You can view the help information for the command by typing ab -h .

$ ab -h
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make at a time
    -t timelimit    Seconds to max. to spend on benchmarking
                    This implies -n 50000
    -s timeout      Seconds to max. wait for each response
                    Default is 30 seconds
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -B address      Address to bind to when making outgoing connections
    -p postfile     File containing data to POST. Remember also to set -T
    -u putfile      File containing data to PUT. Remember also to set -T
    -T content-type Content-type header to use for POST/PUT data, eg.
                    'application/x-www-form-urlencoded'
                    Default is 'text/plain'
    -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: gzip'
                    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.
    -q              Do not show progress when doing more than 150 requests
    -l              Accept variable document length (use this for dynamic pages)
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -r              Don't exit on socket receive errors.
    -m method       Method name
    -h              Display usage information (this message)
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol     Specify SSL/TLS protocol
                    (SSL2, SSL3, TLS1 or ALL)
$

You can use a specific webpage URL as in the example below. You can specify the number of HTTP GET requests to make with the -n option and the number of requests to make at one time, i.e., the number of concurrent requests, with the -c option.

Udemy
$ ab -n 25 -c 5 http://www.iana.org/domains/reserved
This is ApacheBench, Version 2.3 <$Revision: 1663405 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.iana.org (be patient).....done


Server Software:        Apache
Server Hostname:        www.iana.org
Server Port:            80

Document Path:          /domains/reserved
Document Length:        10232 bytes

Concurrency Level:      5
Time taken for tests:   1.671 seconds
Complete requests:      25
Failed requests:        0
Total transferred:      263072 bytes
HTML transferred:       255800 bytes
Requests per second:    14.96 [#/sec] (mean)
Time per request:       334.157 [ms] (mean)
Time per request:       66.831 [ms] (mean, across all concurrent requests)
Transfer rate:          153.76 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       94  111  13.9    107     140
Processing:   192  218  18.9    217     263
Waiting:       94  110  13.6    103     141
Total:        286  329  28.7    316     396

Percentage of the requests served within a certain time (ms)
  50%    314
  66%    344
  75%    352
  80%    358
  90%    368
  95%    378
  98%    396
  99%    396
 100%    396 (longest request)
$

If you wanted to know how many bytes of data are on a particular webpage, you could set n to 1.

Hide.me 25% discount
$ ab -n 1 http://www.iana.org/domains/reserved
This is ApacheBench, Version 2.3 <$Revision: 1663405 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.iana.org (be patient).....done


Server Software:        Apache
Server Hostname:        www.iana.org
Server Port:            80

Document Path:          /domains/reserved
Document Length:        10232 bytes

Concurrency Level:      1
Time taken for tests:   0.293 seconds
Complete requests:      1
Failed requests:        0
Total transferred:      10522 bytes
HTML transferred:       10232 bytes
Requests per second:    3.41 [#/sec] (mean)
Time per request:       293.229 [ms] (mean)
Time per request:       293.229 [ms] (mean, across all concurrent requests)
Transfer rate:          35.04 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       94   94   0.0     94      94
Processing:   200  200   0.0    200     200
Waiting:      102  102   0.0    102     102
Total:        293  293   0.0    293     293
$

E.g., in the above example, the web page contains 10,232 bytes. The curl command shows the same number of bytes.

$ curl -o iana.txt http://www.iana.org/domains/reserved
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10232    0 10232    0     0   5571      0 --:--:--  0:00:01 --:--:--  5569

The following list describes the values returned by ab:

Server Software
The value, if any, returned in the server HTTP header of the first successful response. This includes all characters in the header from beginning to the point a character with decimal value of 32 (most notably: a space or CR/LF) is detected.
Server Hostname
The DNS or IP address given on the command line
Server Port
The port to which ab is connecting. If no port is given on the command line, this will default to 80 for http and 443 for https.
SSL/TLS Protocol
The protocol parameters negotiated between the client and server. This will only be printed if SSL is used.
Document Path
The request URI parsed from the command line string.
Document Length
This is size in bytes of the first succesfully returning document. If the document length changes during testing, the response is considered an error.
Concurrency Level
The number of concurrent clients used during the test
Time taken for tests
This is the time taken from the moment the first socket connection is created to the moment the last response is recieved
Complete requests
The number of successful responses recieved
Failed requests
The number of requests that were considered a failure. If the number is greater than zero, another line will be printed showing the numer of requests that failed due to connecting, reading, incorrect content length, or exceptions.
Write errors
The number of errors that failed during write (broken pipe).
Non-2xx responses
The number of responses that were not in the 200 series of response codes. If all responses were 200, this field is not printed.
Keep-Alive requests
The number of connections that resulted in Keep-Alive requests
Total body sent
If configured to send data as part of the test, this is the total number of bytes sent during the tests. This field is omitted if the test did not include a body to send.
Total transferred
The total number of bytes received from the server. This number is essentially the number of bytes sent over the wire.
HTML transferred
The total number of document bytes received from the server. This number excludes bytes received in HTTP headers
Requests per second
This is the number of requests per second. This value is the result of dividing the number of requests by the total time taken
Time per request
The average time spent per request. The first value is calculated with the formula concurrency * timetaken * 1000 / done while the second value is calculated with the formula timetaken * 1000 / done
Transfer rate
The rate of transfer as calculated by the formula totalread / 1024 / timetaken

The ab utility is part of the httpd-tools package on CentOS Linux systems.

$ rpm -q --whatprovides /usr/bin/ab
httpd-tools-2.4.6-31.el7.centos.x86_64
$

If you use the yum package manager, you can install it with yum install httpd-tools.

References:

  1. ab - Apache HTTP server benchmarking tool
    The Apache Software Foundation
  2. AppleBench
    Wikipedia, The Free Encyclopedia

 

TechRabbit ad 300x250 newegg.com

Justdeals Daily Electronics Deals1x1 px