zoukankan      html  css  js  c++  java
  • 压测工具ab的简单使用

    apache benchmark(ab)是一种常见的压测工具,不仅可以对apache进行压测,也可以对nginx,tomcat,IIS等进行压测

    安装

    如果安装了apache,那么ab已经自带了,不需要再额外安装,如果没有安装apache,可以通过以下方式安装

    # ubuntu
    sudo apt-get install apache2-util
    
    # centos
    yum -y install httpd-tools
    

    压测

    在压测前,需要关注几个选项,通过ab --help查看

    -n  requests       要执行的请求次数
    -c  concurrency    并发数量
    -s  timeout        响应时间
    

    #### 执行

    执行以下代码进行压测

    ab -n 1000 -c 100 -s 1 http://127.0.0.1:1080/index
    # 一共1000个请求,并发100,超时时间为1s,后面为测试的url
    

    测试结果
    apr_pollset_poll: The timeout specified has expired (70007)
    Total of 997 requests completed
    

    显示有997个请求完成了,而且报错了,说明有请求超过1s,所以把超时时间去掉重新测试

    ab -n 1000 -c 100 http://127.0.0.1:1080/index
    

    结果
    Server Software:        nginx/x.x.x
    Server Hostname:        www.my.com
    Server Port:            80
    
    Document Path:          /
    Document Length:        2368 bytes
    
    Concurrency Level:      100
    Time taken for tests:   30.914 seconds
    Complete requests:      1000
    Failed requests:        0
    Write errors:           0
    Total transferred:      2527000 bytes
    HTML transferred:       2368000 bytes
    Requests per second:    32.35 [#/sec] (mean)
    Time per request:       3091.393 [ms] (mean)
    Time per request:       30.914 [ms] (mean, across all concurrent requests)
    Transfer rate:          79.83 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0  174 381.6      0    2006
    Processing:     1 2391 6166.6    205   25853
    Waiting:        1 2080 5941.6    205   25853
    Total:          2 2565 6143.6    406   26609
    
    Percentage of the requests served within a certain time (ms)
      50%    406
      66%   1004
      75%   1413
      80%   1616
      90%   6448
      95%  25760
      98%  25824
      99%  25855
     100%  26609 (longest request)
    

    这里我们需要关注以下几个数据

    1)Failed requests:失败的请求

    2)Requests per second:也就是常说的QPS, 每秒查询率,这是一个平均值

    3)Time per request:完成一个请求所花费的时间

    4)Transfer rate: 网络传输速度。 对于大文件的请求测试,这个值很容易成为系统瓶颈所在 要确定该值是不是瓶颈,需要了解客户端和被测服务器之间的网络情况,包括网络带宽和网卡速度等信息。

  • 相关阅读:
    Codeforces Gym 100015F Fighting for Triangles 状压DP
    Codeforces Gym 100015B Ball Painting 找规律
    Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律
    Codeforces Gym 100231G Voracious Steve 记忆化搜索
    Codeforces Gym 100231F Solitaire 折半搜索
    Codeforces Gym 100231L Intervals 数位DP
    Codeforces Gym 100231B Intervals 线段树+二分+贪心
    Codeforces Round #339 (Div. 1) A. Peter and Snow Blower 计算几何
    Codeforces Round #339 (Div. 2) B. Gena's Code 水题
    Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题
  • 原文地址:https://www.cnblogs.com/zzliu/p/11924151.html
Copyright © 2011-2022 走看看