魏长东

weichangdong

Apache压力测试工具ab用法

ab -c 100 -n 100 http://swordman.sinaapp.com/index.php

ab是Apache自带的HTTP压力测试工具,全称是ApacheBench.

ab是专门用于HTTP Server的benchmark testing,可以同时模拟多个并发请求
ab的设计意图是描绘当前所安装的Apache的执行性能,主要是显示所安装的Apache每秒可以处理多少个请求

参数解释:

[root@bj-171-121 ~]# 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//测试所进行的最大秒数,默认为无时间限制....其内部隐含值是[-n 50000],它可以使对服务器的测试限制在一个固定的总时间以内 
    -p postfile     File containing data to POST  //包含了需要POST的数据的文件
    -T content-type Content-type header for POSTing //POST数据所使用的Content-type头信息 
    -v verbosity    How much troubleshooting info to print
    -w              Print out results in HTML tables//以HTML表格的形式输出结果,默认是白色背景的两列宽度的一张表 
    -i              Use HEAD instead of GET//执行HEAD请求,而不是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
    -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)

我的执行结果

[root@bj-171-121 ~]# ab -c 100 -n 100 http://swordman.sinaapp.com/index.php
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking swordman.sinaapp.com (be patient).....done


Server Software:        ASERVER/1.2.9-3
Server Hostname:        swordman.sinaapp.com
Server Port:            80

Document Path:          /index.php
Document Length:        1266 bytes

Concurrency Level:      100#并发数 
Time taken for tests:   3.97027 seconds #全部请求完成耗时
Complete requests:      100#完成的请求数
Failed requests:        56 #失败的请求
   (Connect: 0, Length: 56, Exceptions: 0)
Write errors:           0
Non-2xx responses:      44
Total transferred:      1869312 bytes
HTML transferred:       1814392 bytes
Requests per second:    32.29 [#/sec] (mean)#每秒请求数(平均)
Time per request:       3097.027 [ms] (mean)每次并发请求时间(所有并发
Time per request:       30.970 [ms] (mean, across all concurrent requests)每一请求时间(并发平均) 
Transfer rate:          589.27 [Kbytes/sec] received#传输速率

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       50   51   1.0     51      54
Processing:   258  830 674.7    890    3045
Waiting:      252  694 526.2    737    2893
Total:        310  881 674.6    943    3095

Percentage of the requests served within a certain time (ms)
  50%    943
  66%   1046
  75%   1116
  80%   1130
  90%   1205
  95%   2932
  98%   3048
  99%   3095
 100%   3095 (longest request)