ApacheBench is a command line computer program for measuring the performance of HTTP web servers, in particular the Apache HTTP Server. It was designed to give an idea of the performance that a given Apache installation can provide. In particular, it shows how many requests per second the server is capable of serving.
The ab tool comes bundled with the standard Apache source distribution, and like the Apache web server itself, is free, open source software and distributed under the terms of the Apache License.
The performance is usually measured in terms of:
- Number of requests that can be served per second (depending on the type of request, etc.);
- Latency response time in milliseconds for each new connection or request;
- Throughput in bytes per second (depending on file size, cached or not cached content, available network bandwidth, etc.).
The measurements must be performed under a varying load of clients and requests per client.
ab [ -A auth-username:password ] [ -c concurrency ]
[ -C cookie-name=value ] [ -d ] [ -e csv-file ]
[ -g gnuplot-file ] [ -h] [ -H custom-header ]
[ -i ] [ -k ] [ -n requests ] [ -p POST-file ]
[ -P proxy-auth-username:password ]
[ -q ] [ -s ] [ -S] [ -t timelimit ] [ -T content-type ]
[ -v verbosity] [ -V ] [ -w ] [ -x <table>-attributes ]
[ -X proxy[:port] ] [ -y <tr>-attributes ]
[ -z <td>-attributes ] [http://]hostname[:port]/path
-A auth-username: password
Supply BASIC Authentication credentials to the server. The username and password are separated by a single : and sent on the wire base64 encoded. The string is sent regardless of whether the server needs it
Number of multiple requests to perform at a time. Default is one request at a time.
-C cookie-name= value
Add a Cookie: line to the request. The argument is typically in the form of a name=value pair. This field is repeatable.
Do not display the "percentage served within XX [ms] table". (legacy support).
Write a Comma separated value (CSV) file which contains for each percentage (from 1% to 100%) the time (in milliseconds) it took to serve that percentage of the requests. This is usually more useful than the 'gnuplot' file; as the results are already 'binned'.
Write all measured values out as a 'gnuplot' or TSV (Tab separate values) file. This file can easily be imported into packages like Gnuplot, IDL, Mathematica, Igor or even Excel. The labels are on the first line of the file.
Display usage information.
Append extra headers to the request. The argument is typically in the form of a valid header line, containing a colon-separated field-value pair (i.e., "Accept-Encoding: zip/zop;8bit").
Do HEAD requests instead of GET.
Enable the HTTP KeepAlive feature, i.e., perform multiple requests within one HTTP session. Default is no KeepAlive.
Number of requests to perform for the benchmarking session. The default is to just perform a single request which usually leads to non-representative benchmarking results.
File containing data to POST.
-P proxy-auth-username: password
Supply BASIC Authentication credentials to a proxy en-route. The username and password are separated by a single : and sent on the wire base64 encoded. The string is sent regardless of whether the proxy needs it (i.e., has sent an 407 proxy authentication needed).
When processing more than 150 requests, ab outputs a progress count on stderr every 10% or 100 requests or so. The -q flag will suppress these messages.
When compiled in (ab -h will show you) use the SSL protected https rather than the http protocol. This feature is experimental and very rudimentary. You probably do not want to use it.
Do not display the median and standard deviation values, nor display the warning/error messages when the average and median are more than one or two times the standard deviation apart. And default to the min/avg/max values. (legacy support).
Maximum number of seconds to spend for benchmarking. This implies a -n 50000 internally. Use this to benchmark the server within a fixed total amount of time. Per default there is no timelimit.
Content-type header to use for POST data.
Set verbosity level - 4 and above prints information on headers, 3 and above prints response codes (404, 200, etc.), 2 and above prints warnings and info.
Display version number and exit.
Print out results in HTML tables. Default table is two columns wide, with a white background.
String to use as attributes for <table>. Attributes are inserted <table here >.
-X proxy[: port]
Use a proxy server for the requests.
String to use as attributes for <tr>.
String to use as attributes for <td>.
Apache Benchmark Procedures
- First record server load using top or uptime command
- Take at least 3-5 readings and use the best result
- After each test reboot the server and carry out test on next configuration (web server)
- Again record server load using top or uptime command
- Carry on test using static html/php files and dynamic pages
- It also important to carry out test using the Non-KeepAlive and KeepAlive (the Keep-Alive extension to provide long-lived HTTP sessions, which allow multiple requests to be sent over the same TCP connection) features
Note down server load using uptime command
Create a static (small) html page as follows (snkpage.html) (assuming that server IP is 18.104.22.168) in /var/www/html (or use your own webroot):
This is a webserver test page.
Login to Linux/bsd desktop computer and type following command:
$ ab -n 1000 -c 5 http://22.214.171.124/snkpage.html
- -n 1000: ab will send 1000 number of requests to server 126.96.36.199 in order to perform for the benchmarking session
- -c 5 : 5 is concurrency number i.e. ab will send 5 number of multiple requests to perform at a time to server 188.8.131.52
- For example if you want to send 10 request, type following command:
$ ab -n 10 -c 2 http://www.somewhere.com/
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
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 www.cyberciti.biz (be patient).....done
Server Hostname: www.somewhere.com
Server Port: 80
Document Path: /
Document Length: 16289 bytes
Concurrency Level: 1
Time taken for tests: 16.885975 seconds
Complete requests: 10
Failed requests: 0
Write errors: 0
Total transferred: 166570 bytes
HTML transferred: 162890 bytes
Requests per second: 0.59 [#/sec] (mean)
Time per request: 1688.597 [ms] (mean)
Time per request: 1688.597 [ms] (mean, across all concurrent requests)
Transfer rate: 9.59 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 353 375 16.1 386 391
Processing: 1240 1312 52.1 1339 1369
Waiting: 449 472 16.2 476 499
Total: 1593 1687 67.7 1730 1756
Percentage of the requests served within a certain time (ms)
100% 1756 (longest request)
Repeat above command 3-5 times and save the best reading.
Use -k option that enables the HTTP KeepAlive feature using ab test tool. For example:
$ ab -k -n 1000 -c 5 http://184.108.40.206/snkpage.html
Use -e option that allows to write a comma separated value (CSV) file which contains for each percentage (from 1% to 100%) the time (in milliseconds) it took to serve that percentage of the requests:
$ ab -k -n 50000 -c 2 -e apache2r1.cvs http://220.127.116.11/snkpage.html
After displaying some status reports every 100 requests or so, it will print out a fairly detailed report, including document length, bytes transferred, completed and failed requests, requests per second and some statistics on connection times.