参数:ab 用法如下

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   //等待响应时间
    -p postfile     File containing data to POST
    -T content-type Content-type header for POSTing
    -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  //http验证, 分隔传递用户名及密码
                    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  //查看ab版本
    -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
    -s              Use httpS instead of HTTP (SSL)
    -h              Display usage information (this message)

# ab -n 请求数 -c 并发数 测试 url

# ab -n 100 -c 5 -k http://www.gaingreat.com/42.html  //必须在后方指定相应文件42.html或加上“/”
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 www.gaingreat.com (be patient).....done

Server Software:        nginx  //Web服务器引擎
Server Hostname:        www.gaingreat.com  //服务器地址
Server Port:            80  //服务器端口

Document Path:          /42.html  //请求的文件路径
Document Length:        37927 bytes  //文件大小

Concurrency Level:      5  //并发次数
Time taken for tests:   32.732276 seconds  //测试所需时间
Complete requests:      100  //成功请求次数
Failed requests:        73  //失败请求次数
   (Connect: 0, Length: 73, Exceptions: 0)
Write errors:           0  //写入错误
Keep-Alive requests:    0
Total transferred:      3817232 bytes  //测试过程传输字节数
HTML transferred:       3791532 bytes  //HTML内容传输字节数
Requests per second:    3.06 [#/sec] (mean)  //每秒请求数 ( 平均 )
Time per request:       1636.614 [ms] (mean)  //每次并发请求时间 ( 所有并发 )
Time per request:       327.323 [ms] (mean, across all concurrent requests)  //每一请求时间 ( 并发平均 )
Transfer rate:          113.86 [Kbytes/sec] received  //平均传输速率

Connection Times (ms)  //响应时间小、中、大值
              min  mean[+/-sd] median   max
Connect:       16  183 111.5    192     460
Processing:   793 1427 548.2   1296    3839
Waiting:      300  822 485.0    650    3190
Total:        925 1611 512.8   1447    3891
Percentage of the requests served within a certain time (ms)
  50%   1447
  66%   1567
  75%   1667
  80%   1742
  90%   2241
  95%   2793
  98%   3748
  99%   3891
 100%   3891 (longest request)

附录1:关于ab -n 请求数 -c 并发数 测试 url的部分说明
并发连接数不能够大于请求数,即C≤ N 否则会提示:Cannot use concurrency level greater than total number of requests。

附录2.ab: error while loading shared libraries: libaprutil-1.so.0: cannot open shared object file: No such file or directory
这是因为apr-utils没用安装,centOS的话,直接yum install apr-utils即可。若apr-utils是编译安装的,如我这里的/usr/local/apr-utils目录,刚ln -s /usr/local/apr-util/lib/libaprutil-1.so.0* /usr/lib64/将apr-utils软链接到/usr/lib64目录下(64位系统,32位系统目录为/usr/lib/)

附录3.yum install arp-utils时用到的文件目录

# rpm -ql apr-util



0 条评论。