ApacheBench 是一个指令列程式,专门用来执行网站服务器的运行效能,特别是针对Apache 网站服务器。这本来是用来检测 Apache 网站服务器可以提供的效能,特别是能够看出Apache能提供每秒能送出多少网页。php
点击[下载]html
ab [ -A auth-username:password ] [ -b windowsize ] [ -B local-address ] [ -c concurrency ] [ -C cookie-name=value ] [ -d ] [ -e csv-file ] [ -f protocol ] [ -g gnuplot-file ] [ -h ] [ -H custom-header ] [ -i ] [ -k ] [ -l ] [ -m HTTP-method ] [ -n requests ] [ -p POST-file ] [ -P proxy-auth-username:password ] [ -q ] [ -r ] [ -s timeout ] [ -S ] [ -t timelimit ] [ -T content-type ] [ -u PUT-file ] [ -v verbosity] [ -V ] [ -w ] [ -x <table>-attributes ] [ -X proxy[:port] ] [ -y <tr>-attributes ] [ -z <td>-attributes ] [ -Z ciphersuite ] [http[s]://]hostname[:port]/path
ab -n 4000 -c 1000 http://www.ha97.com/
算法
-n后面的4000表明总共发出4000个请求;-c后面的1000表示采用1000个并发(模拟1000我的同时访问),后面的网址表示测试的目标URL。apache
This is ApacheBench, Version 2.3 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.80.157 (be patient) Completed 400 requests Completed 800 requests Completed 1200 requests Completed 1600 requests Completed 2000 requests Completed 2400 requests Completed 2800 requests Completed 3200 requests Completed 3600 requests Completed 4000 requests Finished 4000 requests Server Software: Apache/2.2.15 Server Hostname: 192.168.80.157 Server Port: 80 Document Path: /phpinfo.php #测试的页面 Document Length: 50797 bytes #页面大小 Concurrency Level: 1000 #测试的并发数 Time taken for tests: 11.846 seconds #整个测试持续的时间 Complete requests: 4000 #完成的请求数量 Failed requests: 0 #失败的请求数量 Write errors: 0 Total transferred: 204586997 bytes #整个过程当中的网络传输量 HTML transferred: 203479961 bytes #整个过程当中的HTML内容传输量 Requests per second: 337.67 [#/sec] (mean) #最重要的指标之一,至关于LR中的每秒事务数,后面括号中的mean表示这是一个平均值 Time per request: 2961.449 [ms] (mean) #最重要的指标之二,至关于LR中的平均事务响应时间,后面括号中的mean表示这是一个平均值 Time per request: 2.961 [ms] (mean, across all concurrent requests) #每一个链接请求实际运行时间的平均值 Transfer rate: 16866.07 [Kbytes/sec] received #平均每秒网络上的流量,能够帮助排除是否存在网络流量过大致使响应时间延长的问题 Connection Times (ms) min mean[+/-sd] median max Connect: 0 483 1773.5 11 9052 Processing: 2 556 1459.1 255 11763 Waiting: 1 515 1459.8 220 11756 Total: 139 1039 2296.6 275 11843 #网络上消耗的时间的分解,各项数据的具体算法还不是很清楚 Percentage of the requests served within a certain time (ms) 50% 275 66% 298 75% 328 80% 373 90% 3260 95% 9075 98% 9267 99% 11713 100% 11843 (longest request) #整个场景中全部请求的响应状况。在场景中每一个请求都有一个响应时间,其中50%的用户响应时间小于275毫秒,66%的用户响应时间小于298毫秒,最大的响应时间小于11843毫秒。对于并发请求,cpu实际上并非同时处理的,而是按照每一个请求得到的时间片逐个轮转处理的,因此基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求数。
-A auth-username:password 有的请求须要用户名和密码进行验证:(例如:401 验证需求). -b windowsize TCP 发送和接收的buffer大小,单位是 bytes -c concurrency 并发数,同一时间有多少强求发出去,默认是1。 -C cookie-name=value 加上Cookie:以“ name=value ”的形式,能够重复 -C xx1=yy1 -C xx2=yy2。 -d 不展现"percentage served within XX [ms] table". -e csv-file 写一个逗号分隔的CSV文件,包含每一个百分比(from 1% to 100%)服务器执行的时间(毫秒),这个文件通常比'gunplot'有用。 -f protocol 指定 SSL/TLS 协议 (SSL2, SSL3, TLS1, or ALL). -g gnuplot-file 写全部有用的信息到TSV(Tab separate values)文件,能够轻松导入Excel等里面,label在文件第一行。 -h 展现帮助信息 -H custom-header 加入额外的头信息。以冒号分割,例如("Accept-Encoding: zip/zop;8bit") -i 发送GET请求 -k 打开Http的keepalive功能。在一个http会话里执行多个请求。默认不开启。 -n requests 要执行的请求校验次数。默认请求一次,请求一次的结果不能表明校验结果,不许确。 -p POST-file 包含POST数据文件 -P proxy-auth-username:password 支持基本Auth代理路由验证。在(http code : 407 的时候须要) -q 当程序有150个请求,输出以每10%或100个来显示。-q 用来取消这些信息。 -r 在socket错误的时候不退出。 -s 若是用在SSl协议,功能还处在试验阶段,你不须要用它。 -S 不展现终止和标准值,也不展现警告信息。 -t timelimit 校验花费的最大时间,内部设置-n 50000 次。使用这个选项在特定时间内测试。默认不开启 -T content-type 用于POST/PUT 数据,例如eg. application/x-www-form-urlencoded. Default: text/plain. -u PUT-file PUT 的文件,记着加上-T -v verbosity 设置输出等级, 4 输出头信息,3 输出响应码(404,200) 2 输出警告和信息 -V 展现版本,而后退出。 -w 输出结果到html里的table,默认两列,白色背景。 -x <table>-attributes String to use as attributes for <table>. Attributes are inserted <table here >. -X proxy[:port] 使用代理。 -y <tr>-attributes 设置属性到 <tr>. -z <td>-attributes 设置属性到 <td>. -Z ciphersuite 指定 SSL/TLS 密码套件 (See openssl ciphers).
说明:我找了一个内网比较复杂的页面进行测试,咱们经过结果能够大概看到网站平均吞吐量在442左右,须要注意的是若是你也须要测试最好找一个内网的页面或者站点进行测试,这样网速等其余区因素的影响会下降到最小,我开始是拿咱们博客园进行测试,可是刚好今天网络很不稳定因此数据等待结果很是慢,因此为了减少偏差,咱们尽可能选用内网进行测试。你们经过结果能够清晰的估算出咱们网站目前的状况!经过使用也能对比出ab相对于我以前说起到的Jmeter轻量不少.windows