网站首页linux
ab压力测试工具
发布时间:2016-02-16 18:45:41编辑:阅读(3671)
ab是apache自带的压力测试工具。若要单独安装ab, 可使用yum:
yum install httpd-tools
完成后,就可以直接运行ab.
ab -n 100 -c 20 http://localhost/
-n :总共的请求执行数,缺省是1;
-c: 并发数,缺省是1;
上面这个命令就是:访问http://localhost/这个地址100次,20个并发同时执行。
结果如下:
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 test.carp2p.cn (be patient).....done Server Software: nginx #web服务器软件 Server Hostname: localhost #请求URL的主机部分 Server Port: 80 #端口号 Document Path: / #请求的页面路径 Document Length: 206 bytes #页面大小 Concurrency Level: 20 #并发数(-c参数) Time taken for tests: 1.084 seconds #测试持续时间 Complete requests: 100 #完成的请求数量 Failed requests: 6 #失败的请求数量,(请求在连接服务器、发送数据等环节发生异常,以及无响应后超时的情况) (Connect: 0, Receive: 0, Length: 6, Exceptions: 0) #Connect是无法送出要求、目标主机连接失败、要求的过程中被中断 #Receive是接收失败 #Length是响应的内容长度不一致(以Content-Length 头值为判断依据), #这里Length显示6,是因为测试的是PHP页面,测试过程中响应的Content-Length大小不一致造成的.实际上是成功访问了6次。 Write errors: 0 #写入错误 Non-2xx responses: 94 #链接状态异常数量,接收到的HTTP响应数据的头信息中含有2XX以外的状态码 Total transferred: 485983 bytes #发送请求的响应数据传输量的总和,包含头信息和正文长度 HTML transferred: 468559 bytes #HTML内容传输量 Requests per second: 92.26 [#/sec] (mean) #吞吐率,每秒处理的请求量 Time per request: 216.783 [ms] (mean) #平均请求处理时间 Time per request: 10.839 [ms] (mean, across all concurrent requests) Transfer rate: 437.85 [Kbytes/sec] received #极限处理能力带宽 Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 1 Processing: 0 29 132.8 1 929 Waiting: 0 29 132.3 1 926 Total: 1 30 132.8 2 929 Percentage of the requests served within a certain time (ms) 50% 2 66% 2 75% 2 80% 2 90% 2 95% 160 98% 730 99% 929 100% 929 (longest request)
因为限制了每个IP的链接数最大为5, 所以上面100个请求,成功了6个,另外94个返回了503状态位。
ab常见报错的解决方法:
apr_socket_recv: Connection reset by peer (104)
解:加个-r参数, ab -n 10000 -c 2000 -r http://www.yousite.com
socket: Too many open files (24)
解:执行 ulimit -n 65535
评论