zoukankan      html  css  js  c++  java
  • ab测试工具使用

    安装:

    centos : yum install httpd-tools

    ubuntu: apt-get install apache2-utils

    官网英文版: http://httpd.apache.org/docs/2.2/programs/ab.html

    ab - Apache HTTP server 性能工具

    ab是校准http(Hypertext Transfer Protocol 超文本协议)服务器的工具。展示服务器每秒能处理多少请求。

    使用:

    ab -n 30 -c 2 -p post.txt http://127.0.0.1:9090/query
    发送30次请求,每次发两个,post的body在post.txt里。
    
    ab -n 30 -c 2 -i http://127.0.0.1:9090/get
    发送30个请求,每次发两个,get请求。

    提要:

    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 <table>-attributes ] [ -X proxy[:port] ] [ -y <tr>-attributes ] [ -z <td>-attributes ] [ -Z ciphersuite ] 
    [http[s]://]hostname[:port]/path

    选项:

    -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 <table>-attributes
        String to use as attributes for <table>. Attributes are inserted <table here >.
    -X proxy[:port]
        使用代理。
    -y <tr>-attributes
        设置属性到 <tr>.
    -z <td>-attributes
        设置属性到 <td>.
    -Z ciphersuite
        指定 SSL/TLS 密码套件 (See openssl ciphers).

    输出内容:

    Server Software
        服务器的信息
    Server Hostname
        DNS 或 IP 地址
    Server Port
        连接的端口,如果不存在就是默认的80(http)或443(https)
    SSL/TLS Protocol
        客户端和服务端的信息,只在SSL请求的时候使用。
    Document Path
        请求的URI
    Document Length
        第一次返回文档的大小。如果文档大小在测试的时候改变了,那么这个响应会视为一个错误。
    Concurrency Level
        并发数
    Time taken for tests
        从第一个socket连接建立 到 最后一个响应收到回复 所用到的时间。
    Complete requests
        成功收到响应的请求数。
    Failed requests
        视为失败的请求数。如果>0,另一行会输出多少由于连接失败、读取失败、不正确的文本长度或异常。
    Write errors
        在发送的时候失败的次数
    Non-2xx responses
        输出响应不是200的响应。如果所有响应都是200,这个字段就不输出了。
    Keep-Alive requests
        保持Keep-Alive的请求数。
    Total body sent
        如果测试的时候配置了发送数据,这里是发送总大写(bytes)。在没发送body的时候这个字段也会被忽略。
    Total transferred
        从服务器接收的字节数。这是明确的网络发送字节。
    HTML transferred
        从服务器上接受的文档自己数。这里排除了http头信息。
    Requests per second
        每秒处理的请求数。这是平均数。
    Time per request
        每个请求所使用的平均时间。
    Transfer rate
        实际的速度:接收速度,发送速度,总速度。
    Connection Times (ms)
        连接处理时间
        min:    最小值
        mean: 平均值
        median: 中间值
        max:    最大值
        Connect:    socket发出请求到建立连接所花的时间。
        Processing:   连接建立后,直到http全部接收所用的时间。
        Waiting:    发送http完后,到接到第一个byte所等待的时间。
        Total:      Connect+Processing
        
  • 相关阅读:
    菜根谭#317
    菜根谭#316
    菜根谭#315
    菜根谭#314
    菜根谭#313
    菜根谭#312
    菜根谭#311
    菜根谭#310
    菜根谭#309
    Matlab xpC启动盘
  • 原文地址:https://www.cnblogs.com/wanself/p/2805716.html
Copyright © 2011-2022 走看看