apachebench的简单使用1

ApacheBench Apache 附带的一个小工具专门用于 HTTP Server benchmark testing可以同时模拟多个并发请求。

ab的基本格式:

 

 NAME
ab - Apache HTTP server benchmarking tool
SYNOPSIS
ab [ -A auth-username:password ] [ -b windowsize ] [ -c concurrency ] [ -C cookie-name=value ] [ -d ] [ -e csv-file ] [ -f protocol ] [ -g gnuplot-file ] [ -h ] [ -H custom-header ] [ -i ]
[ -k ] [ -n requests ] [ -p POST-file ] [ -P proxy-auth-username:password ] [ -q ] [ -r ] [ -s ] [ -S ] [ -t timelimit ] [ -T content-type ] [ -u PUT-file ] [ -v verbosity] [ -V ] [ -w ] [
-x -attributes ] [ -X proxy[:port] ] [ -y -attributes ] [ -z
-attributes ] [ -Z ciphersuite ] [http[s]://]hostname[:port]/path

    针对百度的一个简单的测试以及结果:
   

    [root@nginx1 ~]# ab -n 100 -c 10 http://www.baidu.com/                  ###-n:发出的请求数  -c:每次的并发数
    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 2006 The Apache Software Foundation, http://www.apache.org/

    Benchmarking www.baidu.com (be patient).....done


    Server Software: BWS/1.0                   ###服务器的信息
    Server Hostname: www.baidu.com             ###域名
    Server Port: 80                            ###连接的端口
    Document Path: /                           ###请求的URI
    Document Length: 10530 bytes               ###第一次返回文档的大小。如果文档大小在测试的时候改变了,那么这个响应会视为一个错误。

    Concurrency Level: 10                      ###并发数
    Time taken for tests: 29.32944 seconds     ###开始到结束的时间
    Complete requests: 100                     ###成功的请求数
    Failed requests: 42                        ###失败的请求数
    (Connect: 0, Length: 42, Exceptions: 0)    ###详细的多少个连接失败,长度异常,读取失败
    Write errors: 0                            ###在发送的时候失败的次数
    Total transferred: 1131908 bytes           ###从服务器接收的字节数。这是明确的网络发送字节。
    HTML transferred: 1084140 bytes            ###html内容传输量
    Requests per second: 3.44 [#/sec] (mean)   ###每秒请求数
    Time per request: 2903.294 [ms] (mean)     ###每个并发的时间
    Time per request: 290.329 [ms] (mean, across all concurrent requests)   ###个人理解是每个并发中每个请求的时间
    Transfer rate: 38.06 [Kbytes/sec] received ###每秒的网络流量

    Connection Times (ms)             
    min mean[+/-sd] median max
    Connect: 37 1003 809.6 898 4056                     ###socket发出请求到建立连接所花的时间。
    Processing: 253 1713 861.2 1800 5643                ###连接建立后,直到http全部接收所用的时间。
    Waiting: 42 759 711.5 715 4886                      ###发送http完后,到接到第一个byte所等待的时间。
    Total: 336 2717 1248.4 2739 6655                    ###conn+processing



###下面的内容为整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中 50% 的用户响应时间小于 3064 毫秒,60 % 的用户响应时间小于 3094 毫秒,最大的响应时间小于 3184 毫秒

    Percentage of the requests served within a certain time (ms)
    50% 2739
    66% 3017
    75% 3141
    80% 3187
    90% 3998
    95% 5607
    98% 6095
    99% 6655
    100% 6655 (longest request)

 

更多参数:

-A auth-username:password
    有的请求需要用户名和密码进行验证:(例如:401 验证需求).
-b windowsize
    TCP 发送和接收的buffer大小,单位是 bytes
-c concurrency
    并发数,同一时间有多少请求发出去,默认是1。
-C cookie-name=value
    加上Cookie:以“ name=value ”的形式,可以重复 -C xx1=yy1 -C xx2=yy2。
-d
    不展示"percentage served within XX [ms] table".
-e csv-file
    写一个逗号分隔的CSV文件,包含每个百分比(from 1% to 100%)服务器执行的时间(毫秒),这个文件一般比'gunplot'有用。
-f protocol
    指定 SSL/TLS 协议 (SSL2, SSL3, TLS1, or ALL).
-g gnuplot-file
    写所有有用的信息到TSV(Tab separate values)文件,可以轻松导入Excel等里面,label在文件第一行。
-h
    展示帮助信息
-H custom-header
    加入额外的头信息。以冒号分割,例如("Accept-Encoding: zip/zop;8bit"-i
    发送GET请求
-k
    打开Http的keepalive功能。在一个http会话里执行多个请求。默认不开启。
-n requests
    要执行的请求校验次数。默认请求一次,请求一次的结果不能代表校验结果,不准确。
-p POST-file
    包含POST数据文件
-P proxy-auth-username:password
    支持基本Auth代理路由验证。在(http code : 407 的时候需要)
-q
    当程序有150个请求,输出以每10%或100个来显示。-q 用来取消这些信息。
-r
    在socket错误的时候不退出。
-s
    如果用在SSl协议,功能还处在试验阶段,你不需要用它。
-S
    不展示终止和标准值,也不展示警告信息。
-t timelimit
    校验花费的最大时间,内部设置-n 50000 次。使用这个选项在特定时间内测试。默认不开启
-T content-type
    用于POST/PUT 数据,例如eg. application/x-www-form-urlencoded. Default: text/plain.
-u PUT-file
    PUT 的文件,记着加上-T
-v verbosity
    设置输出等级, 4 输出头信息,3 输出响应码(404,200) 2 输出警告和信息
-V
    展示版本,然后退出。
-w
    输出结果到html里的table,默认两列,白色背景。
-x -attributes
    String to use as attributes for 
. Attributes are inserted 
.
-X proxy[:port]
    使用代理。
-y -attributes
    设置属性到 .
-z 
-attributes
    设置属性到     .
-Z ciphersuite
    指定 SSL/TLS 密码套件 (See openssl ciphers).

来源:http://blog.chinaunix.net/uid-14010457-id-3512262.html

 

posted @ 2016-05-10 21:28  墙头一颗草  Views(292)  Comments(0Edit  收藏  举报