ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.


ab的全称是ApacheBench,是 Apache 附带的一个小工具,专门用于 HTTP Server 的benchmark testing,可以同时模拟多个并发请求。

下载安装(ubuntu 12.04 x64)

sudo apt-get install apache2-utils


zhou@zhou-VirtualBox:~$ ab --help
ab: wrong number of arguments
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
    -t timelimit    Seconds to max. wait for responses
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -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 for POSTing, eg.
                    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.
    -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.
    -h              Display usage information (this message)
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol     Specify SSL/TLS protocol (SSL3, TLS1, or ALL)


zhou@zhou-VirtualBox:~$ ab -c 500 -t 30 http://localhost:3000/

This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Finished 15255 requests

Server Software:        
Server Hostname:        localhost
Server Port:            3000

# 请求的路径
Document Path:          /
# 请求响应文档的长度
Document Length:        206 bytes

# 并发数
Concurrency Level:      500
# 执行时间
Time taken for tests:   30.009 seconds
# 完成请求数
Complete requests:      15255
Failed requests:        0
Write errors:           0
# 总数据传输量
Total transferred:      5568075 bytes
# HTML数据传输量
HTML transferred:       3142530 bytes
# 平均每秒请求数
Requests per second:    508.35 [#/sec] (mean)
# 实际平均请求响应时间
Time per request:       983.568 [ms] (mean)
# 总平均请求响应时间
Time per request:       1.967 [ms] (mean, across all concurrent requests)
# 每秒数据传输量
Transfer rate:          181.20 [Kbytes/sec] received

# 连接时间耗费情况
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   8.5      0     155
Processing:   151  964 103.2    960    1325
Waiting:      145  964 103.2    960    1325
Total:        234  966  98.6    961    1325

# 整个场景中所有请求的响应情况。如50%请求的响应时间不超过961毫秒
Percentage of the requests served within a certain time (ms)
  50%    961
  66%    986
  75%   1002
  80%   1014
  90%   1046
  95%   1123
  98%   1239
  99%   1281
 100%   1325 (longest request)