• ab性能测试工具


    Apache自带的压力测试工具——ab初体验

        我们知道压力测试的软件确实很多,诸如微软的WAST,惠普的LoadRunner以及等等其他的,但这些软件学习起来还是需要花费些时间,在选择上实在头痛,后来在郭欣的那本《构建高性能WEB站点》上看到了他介绍的这款Apache自带的压力测试工具ab,十分喜爱,于是今天终于有机会体验下ab对网站的压力测试。

        实验之前我的apache已经安装了,操作系统:Ubuntu 10.04 VMware 7.0

    1、先查看一下版本信息 ab -V(注意是大写的V)

    1. studiogang@studiogang:~$ ab -V
    2. This is ApacheBench, Version 2.3 <$Revision: 655654 $>
    3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    4. Licensed to The Apache Software Foundation, http://www.apache.org/

    2、我们也可以使用小写的v查看下ab命令的一些属性 ab -v

    1. studiogang@studiogang:~$ ab -v
    2. ab: option requires an argument -- v
    3. ab: wrong number of arguments
    4. Usage: ab [options] [http[s]://]hostname[:port]/path
    5. Options are:
    6. -n requests Number of requests to perform
    7. -c concurrency Number of multiple requests to make
    8. -t timelimit Seconds to max. wait for responses
    9. -b windowsize Size of TCP send/receive buffer, in bytes
    10. -p postfile File containing data to POST. Remember also to set -T
    11. -u putfile File containing data to PUT. Remember also to set -T
    12. -T content-type Content-type header for POSTing, eg.
    13. 'application/x-www-form-urlencoded'
    14. Default is 'text/plain'
    15. -v verbosity How much troubleshooting info to print
    16. -w Print out results in HTML tables
    17. -i Use HEAD instead of GET
    18. -x attributes String to insert as table attributes
    19. -y attributes String to insert as tr attributes
    20. -z attributes String to insert as td or th attributes
    21. -C attribute Add cookie, eg. 'Apache=1234. (repeatable)
    22. -H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
    23. Inserted after all normal header lines. (repeatable)
    24. -A attribute Add Basic WWW Authentication, the attributes
    25. are a colon separated username and password.
    26. -P attribute Add Basic Proxy Authentication, the attributes
    27. are a colon separated username and password.
    28. -X proxy:port Proxyserver and port number to use
    29. -V Print version number and exit
    30. -k Use HTTP KeepAlive feature
    31. -d Do not show percentiles served table.
    32. -S Do not show confidence estimators and warnings.
    33. -g filename Output collected data to gnuplot format file.
    34. -e filename Output CSV file with percentages served
    35. -r Don't exit on socket receive errors.
    36. -h Display usage information (this message)
    37. -Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
    38. -f protocol Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)

    3、现在我们就对51CTO的网站进行一次压力测试吧,使用命令ab -n1000 -c10 http://www.51cto.com/index.php,其中 -n1000 表示总请求数 -c10表示并发用户数为10 http://www.51cto.com/index.php 表示请求的URL,下面是测试的结果,其中我们最关心的三个指标,我已经注释出来了。

    1. studiogang@studiogang:~$ ab -n1000 -c10 http://www.51cto.com/index.php
    2. This is ApacheBench, Version 2.3 <$Revision: 655654 $>
    3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    4. Licensed to The Apache Software Foundation, http://www.apache.org/
    5. Benchmarking www.51cto.com (be patient)
    6. Completed 100 requests
    7. Completed 200 requests
    8. Completed 300 requests
    9. Completed 400 requests
    10. Completed 500 requests
    11. Completed 600 requests
    12. Completed 700 requests
    13. Completed 800 requests
    14. Completed 900 requests
    15. Completed 1000 requests
    16. Finished 1000 requests
    17. /*WEB服务器用的是nginx*/
    18. Server Software: nginx
    19. Server Hostname: www.51cto.com
    20. Server Port: 80
    21. Document Path: /index.php
    22. Document Length: 154 bytes
    23. Concurrency Level: 10
    24. Time taken for tests: 74.373 seconds
    25. Complete requests: 1000
    26. Failed requests: 0
    27. Write errors: 0
    28. Non-2xx responses: 1000
    29. Total transferred: 330000 bytes
    30. HTML transferred: 154000 bytes
    31. /*大家最关心的指标之一,指的是吞吐率
    32. 相当于 LR 中的 每秒事务数 ,后面括号中的 mean 表示这是一个平均值*/
    33. Requests per second: 13.45 [#/sec] (mean)
    34. /*大家最关心的指标之二,指的是用户平均请求等待时间
    35. 相当于 LR 中的 平均事务响应时间 ,后面括号中的 mean 表示这是一个平均值*/
    36. Time per request: 743.726 [ms] (mean)
    37. /*大家最关心的指标之三,指的是服务器平均请求处理时间
    38. Time per request: 74.373 [ms] (mean, across all concurrent requests)
    39. Transfer rate: 4.33 [Kbytes/sec] received
    40. Connection Times (ms)
    41. min mean[+/-sd] median max
    42. Connect: 129 163 245.3 145 3154
    43. Processing: 129 576 1510.8 147 11756
    44. Waiting: 129 567 1502.0 147 11756
    45. Total: 261 739 1543.7 294 11888
    46. Percentage of the requests served within a certain time (ms)
    47. 50% 294
    48. 66% 297
    49. 75% 304
    50. 80% 308
    51. 90% 1290
    52. 95% 3452
    53. 98% 7582
    54. 99% 7962
    55. 100% 11888 (longest request)

    4、为了使结果更有对比性,我们将并发用户更改为100个进行压力测试,我这里只将三个指标贴出来。

    1. Requests per second: 190.95 [#/sec] (mean)
    2. Time per request: 523.694 [ms] (mean)
    3. Time per request: 5.237 [ms] (mean, across all concurrent requests)

    5、将并发用户改为200个进行测试

    1. Requests per second: 186.00 [#/sec] (mean)
    2. Time per request: 1149.433 [ms] (mean)
    3. Time per request: 5.747 [ms] (mean, across all concurrent requests)

    6、500个并发用户时的情况

    1. Requests per second: 180.99 [#/sec] (mean)
    2. Time per request: 2631.662 [ms] (mean)
    3. Time per request: 5.263 [ms] (mean, across all concurrent requests)

         我们来分析下测试的结果,先对比下吞吐率,当并发用户的时候吞吐率最高为190 reqs/s,当并发用户数为200,500 吞吐率下降了,随之用户的等待时间更是明显增加了,已经有2s的等待时间了。这说明性能明显下降了。当然分析这个测试结果并不是说明51CTO的网站的并发用户只能在500左右,因为我是在服务器负荷的情况下就行测试的,这显然不能说明问题。另外我们在生产环境下测试的时候,最好能将测试结果做成报表,这样可以非常清晰地对比出问题来,好了,我该准备下,给上面提交一份我们公司网站的测试报告了。

    http://studiogang.blog.51cto.com/505887/386852

    网站压力测试工具ab使用详解
    
    就是APACHE自带的测试工具AB(apache benchmark).在APACHE的bin目录下。
    格式: ./ab [options] [http://]hostname[:port]/path
    参数:
    -n requests     Number of requests to perform
    //在测试会话中所执行的请求个数。默认时,仅执行一个请求
    -c concurrency Number of multiple requests to make
    //一次产生的请求个数。默认是一次一个。 
    -t timelimit    Seconds to max. wait for responses
    //测试所进行的最大秒数。其内部隐含值是-n 50000。它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。
        -p postfile     File containing data to POST
    //包含了需要POST的数据的文件. 
    -T content-type Content-type header for POSTing
    //POST数据所使用的Content-type头信息。
    -v verbosity    How much troubleshooting info to print
    //设置显示信息的详细程度 - 4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。 -V 显示版本号并退出。
        -w              Print out results in HTML tables
    //以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。
        -i              Use HEAD instead of GET
    // 执行HEAD请求,而不是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)
    //-C cookie-name=value 对请求附加一个Cookie:行。 其典型形式是name=value的一个参数对。此参数可以重复。
    -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.
    //-P proxy-auth-username:password 对一个中转代理提供BASIC认证信任。用户名和密码由一个:隔开,并以base64编码形式发送。无论服务器是否需要(即, 是否发送了401认证需求代码),此字符串都会被发送。
    -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)
    //-attributes 设置 属性的字符串. 缺陷程序中有各种静态声明的固定长度的缓冲区。另外,对命令行参数、服务器的响应头和其他外部输入的解析也很简单,这可能会有不良后果。它没有完整地实现 HTTP/1.x; 仅接受某些'预想'的响应格式。 strstr(3)的频繁使用可能会带来性能问题,即, 你可能是在测试ab而不是服务器的性能。
    参数很多,一般我们用 -c 和 -n 参数就可以了. 例如:
    ./ab -c 1000 -n 1000 
    http://127.0.0.1/index.php
    这个表示同时处理1000个请求并运行1000次index.php文件.
    #/usr/local/xiaobai/apache2054/bin/ab -c 1000 -n 1000 
    http://127.0.0.1/index.html.zh-cn.gb2312
    
    This is ApacheBench, Version 2.0.41-dev  apache-2.0
    Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, 
    http://www.zeustech.net/
    Copyright (c) 1998-2002 The Apache Software Foundation, 
    http://www.apache.org/
    Benchmarking 127.0.0.1 (be patient)
    Completed 100 requests
    Completed 200 requests
    Completed 300 requests
    Completed 400 requests
    Completed 500 requests
    Completed 600 requests
    Completed 700 requests
    Completed 800 requests
    Completed 900 requests
    Finished 1000 requests
    Server Software:        Apache/2.0.54
    //平台apache 版本2.0.54
    Server Hostname:        127.0.0.1
    //服务器主机名
    Server Port:            80
    //服务器端口
    Document Path:          /index.html.zh-cn.gb2312
    //测试的页面文档
    Document Length:        1018 bytes
    //文档大小
    Concurrency Level:      1000 
    //并发数
    Time taken for tests:   8.188731 seconds
    //整个测试持续的时间
    Complete requests:      1000
    //完成的请求数量
    Failed requests:        0
    //失败的请求数量
    Write errors:           0
    Total transferred:      1361581 bytes
    //整个场景中的网络传输量
    HTML transferred:       1055666 bytes
    //整个场景中的HTML内容传输量
    Requests per second:    122.12 [#/sec] (mean)
    //大家最关心的指标之一,相当于 LR 中的 每秒事务数 ,后面括号中的 mean 表示这是一个平均值
    Time per request:       8188.731 [ms] (mean)
    //大家最关心的指标之二,相当于 LR 中的 平均事务响应时间 ,后面括号中的 mean 表示这是一个平均值
    Time per request:       8.189 [ms] (mean, across all concurrent requests)
    //每个请求实际运行时间的平均值
    Transfer rate:          162.30 [Kbytes/sec] received
    //平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题
    Connection Times (ms)
    min mean[+/-sd] median   max
    Connect:        4 646 1078.7     89    3291
    Processing:   165 992 493.1    938    4712
    Waiting:      118 934 480.6    882    4554
    Total:        813 1638 1338.9   1093    7785
    //网络上消耗的时间的分解,各项数据的具体算法还不是很清楚
    Percentage of the requests served within a certain time (ms)
    50%   1093
    66%   1247
    75%   1373
    80%   1493
    90%   4061
    95%   4398
    98%   5608
    99%   7368
    100%   7785 (longest request)
    //整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于1093 毫秒,
    60% 的用户响应时间小于1247 毫秒,最大的响应时间小于7785 毫秒 由于对于并发请求,cpu实际上并不是同时处理的,而是按照每个请求获得的时间片逐个轮转处理的,
    所以基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求数

    Apache压力测试工具ab使用详解

          Apache附带的压力测试工具ab,非常容易使用,并且完全可以摸你各种条件对Web服务器发起测试请求。ab可以直接在Web服务器本地发起测试请求,这对于需要了解服务器的处理性能至关重要,因为它不包括数据的网络传输时间以及用户PC本地的计算时间。       下面我们开始压力测试(环境说明:win7,需要在命令行cmd中切换至ab.exe所在目录),执行以下命令:

    ab -n1000 -c10 http://localhost/index.php/
    

          执行结果如下:

    This is ApacheBench, Version 2.3 <$Revision: 655654 $>
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking localhost (be patient)
    Completed 100 requests
    Completed 200 requests
    Completed 300 requests
    Completed 400 requests
    Completed 500 requests
    Completed 600 requests
    Completed 700 requests
    Completed 800 requests
    Completed 900 requests
    Completed 1000 requests
    Finished 1000 requests
    
    Server Software:        Apache/2.2.21
    Server Hostname:        localhost
    Server Port:            80
    
    Document Path:          /index.php/
    Document Length:        0 bytes
    
    Concurrency Level:      10
    Time taken for tests:   1.047 seconds
    Complete requests:      1000
    Failed requests:        0
    Write errors:           0
    Total transferred:      187000 bytes
    HTML transferred:       0 bytes
    Requests per second:    955.06 [#/sec] (mean)
    Time per request:       10.471 [ms] (mean)
    Time per request:       1.047 [ms] (mean, across all concurrent requests)
    Transfer rate:          174.41 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   0.5      0       4
    Processing:     2   10   4.5      9      42
    Waiting:        2   10   4.5      9      41
    Total:          2   10   4.5      9      42
    
    Percentage of the requests served within a certain time (ms)
      50%      9
      66%     11
      75%     13
      80%     15
      90%     17
      95%     18
      98%     20
      99%     21
     100%     42 (longest request)
    

    1.执行ab时3个参数的意思分别表示:

    -n1000 :总请求数为1000 -c10 :并发用户数为10 http://localhost/index.php/ :表示这些请求的目标url

    2.ab测试结果的各项说明:

    Server Software:表示被测试的Web服务器软件名称 Server Hostname:表示请求的URL中的主机名称,这里是localhost Server Port:表示被测试的Web服务器软件的监听端口 Document Path:表示请求的URL中的根绝对路径 Document Length:表示HTTP响应数据的正文长度 Concurrency Level:表示并发用户数,这是我们设置的参数 Time taken for tests:表示所有这些请求被处理完成所要花费的总时间 Complete requests:表示总请求数,这也是我们设置的参数 Failed requests:表示失败的总请求数,这里的失败指请求在连接服务器、发送数据、接收数据等环节发生异常,以及无响应超时等情况 Total transferred:表示所有请求的响应数据长度总和,包括HTTP响应的头信息和正文数据的长度 HTML transferred:表示所有请求的响应数据中正文数据的总和 Requests per second:表示服务器吞吐率(这是我们应该重点关注的) Time per request:表示用户平均请求的等待时间 Time per request (mean, across all concurrent requests):表示服务器平均请求处理时间 Transfer rate:表示这些请求在单位时间内从服务器获取的数据长度 Percentage of the requests served within a certain time (ms):这部分数据描述每个请求处理时间的分布情况

  • 相关阅读:
    .NET程序默认启动线程数
    TPL中Task执行的内联性线程重入
    Unity容器中的对象生存期管理
    C# 异步 TCP 服务器完整实现
    WPF中多源控制Button的状态
    C# 对 TCP 客户端的状态封装
    WPF异步MVVM等待窗体
    C#实现UDP分包组包
    C#实现RTP数据包传输
    PHP 传引用调用
  • 原文地址:https://www.cnblogs.com/qmfsun/p/4311295.html
Copyright © 2020-2023  润新知