找回密码
 注册
首页 ≡≡网络技术≡≡ 服务器 Apache自带的性能测试工具ab的使用

Apache自带的性能测试工具ab的使用

灰儿 2009-6-20 10:05:31
本帖最后由 灰儿 于 2009-6-20 10:54 编辑

  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 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
  -h Display usage information (this message)
  * 中文的列表可以查看Apache手册中文版。
  以上参数最常用的是-n 在测试会话中所执行的请求个数;和-c 一次同时产生的并发请求个数。
  2.3 实例
  假设我们要测试一个PHP论坛系统,我执行了这样一个命令 ab -n 10 -c 10 http://www.sq01.cn/bbs/index.php。这个命令的意思是运行ab ,同时向 www.sq01.cn/bbs/index.php 发送10个并发请求(-c 10)。共发送10次(-n 10) ,

我们可以在cmd shell中输入:
C:\Program Files\Apache2.2\bin>ab -n 10 -c 10 http://www.sq01.cn/bbs/index.php

运行结束后,ab会自动显示测试结果(红色部分是我添加的注释),内容如下:

This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 1997-2005 The Apache Software Foundation, http://www.apache.org/

Benchmarking www.sq01.cn/bbs/index.php (be patient).....done

Server Software:        GWS/2.1
Server Hostname:        www.sq01.cn/bbs/index.php
Server Port:            80

Document Path:          /
Document Length:        230 bytes

Concurrency Level:      10
/*整个测试持续的时间*/
Time taken for tests:   3.234651 seconds
/*完成的请求数量*/
Complete requests:      10
/*失败的请求数量*/
Failed requests:        0
Write errors:           0
Non-2xx responses:      10
Keep-Alive requests:    10
/*整个场景中的网络传输量*/
Total transferred:      6020 bytes
/*整个场景中的HTML内容传输量*/
HTML transferred:       2300 bytes
/*大家最关心的指标之一,相当于 LR 中的 每秒事务数 ,后面括号中的 mean 表示这是一个平均值*/
Requests per second:    3.09 [#/sec] (mean)
/*大家最关心的指标之二,相当于 LR 中的 平均事务响应时间 ,后面括号中的 mean 表示这是一个平均值*/
Time per request:       3234.651 [ms] (mean)
/*这个还不知道是什么意思,有知道的朋友请留言*/
Time per request:       323.465 [ms] (mean, across all concurrent requests)
/*平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题*/
Transfer rate:          1.55 [Kbytes/sec] received
/*网络上消耗的时间的分解,各项数据的具体算法还不是很清楚*/
Connection Times (ms)
              min mean[+/-sd] median   max
Connect:       20 318 926.1     30    2954
Processing:    40 2160 1462.0   3034    3154
Waiting:       40 2160 1462.0   3034    3154
Total:         60 2479 1276.4   3064    3184

/*下面的内容为整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中 50% 的用户响应时间小于 3064 毫秒,60 % 的用户响应时间小于 3094 毫秒,最大的响应时间小于 3184 毫秒*/
Percentage of the requests served within a certain time (ms)
50%   3064
66%   3094
75%   3124
80%   3154
90%   3184
95%   3184
98%   3184
99%   3184
100%   3184 (longest request)

另外要指出的是,除了AB,还有许多优秀的服务器性能测试软件。另外,如果你的服务器不是Apache,请自行寻找测试方法。
您需要登录后才可以回帖 登录 | 注册
学习中心
站长自定义文字内容,利用碎片时间,随时随地获取优质内容。
Q设计语言 了解更多
Q Design 提供商家设计所需的指导与资源,帮商家快速完成产品设计、降低生产成本。
学习中心
站长自定义文字内容,利用碎片时间,随时随地获取优质内容。
Q设计语言 了解更多
Q Design 提供商家设计所需的指导与资源,帮商家快速完成产品设计、降低生产成本。