ab压力测试工具

ab是apache自带的一种压力测试工具。ab可以直接在Web服务器本地发起测试请求,这至关重要,因为有些时候我们需要测试的仅仅是服务器的 处理性能,并不想掺杂着网络传输时间的影响。ab进行一切测试的本质都是基于HTTP的,所以可以说ab对于Web服务器软件的黑盒性能测试,获得的一切 数据和计算结果,都是可以通过HTTP来解释的。

一、ab命令参数详解
  • -n requests Number of requests to perform
    # 在测试会话中所执行的请求个数。 默认时,仅执行一个请求,但通常其结果不具有代表意义。
  • -c concurrency Number of multiple requests to make
    # 在测试会话中所执行的请求并发数
  • -t timelimit Seconds to max. wait for responses
    # 测试所进行的最大秒数。它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。
  • -b windowsize Size of TCP send/receive buffer, in bytes
    # TCP发送/接收的缓冲大小(单位:字节)
  • -p postfile File containing data to POST. Remember also to set -T
    # 发送POST请求时需要上传的文件,此外还必须设置-T参数
  • -u putfile File containing data to PUT. Remember also to set -T
    # 发送PUT请求时需要上传的文件,此外还必须设置-T参数
  • -T content-type Content-type header for POSTing, eg.
    ‘application/x-www-form-urlencoded’
    Default is ‘text/plain’

    # 用于设置Content-Type请求头信息,例如:application/x-www-form-urlencoded,默认值为text/plain。
  • -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
    # 插入字符串作为table标签的属性
  • -y attributes String to insert as tr attributes
    # 插入字符串作为tr标签的属性
  • -z attributes String to insert as td or th attributes
    # 插入字符串作为td标签的属性
  • -C attribute Add cookie, eg. ‘Apache=1234. (repeatable)
    # 添加cookie信息,例如:”Apache=1234″(可以重复该参数选项以添加多个)
  • -H attribute Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’
    Inserted after all normal header lines. (repeatable)

    # 添加任意的请求头,例如:”Accept-Encoding: gzip”,请求头将会添加在现有的多个请求头之后(可以重复该参数选项以添加多个)。
  • -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
    # 指定使用的代理服务器和端口号,例如:”126.10.10.3:88″。
  • -V Print version number and exit
    # 打印版本号并退出。
  • -k Use HTTP KeepAlive feature
    # 使用HTTP的KeepAlive特性
  • -d Do not show percentiles served table.
    # 不显示百分比。
  • -S Do not show confidence estimators and warnings.
    # 不显示预估和警告信息。
  • -g filename Output collected data to gnuplot format file.
    # 输出结果信息到gnuplot格式的文件中。
  • -e filename Output CSV file with percentages served
    # 输出结果信息到CSV格式的文件中。
  • -r Don’t exit on socket receive errors.
    # 指定接收到错误信息时不退出程序。
  • -h Display usage information (this message)
    # 显示用法信息,其实就是ab -help
  • -Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)

    # 使用ssl/tls的协议版本
二、测试性能输出详解
  • Server Software: Apache/2.2.15
    Server Hostname: 192.168.80.135
    Server Port: 80
    Document Path: /phpinfo.php
    Document Length: 50366 bytes
  • Concurrency Level: 100
    # 表示并发的用户数
  • Time taken for tests: 0.739 seconds
    # 表示所有这些请求被处理完成所花费的总时间
  • Complete requests: 1000
    # 表示总请求数量,这是我们设置的参数之一
  • Failed requests: 0
    # 表示失败的请求数量,这里的失败是指请求在连接服务器、发送数据等环节发生异常,以及无响应后超时的情况。如果接收到的HTTP响应数据的头信息中含有 2XX以外的状态码,则会在测试结果中显示另一个名为 “Non-2xx responses”的统计项,用于统计这部分请求数,这些请求并不算在失败的请求中。
  • Write errors: 0
    Keep-Alive requests: 0
  • Total transferred: 50538000 bytes
    # 表示所有请求的响应数据长度总和,包括每个HTTP响应数据的头信息和正文数据的长度。注意这里不包括HTTP请求数据的长度,仅仅为web服务器流向用户PC的应用层数据总长度。
  • HTML transferred: 50366000 bytes
    # 表示所有请求的响应数据中正文数据的总和,也就是减去了Total transferred中HTTP响应数据中的头信息的长度
  • Requests per second: 1353.17 [#/sec] (mean)
    # 吞吐率,计算公式:Complete requests / Time taken for tests
  • Time per request: 73.901 [ms] (mean)
    # 用户平均请求等待时间,计算公式:Time token for tests/(Complete requests/Concurrency Level)
    【注】这里是请求等待时间,不是使用计算公式:Time taken for tests / Concurrency Level
  • Time per request: 0.739 [ms] (mean, across all concurrent requests)
    # 服务器平均请求等待时间,计算公式:Time taken for tests/Complete requests,正好是吞吐率的倒数。也可以这么统计:Time per request/Concurrency Level
  • Transfer rate: 66783.56 [Kbytes/sec] received
    # 表示这些请求在单位时间内从服务器获取的数据长度,计算公式:Total trnasferred/ Timetaken for tests,这个统计很好的说明服务器的处理能力达到极限时,其出口宽带的需求量。
Connection Times (ms)
                    min   avg     max
 Connect:           0      5      13
 Processing:        12     66     98
 Total:             12     71     111

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>