zoukankan      html  css  js  c++  java
  • ab压测札记(Apache Bench)

    1 ab安装

    ab实际上是apache httpd里面的一个工具或者说子模块,安装apache httpd可以参考另一篇文章JBOSS集群的2.3节

    安装目录:/apache目录/bin/,如下

    2 参数解释

    -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) .

    3 执行命令

    语法格式:

    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

    测试结果及解释(载自网络):

    [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)

    4 关于-p (post file)

    关于post file ,个人觉的这是一个很啃爹的问题,网上资料很少,官网也没有详细说明,以至于我通过post传文件参数的形式,发现服务器端接受到了请求,但是没有收到post的数据,但如果是直接在地址后面加上?paramName=paramValue的方式就是OK的,所以可以确定在-p这边对文件的格式或者编码是有要求的,只不过是没有找到相关说明而已。

    总结如果要使用post file,注意

    a. content-type一定要设置成为application/x-www-form-urlencoded ,即 -T ‘application/x-www-form-urlencoded’

    b. 关于-p 文件,后面跟的这个文件最好用vi命令创建,如果是txt有可能会失败

    c. 文件里面的内容test1=a&test2=b

    1.  
  • 相关阅读:
    sql优化
    mysql_存储过程_后一行减去前一行
    python基础笔记
    atom使用markdown
    tensorboard遇到的坑
    WordPaster-Firefox浏览器控件安装方法
    WordPaster.exe安装教程
    Web大文件上传控件-bug修复-Xproer.HttpUploader6
    Web大文件下载控件更新-Xproer.HttpDownloader
    Web大文件上传控件-asp.net-bug修复-Xproer.HttpUploader6.2
  • 原文地址:https://www.cnblogs.com/jager/p/5400779.html
Copyright © 2011-2022 走看看