Apache自带的一个小工具, ab(简称ApacheBench), 可以同时模拟多个并发请求.
Usage: ./ab [options] [http[s]://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make
-t timelimit Seconds to max. wait for responses
-p postfile File containing data to POST
-T content-type Content-type header for POSTing
-v verbosity How much troubleshooting info to print
-w Print out results in HTML tables
-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 Add Basic WWW Authentication, the attributes
are a colon separated username and password.
-P attribute Add Basic Proxy Authentication, the attributes
are a colon separated username and password.
-X proxy:port Proxyserver and port number to use
-V Print version number and exit
-k Use HTTP KeepAlive feature
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings.
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-h Display usage information (this message)
-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
-f protocol Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)
一个简单的测试:
/*向www.sina.com 发送10个请求(-n), 每个请求同时并发10个请求(-c) */
# ./ab -n 10 -c 10 http://www.sina.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking www.sina.com (be patient)…..done
Server Software: Apache/2.0.54
Server Hostname: www.sina.com
Server Port: 80Document Path: /
Document Length: 231 bytesConcurrency Level: 10
Time taken for tests: 0.268 seconds /*测试持续时间*/
Complete requests: 10 /*完成请求数量*/
Failed requests: 0 /*失败请求数量*/
Write errors: 0
Non-2xx responses: 10
Total transferred: 6253 bytes /*网络传输量*/
HTML transferred: 2310 bytes /*html内容传输量*/
Requests per second: 37.33 [#/sec] (mean) /*每秒事务数(平均值)*/
Time per request: 267.848 [ms] (mean) /*事务响应时间(平均值)*/
Time per request: 26.785 [ms] (mean, across all concurrent requests) /*并发事务响应时间(平均值)*/
Transfer rate: 22.80 [Kbytes/sec] received /*每秒网络流量*/Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 1 0.2 1 1
Processing: 183 204 26.7 195 266
Waiting: 183 204 26.7 195 266
Total: 184 205 26.8 196 268/*以下内容为整个测试中所有请求的响应情况. 在测试中每个请求都有一个响应时间, 其中 66%的用户响应时间小于196毫秒,75%的用户响应时间小于197 毫秒,最大的响应时间小于268毫秒*/
Percentage of the requests served within a certain time (ms)
50% 196
66% 196
75% 197
80% 239
90% 268
95% 268
98% 268
99% 268
100% 268 (longest request)