使用ApacheBench对网站进行压力测试

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014424628/article/details/50095311

网站发布了,性能怎么样呢?是时候测试一下了

Apache服务器下载地址:http://www.apache.org/
当我们安装Apache服务器之后,我们在其bin目录下可以看到一个ab.exe,的确ApacheBench(ab)是Apache附带的一个小工具,专门用来做HTTP服务器的BenchMark Testing的。

ok,下面我们以淘宝网为测试对象说明一下这个ab到底是如何使用的。(window下)
打开cmd控制台,切换到ab.exe路径下。
执行下面这条命令:
ab -n 1000 -c 10 http://www.taobao.com/【-n表示发送的请求数,这里发送1000次请求,-c表示每次的并发数,这里设置为10,注意后面的/不要掉了!】
下面是输出的一堆信息:

C:\server\Apache24\bin>ab -n 1000 -c 10 http://www.taobao.com/
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 www.taobao.com (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                   //1000次请求结束


Server Software:        Tengine          //淘宝网使用的web服务器
Server Hostname:        www.taobao.com   //域名
Server Port:            80       //端口号

Document Path:          /                //请求的路径,这里是根路径
Document Length:        258 bytes        //第一次返回的文档的大小,大小发生改变,这个响应会视为一个错误。

Concurrency Level:      10               //并发数,也就是我们前面设置的-c参数值
Time taken for tests:   54.977 seconds   //这1000次请求一共花费的时间是54.977秒
Complete requests:      1000             //成功的请求次数
Failed requests:        2                //失败的请求次数
   (Connect: 2, Receive: 0, Length: 0, Exceptions: 0)                           //连接失败,接收异常,长得异常,读取失败
Non-2xx responses:      1000
Total transferred:      560000 bytes     //从服务器接收的字节数。
HTML transferred:       258000 bytes     //html内容字节数
Requests per second:    18.19 [#/sec] (mean) //没秒请求数
Time per request:       549.766 [ms] (mean)  //每个并发的时间
Time per request:       54.977 [ms] (mean, across all concurrent requests)              //每次并发中,每个请求的时间
Transfer rate:          9.95 [Kbytes/sec]   received  //没秒的网络传输量

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        8   13   4.0     12      55   //socket从发送请求到建立连接所花费的时间
Processing:    10  494 2796.3    109   21385   //建立连接后,直到http全部接收所用的时间
Waiting:        9  334 2290.8     78   21115
//发送HTTP后,到接收到第一个字节所等待的时间
Total:         26  507 2796.2    121   21399
//connect+processing的时间

//对于整个1000个请求来说,50%的请求的响应时间在121毫秒内,60%的请求响应时间在126毫秒内,....,最长的请求响应时间为21399毫秒
Percentage of the requests served within a certain time (ms)
  50%    121
  66%    126
  75%    130
  80%    133
  90%    154
  95%    185
  98%   1082
  99%  21128
 100%  21399 (longest request)

下面看看 ApacheBench有哪些参数。输入ab -help即可查看。
C:\server\Apache24\bin>ab -help
Usage: ab [options] [http://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make at a time
-t timelimit Seconds to max. to spend on benchmarking
This implies -n 50000
-s timeout Seconds to max. wait for each response
Default is 30 seconds
-b windowsize Size of TCP send/receive buffer, in bytes
-B address Address to bind to when making outgoing connections
-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 to use for POST/PUT data, 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.
-q Do not show progress when doing more than 150 requests
-l Accept variable document length (use this for dynamic pages)
-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.
-m method Method name
-h Display usage information (this message)

猜你喜欢

转载自blog.csdn.net/u014424628/article/details/50095311