AB 压力测试工具ApacheBench ab压测参数分析

摘要: ab命令会创建很多的并发访问线程,模拟多个访问者同时对某一URL地址进行访问。它的测试目标是基于URL的,因此,既可以用来测试Apache的负载压力,也可以测试nginx、lighthttp、tomcat、IIS等其它Web服务器的压力。 ab命令对发出负载的计算机要求很低,既不会占用很高CPU,也不会占用很多内存,但却会给目标服务器造成巨大的负载,其原理类似CC攻击。自己测试使用也须注意,否则一次上太多的负载,可能造成目标服务器因资源耗完,严重时甚至导致死机。

首先通过uptime查看当前负载情况, 通过watch uptime查看实时负载,观察负载下降情况

Apache服务自带了应该用于压力测试的工具ab(ApacheBench),对应做一些简单的压力测试,它完全能够胜任,本文主要介绍,在centos中不安装Apache的情况下,安装ab

1,ab运行的时候需要依赖包,我们先安装依赖包,直接yum安装就可以了

yum install apr-util

2, 下载apache的rpm包,分离ab

[python]  view plain  copy
  1. <code class="hljs elixir" style="">[root<span class="hljs-variable" style="">@Tomcat</span> ~]<span class="hljs-comment" style=""># mkdir ab</span>  
  2. [root<span class="hljs-variable" style="">@Tomcat</span> ~]<span class="hljs-comment" style=""># cd ab</span>  
  3. [root<span class="hljs-variable" style="">@Tomcat</span> ab]<span class="hljs-comment" style=""># yum -y install yum-utils</span>  
  4. [root<span class="hljs-variable" style="">@Tomcat</span> ab]<span class="hljs-comment" style=""># yumdownloader httpd  #yumdownloader 需要安装yum-utils才能使用,默认是没有的安装的</span>  
  5. [root<span class="hljs-variable" style="">@Tomcat</span> ab]<span class="hljs-comment" style=""># rpm2cpio httpd-2.2.3-91.el5.centos.i386.rpm |cpio -idmv</span>  
  6. [root<span class="hljs-variable" style="">@Tomcat</span> ab]<span class="hljs-comment" style=""># \cp -pa usr/bin/ab /usr/bin/  #复制到系统PATH就可以使用了</span></code>  

3,ab简单用法


参数很多,一般我们用 -c 和 -n 参数就可以了。

#ab -c 1000 -n 4000 http://www.yousite.com/index.html  #具体到某页面

-n后面的4000代表总共发出4000个请求;-c后面的1000表示采用1000个并发(模拟1000个人同时访问),后面的网址表示测试的目标URL。

[python]  view plain  copy
  1. <table border="1" width="700" cellspacing="1" cellpadding="1"><tbody><tr><td> </td></tr></tbody></table>  

[php]  view plain  copy
  1. [root@Tomcat ab]# ab -c 1000 -n 4000 http://192.168.0.222/docs/manager-howto.html  
  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.   
  6. Benchmarking 192.168.0.222 (be patient)  
  7. Completed 400 requests  
  8. Completed 800 requests  
  9. Completed 1200 requests  
  10. Completed 1600 requests  
  11. Completed 2000 requests  
  12. Completed 2400 requests  
  13. Completed 2800 requests  
  14. Completed 3200 requests  
  15. Completed 3600 requests  
  16. Finished 4000 requests  
  17.   
  18.   
  19. Server Software:        nginx/1.4.3  
  20. Server Hostname:        192.168.0.222  
  21. Server Port:            80  
  22.   
  23. Document Path:          /docs/manager-howto.html  
  24. Document Length:        73924 bytes  
  25.   
  26. Concurrency Level:      1000  
  27. Time taken for tests:   0.875928 seconds  
  28. Complete requests:      4000  
  29. Failed requests:        0  
  30. Write errors:           0  
  31. Total transferred:      296732000 bytes  
  32. HTML transferred:       295696000 bytes  
  33. Requests per second:    4566.59 [#/sec] (mean)  
  34. #最重要的指标之一,相当于LR中的每秒事务数,后面括号中的mean表示这是一个平均值,越大抗压越强  
  35. Time per request:       218.982 [ms] (mean)   
  36. #最重要的指标之二,相当于LR中的平均事务响应时间,后面括号中的mean表示这是一个平均值  
  37. Time per request:       0.219 [ms] (mean, across all concurrent requests)  
  38. Transfer rate:          330822.86 [Kbytes/sec] received  
  39. #平均每秒网络上的流量,吞吐量,越大抗压越强  
  40.   
  41. Connection Times (ms)  
  42.               min  mean[+/-sd] median   max  
  43. Connect:        0    0   4.5      0      29  
  44. Processing:     1   17  14.5     17     653  
  45. Waiting:        0   17  14.5     17     653  
  46. Total:         15   18  15.2     17     674  
  47.   
  48. Percentage of the requests served within a certain time (ms)  
  49.   50%     17  
  50.   66%     18  
  51.   75%     18  
  52.   80%     18  
  53.   90%     20  
  54.   95%     22  
  55.   98%     37  
  56.   99%     40  
  57.  100%    674 (longest request)  


主要介绍里面的几个指标,我基本也就看这几个指标,简单测试足够了,如果要全面的监控nginx,需要用到专业的监控程序,如nagios


[java]  view plain  copy
  1. <strong>下面开始解析这条命令语句:</strong>  
[php]  view plain  copy
  1. 启动ab,并出入三个参数(PS D:\wamp\bin\apache\Apache2.2.21\bin> .\ab -n1000 -c10 http://localhost/index.php )  
  2. -n1000    表示请求总数为1000  
  3. -c10      表示并发用户数为10  
  4. http://localhost/index.php   表示这写请求的目标URL  
  5. 测试结果也一目了然:   
  6. 测试出的吞吐率为:   Requests per second: 2015.93 [#/sec] (mean)  ---除此之外还有其他一些信息----  
  7. Server Software //表示被测试的Web服务器软件名称  
  8. Server Hostname  //表示请求的URL主机名  
  9. Server Port     //表示被测试的Web服务器软件的监听端口  
  10. Document Path   //表示请求的URL中的根绝对路径,通过该文件的后缀名,我们一般可以了解该请求的类型  
  11. Document Length   //表示HTTP响应数据的正文长度  
  12. Concurrency Level  //表示并发用户数,这是我们设置的参数之一  
  13. Time taken for tests //表示所有这些请求被处理完成所花费的总时间  
  14. Complete requests  //表示总请求数量,这是我们设置的参数之一  
  15. Failed requests    //表示失败的请求数量,这里的失败是指请求在连接服务器、发送数据等环节发生异常,以及无响应后超时的情况。如果接收到的HTTP响应数据的头信息中含有2XX以外的状态码,则会在测试结果中显示另一个名为       “Non-2xx responses”的统计项,用于统计这部分请求数,这些请求并不算在失败的请求中。  
  16. Total transferred   //表示所有请求的响应数据长度总和,包括每个HTTP响应数据的头信息和正文数据的长度。注意这里不包括HTTP请求数据的长度,仅仅为web服务器流向用户PC的应用层数据总长度。  
  17. HTML transferred    //表示所有请求的响应数据中正文数据的总和,也就是减去了Total transferred中HTTP响应数据中的头信息的长度。  
  18. Requests per second   //吞吐率,计算公式:Complete requests / Time taken for tests  
  19. Time per request   //用户平均请求等待时间,计算公式:Time token for tests/(Complete requests/Concurrency Level)  
  20. Time per requet(across all concurrent request)   //服务器平均请求等待时间,计算公式:Time taken for tests/Complete requests,正好是吞吐率的倒数。也可以这么统计:Time per request/Concurrency Level  
  21. Transfer rate    //表示这些请求在单位时间内从服务器获取的数据长度,计算公式:Total trnasferred/ Time taken for tests,这个统计很好的说明服务器的处理能力达到极限时,其出口宽带的需求量。  
  22. Percentage of requests served within a certain time(ms)   //这部分数据用于描述每个请求处理时间的分布情况,比如以上测试,80%的请求处理时间都不超过6ms,这个处理时间是指前面的Time per request,即对于单个用户而言,平均每个请求的处理时间。  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值