ApacheBench(ab)测试工具介绍 - 备忘与学习

   ApacheBench是Apache附带的一个小工具,可以做http服务器的压力测试,可以同时模拟多个并发请求,该工具是安装apache时默认安装的,在apache/bin目录下面。如果要使用该工具,需要已安装apache,apache的安装在此不做说明。
   该工具可以给网站做压力测试,测试网站的请求处理速度,并发请求瓶颈等。

    命令格式:
    ab [options][http://]hostname[:port]/path

    参数介绍:
    -n   requests    Number of requests to perform
    做一次测试所发送的请求数,默认是1次请求
    -c   concurrency  Number of multiple requests tomake
    每次请求的并发数
    -t   timelimit   Seconds to max. wait for responses
    测试所进行的最大秒数,,可以将一次测试控制在等待多少秒内,默认没有时间限制
    -p   postfile    File containing data to POST
    测试请求包含的post数据
    -T   content-type Content-type header for POSTing
    POST数据需要声明的Content-type头信息
    -vverbosity    Howmuch troubleshooting info to print
    打印的信息的长度, 4或更大值会显示头信息,3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。 -V显示版本号并退出
   -w             Print out results in HTML tables
    以HTML表格的形式输出测试结果
   -i             Use HEAD instead of GET
    用HEAD请求代替GET
    -x   attributes   String to insert astable attributes
    table表格的属性
    -y   attributes   String to insert astr attributes
    表格中tr的属性
    -z   attributes   String to insert astd or th attributes
    表格中td/th的属性
    -C   attribute    Addcookie, eg. 'Apache=1234. (repeatable)
    对请求附加cookie设置,格式是name=value,该命令可重复设置多个cookie
    -H   attribute    AddArbitrary header line, eg. 'Accept-Encoding: gzip' Inserted afterall normal header lines. (repeatable)
    设置head的参数,例如接收的压缩格式为gzip
    -A   attribute    AddBasic WWW Authentication, the attributes are a colon separatedusername and password.
    -P   attribute    AddBasic Proxy Authentication, the attributes are a colon separatedusername and password.
    -X   proxy:port   Proxyserver and portnumber 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)
   该工具有很多参数,这里水平有限,有些自己也没用过,不做说明,基本我们常用的命令已经给出了解释。

   启动该工具的方式,开始->运行->cmd,进入dos模式,然后进入到apache\bin目录。

   我们以google.com作为测试对象,来具体分析一下返回的结果。
    执行命令:ab -n100 -c 10 http://www.google.com/
   此命令为向google.com发送100次请求,并且每次请求附带10个并发请求
    返回结果:
ServerSoftware:       gws
谷歌所用的网站服务器基于apache开发且对谷歌程序优化版
ServerHostname:       www.google.com
ServerPort:           80

DocumentPath:         /
DocumentLength:       376 bytes

ConcurrencyLevel:     10
并发数为10
Time taken for tests:   5.609seconds
整个测试所花费的时间 5.609秒
Completerequests:     100
请求完成数100
Failedrequests:       0
Writeerrors:          0
Non-2xxresponses:     100
Totaltransferred:     92755 bytes
HTMLtransferred:      37600 bytes
Requests persecond:    17.83[#/sec] (mean)
每秒处理的请求数
Time perrequest:      560.938 [ms] (mean)
每次请求的平均处理时间(毫秒)
Time perrequest:      56.094 [ms] (mean, across all concurrent requests)
每次请求中处理每个并发所用的时间
Transferrate:         16.15 [Kbytes/sec] received

//-----------------------
Connection Times (ms)
             min  mean[+/-sd]median   max
Connect:      47  55  7.8    63     63
连接时间 最小为47毫秒 最大为63毫秒平均连接时间约为55毫秒
Processing:   63  475 88.7   500    516
处理时间 最小为63毫秒 最大为516毫秒平均处理时间约为516毫秒
Waiting:      47  286136.7   281    516
等待时间
Total:       109  530 88.9   547    563
时间总计
WARNING: The median and mean for the initial connection time arenot within a no
rmal deviation
初始连接时间的平均值不在正常的偏差范围内
       These results are probably not that reliable.
-------------------------//以上为本次测试的分析结果,个人不清楚具体的计算过程
Percentage of the requests served within a certain time (ms)
 50%    547
 66%    563
 75%    563
 80%    563
 90%    563
 95%    563
 98%    563
 99%    563
 100%   563 (longest request)
   50%的用户请求处理时间小于547毫秒,66%的的用户请求处理时间小于563毫秒,其他的以此类推,最长的请求处理时间不超过563毫秒
    由于对于并发请求,cpu实际上并不是同时处理的,而是按照每个请求获得的时间片逐个轮转处理的,所以基本上第一个Timeper request时间约等于第二个Time per request时间乘以并发请求数
在本例中 560.938≈56.094*10


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值