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.
$ 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.
$ 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
:
concurrency * timetaken * 1000 / done
while the second value is calculated with the formula
timetaken * 1000 / done
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: