http://httpd.apache.org/docs/2.0/programs/ab.html html
ab
是用于对Apache超文本传输协议(HTTP)服务器进行基准测试的工具。它旨在使您对当前的Apache安装如何执行有一个印象。这尤为向您显示Apache安装每秒可以处理多少个请求。nginx
概要
ab [ -A auth-username:password ] [ -c concurrency ] [ -C cookie-name=value ] [ -d ] [ -e csv-file ] [ -g gnuplot-file ] [ -h ] [ -H custom-header ] [ -i ] [ -k ] [ -n requests ] [ -p POST-file ] [ -P proxy-auth-username:password ] [ -q ] [ -s ] [ -S ] [ -t timelimit ] [ -T content-type ] [ -v verbosity] [ -V ] [ -w ] [ -x <table>-attributes ] [ -X proxy[:port] ] [ -y <tr>-attributes ] [ -z <td>-attributes ] [http://]hostname[:port]/path
数据库
选项
-A auth-username:password
apache
向服务器提供BASIC身份验证凭据。用户名和密码用单个分隔,:
并经过编码为base64的网络发送。不管服务器是否须要该字符串,都将发送该字符串(即,已发送所需的401身份验证)。服务器
-c concurrency
cookie
一次执行的多个请求的数量。默认值为一次一个请求。网络
-C cookie-name=value
并发
Cookie:
在请求中添加一行。参数一般为一 对形式。该字段是可重复的。name=value
工具
-d
性能
不要显示“ XX [ms]表中的投放百分比”。(旧版支持)。
-e csv-file
编写一个逗号分隔值(CSV)文件,其中包含每一个百分比(从1%到100%)的服务该百分比请求所花费的时间(以毫秒为单位)。一般,它比“ gnuplot”文件有用。由于结果已经“装箱”了。
-g gnuplot-file
将全部测量值写为“ gnuplot”或TSV(制表符单独值)文件。此文件能够轻松导入到Gnuplot,IDL,Mathematica,Igor甚至Excel等软件包中。标签位于文件的第一行。
-h
显示使用状况信息。
-H custom-header
将额外的标头添加到请求。该参数是典型地在一个有效报头线的形式,含有一个冒号分隔的字段值对(即,"Accept-Encoding: zip/zop;8bit"
)。
-i
作HEAD
请求,而不是GET
。
-k
启用HTTP KeepAlive功能,即在一个HTTP会话中执行多个请求。默认为no KeepAlive。
-n requests
为基准测试会话执行的请求数。默认设置是仅执行一个请求,这一般会致使非表明性的基准测试结果。
-p POST-file
包含要发布的数据的文件。
-P proxy-auth-username:password
在代理途中提供BASIC身份验证凭据。用户名和密码用单个分隔,:
并经过编码为base64的网络发送。无论代理是否须要它都将发送该字符串(即,已发送了所需的407代理身份验证)。
-q
当处理150个以上的请求时,每10%或100个左右的请求ab
输出进度计数stderr
。该 -q
标志将禁止显示这些消息。
-s
编译为(ab -h
将向您显示)时,请使用SSL保护https
而不是http
协议。此功能是实验性的,很是基础。您可能不想使用它。
-S
当平均值和中位数相距标准误差的一倍或两倍以上时,请勿显示中位数和标准误差值,也不会显示警告/错误消息。并默认为最小值/平均值/最大值。(旧版支持)。
-t timelimit
用于基准测试的最大秒数。这意味着 -n 50000
内部。使用它在固定的总时间内对服务器进行基准测试。默认状况下没有时间限制。
-T content-type
用于POST数据的内容类型标头。
-v verbosity
设置详细级别-4
上方将在标题上显示信息,3
上方将显示响应代码(40四、200等), 2
上方将显示警告和信息。
-V
显示版本号并退出。
-w
在HTML表格中打印出结果。默认表是两列宽,带有白色背景。
-x <table>-attributes
用做的属性的字符串<table>
。插入属性。<table here >
-X proxy[:port]
使用代理服务器处理请求。
-y <tr>-attributes
用做的属性的字符串<tr>
。
-z <td>-attributes
用做的属性的字符串<td>
。
BUG
有各类固定长度的静态声明的缓冲区。与命令行参数的延迟解析,服务器的响应标头以及其余外部输入相结合,这可能会给您带来麻烦。它没有彻底实现HTTP / 1.x。仅接受某些“预期”形式的回复。strstr(3)
概要文件顶部的大量使用显示可能代表性能存在问题;即,您将衡量ab
性能而不是服务器的性能。
并发压测示例
发送1000个http get请求到[http://192.168.10.232:8000/blog,并发为10]:
$ ab -n1000 -c10 http://localhost/ This is ApacheBench, Version 2.3 <$Revision: 1706008 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: nginx/1.10.3 Server Hostname: localhost Server Port: 80 Document Path: / Document Length: 11321 bytes Concurrency Level: 10 Time taken for tests: 0.066 seconds Complete requests: 1000 Failed requests: 0 Total transferred: 11566000 bytes HTML transferred: 11321000 bytes Requests per second: 15207.74 [#/sec] (mean) Time per request: 0.658 [ms] (mean) Time per request: 0.066 [ms] (mean, across all concurrent requests) Transfer rate: 171770.21 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 0 Processing: 0 0 0.1 0 1 Waiting: 0 0 0.2 0 1 Total: 0 1 0.1 1 1 Percentage of the requests served within a certain time (ms) 50% 1 66% 1 75% 1 80% 1 90% 1 95% 1 98% 1 99% 1 100% 1 (longest request)
注意Time per request: 0.658 [ms] (mean)是平均每批请求的完成时间,这里时10个请求完成的时间。Time per request: 0.066 [ms] (mean, across all concurrent requests)是平均每一个请求的完成时间。
ApacheBench将只使用一个操做系统线程。不少状况下ApacheBench自己是瓶颈。当在硬件具备多个处理器核心使用ApacheBench,建议一个cpu核执行一个ab线程,可是如今cpu核数不少的状况下,好比48核,手工执行48个命令也是个体力活。
总体来讲ab由于不能利用到多核、不能进行参数化、不支持http和https之外的协议等缘由,只适合单个组件的粗略测试,好比Apache http。不合适业务级别的测试,如一旦后台有数据库等,ab的测试是几乎没有意义的。