性能测试-ApacheBench

基本简介

ApacheBench 是一个指令列程式,专门用来执行网站服务器的运行效能,特别是针对Apache 网站服务器。这原本是用来检测 Apache 网站服务器能够提供的效能,特别是可以看出Apache能提供每秒能送出多少网页。

工具准备

点击[下载]

命令

  • 在Linux系统,一般安装好ApacheBench后可以直接在终端中执行
  • 如果是Win系统下,打开cmd命令行窗口,cd到apache安装目录的bin目录下
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。

输入图片说明

结果分析

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轻量很多.

posted @ 2017-09-18 10:40  dotleo  阅读(535)  评论(0编辑  收藏  举报