Apache bench压力测试

AndyYang| 阅读:1326 发表时间:2013-08-15 16:10:10 apache
摘要:ab的全称是ApacheBench,是Apache附带的一个小工具,专门用于HTTPServer的benchmark testing,可以同时模拟多个并发请求。一般开发人员在进行真正的压力测试之前可以使用这个工具来进行自测,从而更好地掌握性能。

ab的全称是ApacheBench,是Apache附带的一个小工具,专门用于HTTPServer的benchmark testing,可以同时模拟多个并发请求。一般开发人员在进行真正的压力测试之前可以使用这个工具来进行自测,从而更好地掌握性能。

ab的参数有:

Options are:

    -n requests     Number of requests to perform  

    -cconcurrency  Number of multiple requeststo make  

    -t timelimit    Seconds to max. wait for responses  

    -p postfile     File containing data to POST  

    -T content-typeContent-type header for POSTing  

    -v verbosity    How much troubleshooting info to print  

    -w              Print out results in HTMLtables  

    -i              Use HEAD instead of GET  

    -x attributes   String to insert as table attributes  

    -y attributes   String to insert as tr attributes  

    -z attributes   String to insert as td or th attributes  

    -C attribute    Add cookie, eg. 'Apache=1234.(repeatable)  

    -H attribute    Add Arbitrary header line, eg.'Accept-Encoding: gzip'  

                   Inserted after all normal header lines. (repeatable)  

    -A attribute    AddBasic WWW Authentication, the attributes 

                   are a colon separated username and password.  

    -P attribute    Add Basic Proxy Authentication, theattributes  

                   are a colon separated username and password.  

    -X proxy:port   Proxyserver and port number to use  

    -V              Print version number andexit  

    -k              Use HTTP KeepAlive feature  

    -d              Do not show percentiles servedtable.  

    -S              Do not show confidence estimatorsand warnings.  

    -g filename     Output collected data to gnuplot formatfile.  

    -e filename     Output CSV file with percentagesserved  

-h             Display usage information (this message)  

首先进入安装Apache下的bin目录,比如在我本机就是E:\xampp\apache\bin,较常用的参数是nc,运行命令和结果如下:

E:\xampp\apache\bin>ab -n 10000 -c 100 http://www.hxweb.com/  

This is ApacheBench, Version 2.0.40-dev<$Revision: 1.146 $> apache-2.0  

Copyright 1996 Adam Twiss, Zeus Technology Ltd,http://www.zeustech.net/  

Copyright 2006 The Apache Software Foundation,http://www.apache.org/  

Benchmarking renmai-dev.china.alibaba.com (be patient)  

Completed 1000 requests 

Completed 2000 requests 

Completed 3000 requests 

Completed 4000 requests 

Completed 5000 requests 

Completed 6000 requests 

Completed 7000 requests 

Completed 8000 requests 

Completed 9000 requests 

Finished 10000 requests 

Server Software:       Apache、2.4.3  

Server Hostname:       http://www.hxweb.com/  

ServerPort:            80 

#测试的页面

Document Path:         /

#页面大小  

Document Length:       888 bytes  

#测试的并发数

Concurrency Level:     100  

#整个测试持续的时间

Time taken for tests:  11.813 seconds

#完成的请求数量

Complete requests:     10000  

#失败的请求数量

Failed requests:       0  

Write errors:          0  

#整个过程中的网络传输量

Total transferred:     1266000 bytes  

#整个过程中的HTML内容传输量

HTML transferred:      888000 bytes  

#最重要的指标之一,相当于LR中的每秒事务数,后面括号中的mean表示这是一个平均值

Requests per second:   84.66 [#/sec] (mean)  

#最重要的指标之二,相当于LR中的平均事务响应时间,后面括号中的mean表示这是一个平均值

Time per request:      1181.250 [ms] (mean)  

#每个连接请求实际运行时间的平均值

Time per request:      11.813 [ms] (mean, across all concurrent requests)  

#平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题

Transfer rate:         104.66 [Kbytes/sec] received  

#网络上消耗的时间的分解,各项数据的具体算法还不是很清楚

Connection Times (ms) 

              min  mean[+/-sd] median   max  

Connect:        0    0  1.8      0      31 

Processing:    15  176 101.5   140    1125  

Waiting:       15  176 101.3   140    1125  

Total:         15  177 101.5   140    1125  

#整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于140毫秒,66%的用户响应时间小于156毫秒,最大的响应时间小于1125毫秒。对于并发请求,cpu实际上并不是同时处理的,而是按照每个请求获得的时间片逐个轮转处理的,所以基本上第一个Time per request时间约等于第二个Timeper request时间乘以并发请求数。

Percentage of the requests served within a certain time(ms)  

  50%    140  

  66%    156  

  75%    171  

  80%    171  

  90%    281  

  95%    421  

  98%    484  

  99%    609  

 100%   1125 (longest request)   

总结:在远程对web服务器进行压力测试,往往效果不理想(因为网络延时过大),建议使用内网的另一台或者多台服务器通过内网进行测试,这样得出的数据,准确度会高很多。如果只有单独的一台服务器,可以直接本地测试,比远程测试效果要准确。

摘自:http://httpd.apache.org/docs/2.0/programs/ab.html
如果您觉得好,可以打赏作者:
如果您觉得累了,是否想看点美女养养眼:猛戳>>朋友帮
如果您觉得皮了,是否想来点神吐槽:猛戳>>iPhone查询中

已有0条评论

昵称:
邮箱:

  • 最新评论

iPhone查询中 - bbs.ipcxz.com 朋友帮 - www.pengyb.cn iPhone查询中 - bbs.ipcxz.com
反馈
微信订阅号