Back to Performance Test

See Also JMeterUnix UtilitiesHomebrew

ApacheBench

1. Summary

ab - Apache HTTP server benchmarking tool
       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 instal-
       lation is capable of serving.

2. Getting Started

2.1. 运行一个测试

sudo yum install httpd-tools -y
ab -n 100000 -c 150 -p reportbyte00.txt  http://172.16.100.71/statisdk/portal01
# siege "http://172.16.100.71/statisdk/portal01 POST < reportbyte00.txt" -r100 -c5
# siege "http://172.16.100.71/statisdk/portal01 POST < reportbyte00.txt" -t10s -c10
# curl -d @reportbyte00.txt  http://172.16.100.71/statisdk/portal01
# wget --post-file=reportbyte00.txt  http://172.16.100.71/statisdk/portal01 -O -

2.1.1. Options

➜  ~ ab -c 10 -t 300 -s 300 -k -r http://www.baidu.com/

➜  ~ lsof -Pan -p 2410 -i # 查看进程联网情况

       -c concurrency
              Number of multiple requests to perform at a time. Default is one request at a
              time.

       -k     Enable the HTTP KeepAlive feature, i.e., perform multiple requests within one HTTP  session.
              Default is no KeepAlive.

       -n requests
              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.

       -p POST-file
              File containing data to POST. Remember to also set -T.

       -r     Don't exit on socket receive errors.

       -s timeout
              Maximum  number of seconds to wait before the socket times out. Default is 30
              seconds. Available in 2.4.4 and later.

       -t timelimit
              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.

       -T content-type
              Content-type header to use for POST/PUT data, eg. application/x-www-form-urlencoded. Default
              is text/plain.

2.2. 测试结果分析

   1 ➜  ~ ab -n 100 -c 10 -s 150 https://www.google.com/
   2 This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
   3 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
   4 Licensed to The Apache Software Foundation, http://www.apache.org/
   5 
   6 Benchmarking www.google.com (be patient).....done
   7 
   8 
   9 Server Software:        
  10 Server Hostname:        www.google.com
  11 Server Port:            443
  12 SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128
  13 
  14 Document Path:          /
  15 Document Length:        263 bytes
  16 
  17 Concurrency Level:      10
  18 Time taken for tests:   0.337 seconds
  19 Complete requests:      100
  20 Failed requests:        11
  21    (Connect: 0, Receive: 0, Length: 11, Exceptions: 0)
  22 Write errors:           0
  23 Non-2xx responses:      100
  24 Total transferred:      57659 bytes
  25 HTML transferred:       26278 bytes
  26 Requests per second:    296.77 [#/sec] (mean)
  27 Time per request:       33.696 [ms] (mean)
  28 Time per request:       3.370 [ms] (mean, across all concurrent requests)
  29 Transfer rate:          167.11 [Kbytes/sec] received
  30 
  31 Connection Times (ms)
  32               min  mean[+/-sd] median   max
  33 Connect:       14   27  10.4     25      59
  34 Processing:     2    5   3.5      4      19
  35 Waiting:        2    5   2.5      4      14
  36 Total:         22   32  10.1     29      63
  37 
  38 Percentage of the requests served within a certain time (ms)
  39   50%     29
  40   66%     30
  41   75%     31
  42   80%     32
  43   90%     59
  44   95%     59
  45   98%     61
  46   99%     63
  47  100%     63 (longest request)

2.2.1. 测试概况

2.2.2. 测试结果概况

Concurrency Level:      10
Time taken for tests:   0.337 seconds
Complete requests:      100
Failed requests:        11
   (Connect: 0, Receive: 0, Length: 11, Exceptions: 0)
Write errors:           0
Non-2xx responses:      100
Total transferred:      57659 bytes
HTML transferred:       26278 bytes
Requests per second:    296.77 [#/sec] (mean)
Time per request:       33.696 [ms] (mean)
Time per request:       3.370 [ms] (mean, across all concurrent requests)
Transfer rate:          167.11 [Kbytes/sec] received

2.2.3. 统计细化的响应速度

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       14   27  10.4     25      59
Processing:     2    5   3.5      4      19
Waiting:        2    5   2.5      4      14
Total:         22   32  10.1     29      63

2.2.4. 统计响应速度分布情况

Percentage of the requests served within a certain time (ms)
  50%     29
  66%     30
  75%     31
  80%     32
  90%     59
  95%     59
  98%     61
  99%     63
 100%     63 (longest request)

3. Limitations

ab is an HTTP/1.0 client, not a HTTP/1.1 client, if V1.1 needed, try siege

4. Installation

4.1. Upgrade ab to 2.4.x on OS X

➜  ~ brew uninstall --force ab apr apr-util
➜  ~ brew install ab apr apr-util

4.2. Upgrade ab to 2.4.4 on CentOS

高版本ab增加了-s timeout的参数,安装方法参考http://unix.stackexchange.com/questions/121001/how-to-upgrade-apache-2-2-15-to-2-4-4-in-centos

$ yum info httpd-tools
Installed Packages
Name        : httpd-tools
Arch        : x86_64
Version     : 2.2.15
Release     : 69.el6.centos
Size        : 138 k
Repo        : installed
From repo   : base
Summary     : Tools for use with the Apache HTTP Server
URL         : http://httpd.apache.org/
License     : ASL 2.0
Description : The httpd-tools package contains tools which can be used with
            : the Apache HTTP Server.

# ab -V
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
# cd /etc/yum.repos.d/
# wget https://repos.fedorapeople.org/repos/jkaluza/httpd24/epel-httpd24.repo
# yum -y install httpd24-tools
# cp /opt/rh/httpd24/root/usr/bin/ab /usr/bin/
# ab -V
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
$ ab -c 100 -n 1000000 -k -p /tmp/request.bin -s 100 http://test.li3huo.com/portal01

4.3. Upgrade ab to 2.4.x on Cygwin

Refer to apt-cyg

$ apt-cyg install httpd-tools-2.4

4.4. Reference

MainWiki: ApacheBench (last edited 2013-03-13 06:53:59 by twotwo)