一聚教程网:一个值得你收藏的教程网站

热门教程

apache压力测试工具ab压测参数解释

时间:2022-06-30 18:06:52 编辑:袖梨 来源:一聚教程网

ab是apache自带的一个很好用的压力测试工具,当安装完apache的时候,就可以在bin下面找到ab

 

1 我们可以模拟100个并发用户,对一个页面发送1000个请求

./ab -n1000 -c100 http://vm1.jianfeng.com/a.html

 

其中-n代表请求数,-c代表并发数

 

返回结果:

##首先是apache的版本信息
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking vm1.jianfeng.com (be patient)


Server Software:        Apache/2.2.19    ##apache版本
Server Hostname:        vm1.jianfeng.com   ##请求的机子
Server Port:            80 ##请求端口

Document Path:          /a.html
Document Length:        25 bytes  ##页面长度

Concurrency Level:      100  ##并发数
Time taken for tests:   0.273 seconds  ##共使用了多少时间
Complete requests:      1000   ##请求数
Failed requests:        0   ##失败请求
Write errors:           0 
Total transferred:      275000 bytes  ##总共传输字节数,包含http的头信息等
HTML transferred:       25000 bytes  ##html字节数,实际的页面传递字节数
Requests per second:    3661.60 [#/sec] (mean)  ##每秒多少请求,这个是非常重要的参数数值,服务器的吞吐量
Time per request:       27.310 [ms] (mean)  ##用户平均请求等待时间
Time per request:       0.273 [ms] (mean, across all concurrent requests)  ##服务器平均处理时间,也就是服务器吞吐量的倒数
Transfer rate:          983.34 [Kbytes/sec] received  ##每秒获取的数据长度

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   2.3      0      16
Processing:     6   25   3.2     25      32
Waiting:        5   24   3.2     25      32
Total:          6   25   4.0     25      48

Percentage of the requests served within a certain time (ms)
  50%     25  ## 50%的请求在25ms内返回
  66%     26  ## 60%的请求在26ms内返回
  75%     26
  80%     26
  90%     27
  95%     31
  98%     38
  99%     43
100%     48 (longest request)

 

 

 

2 ab也可以运行在windows中,如果在windows下安装apache,就可以在bin下找到ab.exe

直接就可以使用,不用依赖其他的dll

下面是我使用ab.exe 测试新浪一个页面的结果:

 

C:UsersnickyjfDesktopuseful>ab -n1000 -c100 http://sports.sina.com.cn/k/2011-05-24/12095590365.shtml
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking sports.sina.com.cn (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.0.63
Server Hostname:        sports.sina.com.cn
Server Port:            80

Document Path:          /k/2011-05-24/12095590365.shtml
Document Length:        86680 bytes

Concurrency Level:      100
Time taken for tests:   66.453 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      87135790 bytes
HTML transferred:       86680000 bytes
Requests per second:    15.05 [#/sec] (mean)
Time per request:       6645.294 [ms] (mean)
Time per request:       66.453 [ms] (mean, across all concurrent requests)
Transfer rate:          1280.51 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1   56 398.3      2    3003
Processing:    89 6331 2603.7   6293   14626
Waiting:        2 1748 1485.9   1590    6284
Total:         90 6388 2615.0   6302   14627

Percentage of the requests served within a certain time (ms)
  50%   6302
  66%   7121
  75%   8435
  80%   9193
  90%   9231
  95%   9385
  98%  11549
  99%  12459
100%  14627 (longest request)

 

3 apache的ab工具也算是一种ddos攻击工具

测试

Server Software: Apache/2.0.54
//web服务器平台
Server Hostname: 127.0.0.1
//服务器主机名
Server Port: 80
//服务器端口

Document Path: /index.html.zh-cn.gb2312
//测试的页面文档
Document Length: 1018 bytes
//文档大小

Concurrency Level: 1000
//并发数
Time taken for tests: 8.188731 seconds
//整个测试持续的时间
Complete requests: 1000
//完成的请求数量
Failed requests: 0
//失败的请求数量
Write errors: 0

Total transferred: 1361581 bytes
//整个场景中的网络传输量
HTML transferred: 1055666 bytes
//整个场景中的HTML内容传输量
Requests per second: 122.12 [#/sec] (mean)
//大家最关心的指标之一,相当于 LR 中的 每秒事务数 ,后面括号中的 mean 表示这是一个平均值
Time per request: 8188.731 [ms] (mean)
//大家最关心的指标之二,相当于 LR 中的 平均事务响应时间 ,后面括号中的 mean 表示这是一个平均值
Time per request: 8.189 [ms] (mean, across all concurrent requests)
//每个请求实际运行时间的平均值
Transfer rate: 162.30 [Kbytes/sec] received
//平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题

Connection Times (ms)
min mean[+/-sd] median max
Connect: 4 646 1078.7 89 3291
Processing: 165 992 493.1 938 4712
Waiting: 118 934 480.6 882 4554
Total: 813 1638 1338.9 1093 7785
//网络上消耗的时间的分解,各项数据的具体算法还不是很清楚

Percentage of the requests served within a certain time (ms)
50% 1093
66% 1247
75% 1373
80% 1493
90% 4061
95% 4398
98% 5608
99% 7368
100% 7785 (longest request)
//整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于1093 毫秒,60% 的用户响应时间小于1247 毫秒,最大的响应时间小于7785 毫秒

由于对于并发请求,cpu实际上并不是同时处理的,而是按照每个请求获得的时间片逐个轮转处理的,所以基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求数

    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
    -b windowsize Size of TCP send/receive buffer, in bytes
    -p postfile File containing data to POST. Remember also to set -T
    -u putfile File containing data to PUT. Remember also to set -T
    -T content-type Content-type header for POSTing, eg.
    ‘application/x-www-form-urlencoded’
    Default is ‘text/plain’
    -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
    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
    -r Don’t exit on socket receive errors.
    -h Display usage information (this message)
    -Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol Specify SSL/TLS protocol
    (SSL2, SSL3, TLS1 or ALL)

 

 

 

-A auth-username:password 支持基本的验证证书,用户名和密码之间使用”冒号” : 分隔开,ab将以明文方式传送过去.不管服务器是不是需要 ,也就是说你的服务器需要支持401认证.

-c concurrency 同时向服务器端发送的请求数目,默认状态下是一次 只执行一个http请求.

-C cookie-name=value Add a Cookie: line to the request. The argument is typically in the form of a name=value pair. This field is repeatable.

-d Do not display the “percentage served within XX [ms] table”. (legacy support).

-e csv-file Write a Comma separated value (CSV) file which contains for each percentage (from 1% to 100%) the time (in milli seconds) it took to serve that percentage of the requests. This is usually more useful than the ‘gnuplot’ file; as the results are already ‘binned’.

-g gnuplot-file Write all measured values out as a ‘gnuplot’ or TSV (Tab separate values) file. This file can easily be imported into packages like Gnuplot, IDL, Mathematica, Igor or even Excell. The labels are on the first line of the file.

-h 显示使用说明

-H custom-header 向请求包追加附加的标题字串.此参数应该是有效的标题 行(header line)形式,通常使用冒号”:”来分隔有效配对 (valid pair)例如 ‘Accept-Encoding: zip/zop;8 bit’;

-i 使用一个 http 头(HEAD) 来替换 GET方法.不可以掺入POST 方法

-k 允许http KeepAlive ;也就是说执行多个请求在一个 http 会话当中,默认是不允许的也就是no KeepAlive啦;)

-n requests 执行一次测试会话的时候所发出的请求数目,默认是执行一个单一的请求 当然了这样的测试结果也就没什么意义了

-p POST-file 测试程序也就是ab,将向Apache server发送带有HTTP POST 的请求.

-P proxy-auth-username:password 当需要通过代理测试一台HTTP 服务器的时候而你的代理 又需要用户名密码验证,这时你可以使用这个选项,同样 用户名与密码之间使用冒号”:”分隔开,ab将之以明文的方式 发送出去,当然,前提是你的代理是处于407认证状态的

-q When processing more than 150 requests, ab outputs a progress count on stderr every 10% or 100 requests or so. The -q flag will suppress these messages.

-s When compiled in (ab -h will show you) use the SSL protected https rather than the http protocol. This feature is experimental and very rudimentary. You probably do not want to use it.

-S Do not display the median and standard deviation values, nor display the warning/error messages when the average and median are more than one or two times the standard deviation apart. And default to the min/avg/max values. (legacy support).

-t timelimit 设置测试的时间的长短,使用这个选项ab将自动设置 测试请求会话数目为50000,然后以你设置的时间为 固定周期.默认状态下是没有时限的,也就是直到完成 你所设置的请求数目为止.

-T content-type 内容类型标头,使用在POST数据的时候.

-v verbosity 设置冗余级别,4级打印出每个请求标头的详细信息, 3级打印出回应代码(例如,404,200),2级打印出警告 信息和指示消息

-V 显示版本号并且退出

-w 打印输出结果到HTML表中. 默认的表是两列n行白底黑框

-x

-attributes 使用字串来描述表的属性,该属性字串应该插入到

-X proxy[:port] Use a proxy server for the requests.

-y

-attributes 用于生成html表格每行的属性名 ()

-z

-attributes 用于生成html表格每列的属性名 ()

热门栏目