简介

ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.

参数详解

-n 即requests,用于指定压力测试总共的执行次数。

-c 即concurrency,用于指定的并发数。

-t 即timelimit,等待响应的最大时间(单位:秒)。

-b 即windowsize,TCP发送/接收的缓冲大小(单位:字节)。

-p 即postfile,发送POST请求时需要上传的文件,此外还必须设置-T参数。

-u 即putfile,发送PUT请求时需要上传的文件,此外还必须设置-T参数。

-T 即content-type,用于设置Content-Type请求头信息,例如:application/x-www-form-urlencoded,默认值为text/plain。

-v 即verbosity,指定打印帮助信息的冗余级别。

-w 以HTML表格形式打印结果。

-i 使用HEAD请求代替GET请求。

-x 插入字符串作为table标签的属性。

-y 插入字符串作为tr标签的属性。

-z 插入字符串作为td标签的属性。

-C 添加cookie信息,例如:“Apache=1234”(可以重复该参数选项以添加多个)。

-H 添加任意的请求头,例如:“Accept-Encoding: gzip”,请求头将会添加在现有的多个请求头之后(可以重复该参数选项以添加多个)。

-A 添加一个基本的网络认证信息,用户名和密码之间用英文冒号隔开。

-P 添加一个基本的代理认证信息,用户名和密码之间用英文冒号隔开。

-X 指定使用的和端口号,例如:“126.10.10.3:88”。

-V 打印版本号并退出。

-k 使用HTTP的KeepAlive特性。

-d 不显示百分比。

-S 不显示预估和警告信息。

-g 输出结果信息到gnuplot格式的文件中。

-e 输出结果信息到CSV格式的文件中。

-r 指定接收到错误信息时不退出程序。

-h 显示用法信息,其实就是ab -help。

示例:ab -n 100 -c 10 -T application/json -H terminal:WEB -p postfile.txt -C _token=1 http://www.baidu.com
并发量10 请求100次 http接口的参数格式为json,参数在postfile.txt中

返回格式解读

如: ab -n 100 -c 1 http://www.baidu.com/search.html
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking crazyracing-kartrider.prepub.souche.com (be patient)…..done
Server Software:
Server Hostname: www.baidu.com : 请求的host地址
Server Port: 80 :请求端口号
Document Path: /search.html :请求路径 URI
Document Length: 115768 bytes :返回内容长度
Concurrency Level: 1 : 并发指数
Time taken for tests: 221.598 seconds :所有请求走完花费的时间
Complete requests: 100 :总请求次数
Failed requests: 0 :失败的请求数
Total transferred: 11633600 bytes :总共传输的字段数,包含http header等
Total body sent: 742200 :post发送数据量
HTML transferred: 11576800 bytes :html body字节总数,也就是实际返回数据的字节总长
Requests per second: 0.45 [#/sec] (mean) :qps 每秒并发量
Time per request: 2215.977 [ms] (mean) :单个请求花费时间
Time per request: 2215.977 [ms] (mean, across all concurrent requests) :服务器平均处理时间
Transfer rate: 51.27 [Kbytes/sec] received :每秒获取数据的长度
3.27 kb/s sent
54.54 kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 3 9 5.9 6 29 :连接数
Processing: 1704 2207 482.8 1958 3490
Waiting: 1656 2149 481.8 1900 3449
Total: 1710 2216 483.7 1976 3494
Percentage of the requests served within a certain time (ms)
50% 1976 : 50%的请求在1976ms内返回
66% 2267
75% 2440
80% 2732
90% 3061
95% 3176
98% 3410
99% 3494
100% 3494 (longest request)