日期:2014-05-16  浏览次数:20637 次

Apache的压力测试工具ab
ab是Apache自带的HTTP压力测试工具,全称是ApacheBench,同微软的WAST、惠普的LoadRunner、QALoad等比起来,它要方便易用得多
ab是Apache的一个安装组件,所以需要下载Apache安装后才能使用,该命令位于Apache安装目录下的bin文件夹中
ab是专门用于HTTP Server的benchmark testing,可以同时模拟多个并发请求
ab的设计意图是描绘当前所安装的Apache的执行性能,主要是显示所安装的Apache每秒可以处理多少个请求

ab不像LR那么强大,但它足够轻便,若只是在开发过程中想检查一下某个模块的响应情况,或者做一些场景比较简单的测试,ab是个不错的选择
至少不用花费很多时间去学习LR中的那些复杂的功能,就更别说那License的价格了


下面简单介绍下它的用法


查询版本:[ab -V](注意这里是大写的V)

[Jadyer@Jadyer-RHEL63 ~]$ ab -V
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/

查询参数:[ab -v](注意这里是小写的v)

[Jadyer@Jadyer-RHEL63 ~]$ ab -v
ab: option requires an argument -- v
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
    //测试所进行的最大秒数,默认为无时间限制....其内部隐含值是[-n 50000],它可以使对服务器的测试限制在一个固定的总时间以内
    -t timelimit    Seconds to max. wait for responses
    -b windowsize   Size of TCP send/receive buffer, in bytes
    //包含了需要POST的数据的文件
    -p postfile     File containing data to POST. Remember also to set -T
    -u putfile      File containing data to PUT. Remember also to set -T
    //POST数据所使用的Content-type头信息
    -T content-type Content-type header for POSTing, eg.
                    'application/x-www-form-urlencoded'
                    Default is 'text/plain'
    //设置显示信息的详细程度,4或更大值会显示头信息,3或更大值可以显示响应码(404,200等),2或更大值可以显示警告和其他信息
    -v verbosity    How much troubleshooting info to print
    //以HTML表格的形式输出结果,默认是白色背景的两列宽度的一张表
    -w              Print out results in HTML tables
    //执行HEAD请求,而不是GET
    -i              Use HEAD instead of GET
    //设置<table>属性的字符串,此属性被填入<table 这里>
    -x attributes   String to insert as table attributes
    //设置<tr>属性的字符串
    -y attributes   String to insert as tr attributes
    //设置<td>属性的字符串
    -z attributes   String to insert as td or th attributes
    //对请求附加一个Cookie行,其典型形式是name=value的参数对,此参数可以重复
    -C attribute    Add cookie, eg. 'Apache=1234. (repeatable)
    //对请求附加额外的头信息,此参数的典型形式是一个有效的头信息行,其中包含了以冒号分隔的字段和值的对(如"Accept-Encoding: zip/zop;8bit")
    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
                    Inserted after all normal header lines. (repeatable)
    //HTTP验证,用冒号:分隔传递用户名及密码
    -A attribute    Add Basic WWW Authentication, the attributes
                    are a colon separated username and password.
    //对一个中转代理提供BASIC认证信任,用户名和密码由一个冒号:隔开,并以base64编码形式发送
    //无论服务器是否需要(即是否发送了401认证需求代码),此字符串都会被发送
    -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
    //启用HTTP KeepAlive功能,即在一个HTTP会话中执行多个请求,默认为不启用KeepAlive功能
    -k              Use HTTP KeepAlive feature
    //不显示"percentage served within XX [ms] table"的消息(为以前的版本提供支持)
    -d              Do not show percentiles served table.
    //不显示中值和标准背离值,且均值和中值为标准背离值的1到2倍时,也不显示警告或出错信息,默认会显示最小值/均值/最大值等(为以前的版本提供支持)
    -S              Do not show confidence estimators and warnings.
    //把所有测试结果写入一个'gnuplot'或者TSV(以Tab分隔的)文件
    //此文件可以方便地导入到Gnuplot,ID