点击登录
  • 欢迎访问无限星辰技术博客,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏无限星辰吧
  • 好集导航开张了,传送门:好集导航

使用apachebench进行网站压力测试ab.exe

互联网技术 crx349 3836次浏览 0个评论 扫描二维码

1 概述
ab(ApacheBench)是Apache自带的超文本传输协议(HTTP)性能测试工具。 其设计意图是描绘当前所安装的Apache的执行性能, 主要是显示你安装的Apache每秒可以处理多少个请求。

2 使用
2.1 安装
Apache服务器套件自带ab,只要安装Apache即可,无需另行安装ab。ab位于%ApacheHome%/bin目录下(“%ApacheHome%”为Aapche安装路径),你也可以把ab.exe文件copy出来,独立使用。

2.2 参数列表

C:\>ab
ab: wrong number of arguments
Usage: ab [options] [http://]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 HTMLtables
-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
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)

* 中文的列表可以查看Apache手册中文版。
* 部分中文参数解释:

-A auth-username:password
对服务器提供BASIC认证信任。 用户名和密码由一个:隔开,并以base64编码形式发送。 无论服务器是否需要(即, 是否发送了401认证需求代码),此字符串都会被发送。

-c concurrency
一次产生的请求个数。默认是一次一个。

-C cookie-name=value
对请求附加一个Cookie:行。 其典型形式是name=value的一个参数对。 此参数可以重复。

-d
不显示”percentage served within XX [ms] table”的消息(为以前的版本提供支持)。

-e csv-file
产生一个以逗号分隔的(CSV)文件, 其中包含了处理每个相应百分比的请求所需要(从1%到100%)的相应百分比的(以微妙为单位)时间。 由于这种格式已经“二进制化”,所以比’gnuplot’格式更有用。

-g gnuplot-file
把所有测试结果写入一个’gnuplot’或者TSV (以Tab分隔的)文件。 此文件可以方便地导入到Gnuplot, IDL, Mathematica, Igor甚至Excel中。 其中的第一行为标题。

-h
显示使用方法。

-H custom-header
对请求附加额外的头信息。 此参数的典型形式是一个有效的头信息行,其中包含了以冒号分隔的字段和值的对 (如, “Accept-Encoding: zip/zop;8bit”)。

-i
执行HEAD请求,而不是GET。

-k
启用HTTP KeepAlive功能,即, 在一个HTTP会话中执行多个请求。 默认时,不启用KeepAlive功能。

-n requests
在测试会话中所执行的请求个数。 默认时,仅执行一个请求,但通常其结果不具有代表意义。

-p POST-file
包含了需要POST的数据的文件.

-P proxy-auth-username:password
对一个中转代理提供BASIC认证信任。 用户名和密码由一个:隔开,并以base64编码形式发送。无论服务器是否需要(即, 是否发送了401认证需求代码),此字符串都会被发送。

-q
如果处理的请求数大于150, ab每处理大约10%或者100个请求时,会在stderr输出一个进度计数。 此-q标记可以抑制这些信息。

-s
用于编译中(ab -h会显示相关信息)使用了SSL的受保护的https, 而不是http协议的时候。此功能是实验性的,也是很简陋的。最好不要用。

-S
不显示中值和标准背离值, 而且在均值和中值为标准背离值的1到2倍时,也不显示警告或出错信息。 默认时,会显示 最小值/均值/最大值等数值。(为以前的版本提供支持)。

-t timelimit
测试所进行的最大秒数。其内部隐含值是-n 50000。 它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。

-T content-type
POST数据所使用的Content-type头信息。

-v verbosity
设置显示信息的详细程度 – 4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。

-V
显示版本号并退出。

-w
以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。

-x < table >-attributes
设置< table >属性的字符串。 此属性被填入


-X proxy[:port]
对请求使用代理服务器。

-y < tr >-attributes
设置< tr >属性的字符串。

-z < td >-attributes
设置< td >属性的字符串。

以上参数最常用的是-n 在测试会话中所执行的请求个数;和-c 一次同时产生的并发请求个数。

2.3 实例

假设我们要测试一个网站,其中一个性能测试用例是:“同时处理50个并发请求并运行 1000 次网站首页”,我们可以在cmd shell中输入
ab -n 1000 -c 50 http://www.baidu.com/
n请求总数,c并发个数,运行结束后,ab会自动显示测试结果,如下:

Server Software: Apache/2.0.55
Server Hostname: localhost
Server Port: 80

Document Path: /1.php
Document Length: 82522 bytes #请求文档大小

Concurrency Level: 50 #并发数
Time taken for tests: 92.76140 seconds #全部请求完成耗时
Complete requests: 10000 #全部请求数
Failed requests: 1974 #失败的请求
(Connect: 0, Length: 1974, Exceptions: 0)
Write errors: 0
Total transferred: 827019400 bytes #总传输大小
HTML transferred: 825219400 bytes
Requests per second: 108.61 [#/sec] (mean) #每秒请求数(平均)
Time per request: 460.381 [ms] (mean) #每次并发请求时间(所有并发)
Time per request: 9.208 [ms] (mean, across all concurrent requests) #每一请求时间(并发平均)
Transfer rate: 8771.39 [Kbytes/sec] received #传输速率

Connection Times (ms) #连接时间
min mean[+/-sd] median max
Connect(#连接): 0 0 2.1 0 46
Processing(#处理): 31 458 94.7 438 1078
Waiting(#等待): 15 437 87.5 422 938
Total: 31 458 94.7 438 1078

3问题
程序中有各种静态声明的固定长度的缓冲区。 另外,对命令行参数、服务器的响应头和其他外部输入的解析也很简


无限星辰 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明使用apachebench进行网站压力测试ab.exe!
喜欢 (0)
[]
分享 (0)

您必须 登录 才能发表评论!