zoukankan      html  css  js  c++  java
  • apachebench的简单使用

    apachebench的简单使用 2013-03-08 15:48:47

    分类: LINUX

        ApacheBench Apache 附带的一个小工具专门用于 HTTP Server benchmark testing可以同时模拟多个并发请求。
        需要针对web做压力测试,所以简单学习了一下,并做个记录。
       
        使用的环境是centos5.5,使用yum安装apache,ab工具在/usr/bin目录下:


    1. [root@nginx1 ~]# cat /etc/redhat-release
    2. CentOS release 5.5 (Final)
    3. [root@nginx1 ~]# ls /usr/bin/ab*
    4. /usr/bin/ab


        ab的基本格式:



    1. NAME
    2. ab - Apache HTTP server benchmarking tool
    3. SYNOPSIS
    4. 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 ]
    5. [ -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 ] [
    6. -x <table>-attributes ] [ -X proxy[:port] ] [ -y <tr>-attributes ] [ -z <td>-attributes ] [ -Z ciphersuite ] [http[s]://]hostname[:port]/path



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

    1. [root@nginx1 ~]# ab -n 100 -c 10 http://www.baidu.com/                  ###-n:发出的请求数  -c:每次的并发数
    2. This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
    3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    4. Copyright 2006 The Apache Software Foundation, http://www.apache.org/

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


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

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

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



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

    1. Percentage of the requests served within a certain time (ms)
    2. 50% 2739
    3. 66% 3017
    4. 75% 3141
    5. 80% 3187
    6. 90% 3998
    7. 95% 5607
    8. 98% 6095
    9. 99% 6655
    10. 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 <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).
  • 相关阅读:
    格式化字符串漏洞利用实战之 0ctf-easyprintf
    java多线程机制中的Thread和Runnable()区别
    Eclipse中部署Android开发环境插件安装问题方案
    java接口实现
    Visual Studio UML
    java子类继承关系
    Visual Studio UML类图
    java方法重载和重写
    javaSocket笔记
    python网络爬虫笔记(九)
  • 原文地址:https://www.cnblogs.com/zhengah/p/4332113.html
Copyright © 2011-2022 走看看