windows下:
linux下,如果没有装apche,先要装一下ab:
测试工具安装(以centos系统为例)yum -y install httpd-tools
ab 的用法是:ab [options] [http://]hostname[:port]/path
例如:ab -n 5000 -c 200 http://localhost/index.php
上例表示总共访问http://localhost/index.php这个脚本5000次,200并发同时执行。
ab常用参数的介绍:
-n :总共的请求执行数,缺省是1;
-c: 并发数,缺省是1;
-t:测试所进行的总时间,秒为单位,缺省50000s
-p:POST时的数据文件
-w: 以HTML表的格式输出结果
下面是一个完整的测试:
[root@localhost public]# ab -n 100 -c 100 http://www.hu-rong.com
ab: invalid URL
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
-b windowsize Size of TCP send/receive buffer, in bytes
-p postfile File containing data to POST. Remember also to set -T
-u putfile File containing data to PUT. Remember also to set -T
-T content-type Content-type header for POSTing, eg.
'application/x-www-form-urlencoded'
Default is 'text/plain'
-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
-r Don't exit on socket receive errors.
-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)
[root@localhost public]# ab -n 100 -c 100 http://www.hu-rong.com/index.php
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 www.hu-rong.com (be patient).....done
Server Software: nginx
Server Hostname: www.hu-rong.com
Server Port: 80
Document Path: /index.php
Document Length: 21966 bytes
Concurrency Level: 100
Time taken for tests: 7.392 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 2357528 bytes
HTML transferred: 2320439 bytes
Requests per second: 13.53 [#/sec] (mean)
Time per request: 7391.820 [ms] (mean)
Time per request: 73.918 [ms] (mean, across all concurrent requests)
Transfer rate: 311.46 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 11 749 1248.5 96 3037
Processing: 44 2361 1763.3 2064 7151
Waiting: 29 630 595.0 415 3061
Total: 122 3110 2002.9 3629 7234
Percentage of the requests served within a certain time (ms)
50% 3629
66% 4245
75% 4644
80% 4947
90% 5532
95% 6486
98% 6776
99% 7234
100% 7234 (longest request)
[root@localhost public]#