复制代码

为懒人提供无限可能,生命不息,code不止

人类感性的情绪,让我们知难行难
我思故我在
日拱一卒,功不唐捐
  • 首页
  • 前端
  • 后台
  • 数据库
  • 运维
  • 资源下载
  • 实用工具
  • 接口文档工具
  • 登录
  • 注册

系统测试

【原创】apache ab 性能压力测试详解

作者: whooyun发表于: 2017-03-22 12:53

网站性能压力测试是中大型业务系统上线前不可缺少的一环,只有进行了测试才能有预见性的发现系统中的问题,并在后续用户量,pv增加的基础上进行针对性的优化。
下面介绍下 ApacheBench的ab测试方法。

系统架构为springmvc+mybatis,以下测试针对的是restful风格的接口

apache ab远程测试机测试(应用部署在本机,mysql部署在本机,但是ab测试由本地发起)
(参数解析,在本次测试中,-c 代表每次请求的连接数,-n 代表发起多少次请求,-k指的是启用http长连接)
[root@iZ948nttzx8Z bin]# ab -n 400 -c 400 -k http://120.25.98.197:8080/getAllArticles 
(ab命令使用http长连接,向接口http://120.25.98.197:8080/getAllArticles请求了400次,每次(指1秒内)发起了400个连接)
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 120.25.98.197 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests


Server Software:        Apache-Coyote/1.1
Server Hostname:        120.25.98.197
Server Port:            8080

Document Path:          /getAllArticles
Document Length:        12397 bytes

Concurrency Level:      400
Time taken for tests:   56.681 seconds
Complete requests:      400
Failed requests:        0
Write errors:           0
Keep-Alive requests:    0
Total transferred:      5019448 bytes
HTML transferred:       4960100 bytes
Requests per second:    7.06 [#/sec] (mean)
Time per request:       56680.540 [ms] (mean)
Time per request:       141.701 [ms] (mean, across all concurrent requests)
Transfer rate:          86.48 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0 1570 2136.9      7    6595
Processing:    14 20957 12329.4  19054   56666
Waiting:        5 12335 14251.3   6487   56665
Total:         15 22527 11909.4  20746   56670

Percentage of the requests served within a certain time (ms)
  50%  20746
  66%  27694
  75%  30274
  80%  31638
  90%  36210
  95%  40453
  98%  56273
  99%  56477
 100%  56670 (longest request)

apache ab本机测试(应用部署到本机,mysql部署到本机,ab测试由应用机发起)
[root@iZ94chsjsmvZ bin]# ab -n 400 -c 400 -k http://120.25.98.197:8080/getAllArticles
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 120.25.98.197 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests


Server Software:        Apache-Coyote/1.1
Server Hostname:        120.25.98.197
Server Port:            8080

Document Path:          /getAllArticles //#测试的页面或接口
Document Length:        12397 bytes    //请求返回的字符大小

Concurrency Level:      400           //并发数(秒)
Time taken for tests:   1.696 seconds   //测试所花费的时间
Complete requests:      400         //完成请求的次数
Failed requests:        0           //请求失败次数
Write errors:           0
Keep-Alive requests:    0       
Total transferred:      5045000 bytes  //整个过程中的网络传输量
HTML transferred:       4985356 bytes   //整个过程中的HTML 传输量
Requests per second:    235.81 [#/sec] (mean)  //每秒请求数 后面括号中的mean表示这是一个平均值
Time per request:       1696.247 [ms] (mean)  //相当于LR中的平均事务响应时间,后面括号中的mean表示这是一个平均值
Time per request:       4.241 [ms] (mean, across all concurrent requests) //每个连接请求实际运行时间的平均值
Transfer rate:          2904.50 [Kbytes/sec] received  //平均每秒网络上的流量

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  132 318.2      0    1000
Processing:    13  366 137.9    409     830
Waiting:        5  360 136.8    398     830
Total:         57  498 377.3    415    1576

Percentage of the requests served within a certain time (ms)
  50%    415
  66%    442
  75%    461
  80%    475
  90%   1423
  95%   1488
  98%   1567
  99%   1572
 100%   1576 (longest request)

总结下,结果看:
对比下俩次测试的最后四个参数
Requests per second:     
Time per request:        
Time per request:        
Transfer rate:           
然后再看下服务器当时的网络进出流量监控可以发现apache ab远程测试机测试网络延时还是比较大的,所以本次测试肯定是不准的。

强烈建议在局域网内做测试(并且先对网络进行调优,以增加测试的精确性),平时看下90%的请求数所花的时间(时间段)就可以了,个人觉得超过3秒就需要调优了。

官网的意思是它是作为http server的测试工具,你如果想用来测web server也可以,但是可能不是很准,毕竟俩种是不同的服务,有测试组建议还是用jemeter,loadrunner。
原话是:
ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.
大体意思是它就是用来测http 每秒的并发请求数的,感觉用来测nginx还是可以的。