1、命令格式
ab命令放在apache目录bin目录下面,使用方法如下
./ab -n 3000 -c 3000 http://www.test.com/
其中-n代表每次并发量,-c代表总共发送的数量
2、测试结果分析
[root@Svr107 bin]# ./ab -n 3000 -c 3000 http://www.test.com/ 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 www.twioo.com (be patient)Completed 300 requestsCompleted 600 requestsCompleted 900 requestsCompleted 1200 requestsCompleted 1500 requestsCompleted 1800 requestsCompleted 2100 requestsCompleted 2400 requestsCompleted 2700 requestsCompleted 3000 requestsFinished 3000 requests
Server Software: nginx/0.7.65Server Hostname: www.test.comServer Port: 80
Document Path: / ###请求的资源Document Length: 50679 bytes ###文档返回的长度,不包括相应头
Concurrency Level: 3000 ###并发个数Time taken for tests: 30.449 seconds ###总请求时间Complete requests: 3000 ###总请求数Failed requests: 0 ###失败的请求数Write errors: 0Total transferred: 152745000 bytesHTML transferred: 152037000 bytesRequests per second: 98.52 [#/sec] (mean) ###平均每秒的请求数Time per request: 30449.217 [ms] (mean) ###平均每个请求消耗的时间Time per request: 10.150 [ms] (mean, across all concurrent requests) ###上面的请求除以并发数Transfer rate: 4898.81 [Kbytes/sec] received ###传输速率
Connection Times (ms) min mean[+/-sd] median maxConnect: 2 54 27.1 55 98Processing: 51 8452 5196.8 7748 30361Waiting: 50 6539 5432.8 6451 30064Total: 54 8506 5210.5 7778 30436
Percentage of the requests served within a certain time (ms) 50% 7778 ###50%的请求都在7778Ms内完成 66% 11059 75% 11888 80% 12207 90% 13806 95% 18520 98% 24232 99% 24559 100% 30436 (longest request)
3、如果用ab访问的是他本机上的web服务器,使用127.0.0.1或者是web服务器上的网卡IP地址,这个是不走网络设备的,可以忽略网络消耗
4、ab使用的一些问题
a、ab命令在一般系统上面做测试时候,一般并发不能超过1024个,其实是因为因为系统限制每个进程打开的最大文件数为1024,可以用ulimit -a来查看
open files (-n) 65536 ##这个我系统已经修改过
b、-n 可以指定最大请求数,但是不能超过50000个
c、-v n 当n>=2 时,可以显示发送的http请求头,和响应的http头及内容,压力测试时不要这么做
[root@Svr107 bin]# ./ab -n 1 -c 1 -v 2 http://www.test.com/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 www.test.com (be patient)...INFO: POST header == ---GET / HTTP/1.0Host: www.test.comUser-Agent: ApacheBench/2.3Accept: */*
---LOG: header received:HTTP/1.1 200 OKServer: nginx/0.7.65Date: Thu, 01 Dec 2011 13:08:16 GMTContent-Type: text/htmlConnection: closeVary: Accept-EncodingContent-Length: 50515Last-Modified: Thu, 01 Dec 2011 13:08:04 GMTAccept-Ranges: bytes
<sc< div="" style="word-wrap: break-word;">..done
Server Software: nginx/0.7.65Server Hostname: www.test.comServer Port: 80
Document Path: /Document Length: 50515 bytes
Concurrency Level: 1Time taken for tests: 0.006 secondsComplete requests: 1Failed requests: 0Write errors: 0Total transferred: 50751 bytesHTML transferred: 50515 bytesRequests per second: 176.27 [#/sec] (mean)Time per request: 5.673 [ms] (mean)Time per request: 5.673 [ms] (mean, across all concurrent requests)Transfer rate: 8736.39 [Kbytes/sec] received
Connection Times (ms) min mean[+/-sd] median maxConnect: 0 0 0.0 0 0Processing: 5 5 0.0 5 5Waiting: 1 1 0.0 1 1Total: 6 6 0.0 6 6
在做压力测试的时候,一般情况下压力测试客户端接收到的数据量一定会远大于发送出去的数据量
参考http://johnnyhg.iteye.com/blog/523818