2013年8月13日 星期二

[研究] ApacheBench 2.3 (CentOS 6.4 x64)

[研究] ApacheBench 2.3 (CentOS 6.4 x64)

ApacheBench (ab) 是 Apache HTTP server benchmarking tool

CentOS 6.4 預設好像會安裝它,可以用下面方法查出是 httpd-tools 套件中的工具

[root@localhost ~]# rpm -q --whatprovides /usr/bin/ab
httpd-tools-2.2.15-26.el6.centos.x86_64

安裝最新版 ApacheBench

[root@localhost ~]# yum -y install  httpd-tools

執行 ab,可以看出提供的參數,最常用的該是 -n 和 -c

[root@localhost ~]# ab
ab: wrong number of arguments
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 ~]#

檢查版本

[root@localhost ~]# ab -V
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/

先簡單測試一下,送出 200 個要求,同一時間最多 100 要求同時出現
(可以想成某段時間共 200 人次瀏覽,同一時間最多 100 人同時瀏覽;所以 n 不可小於 c )

注意:這台網站是另外架設的測試機器,不要拿公開的網站當白老鼠

[root@localhost ~]# ab -n 200 -c 100 http://forum2.icst.org.tw/phpbb/index.php
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 forum2.icst.org.tw (be patient)
Completed 100 requests
Completed 200 requests
Finished 200 requests


Server Software:        Apache/2.2.15
Server Hostname:        forum2.icst.org.tw
Server Port:            80

Document Path:          /phpbb/index.php
Document Length:        84222 bytes

Concurrency Level:      100
Time taken for tests:   6.291 seconds
Complete requests:      200
Failed requests:        0
Write errors:           0
Total transferred:      16968400 bytes
HTML transferred:       16844400 bytes
Requests per second:    31.79 [#/sec] (mean)
Time per request:       3145.380 [ms] (mean)
Time per request:       31.454 [ms] (mean, across all concurrent requests)
Transfer rate:          2634.13 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    7   5.0      9      13
Processing:   587 2583 934.7   2983    3968
Waiting:      577 2560 932.8   2949    3815
Total:        600 2590 930.9   2986    3968

Percentage of the requests served within a certain time (ms)
  50%   2986
  66%   3232
  75%   3303
  80%   3382
  90%   3458
  95%   3519
  98%   3612
  99%   3689
 100%   3968 (longest request)
[root@localhost ~]#

接下來測試 (建議 n 比 c 大個10倍或更多,若 -n 100 -c 100,雖然 -c 100 設定同時最多 100 個要求同時送出,但實際上不太可能發生)
ab -n 1000 -c 100 http://forum2.icst.org.tw/phpbb/index.php
ab -n 1000 -c 200 http://forum2.icst.org.tw/phpbb/index.php
ab -n 1000 -c 300 http://forum2.icst.org.tw/phpbb/index.php
都順利跑完

[root@localhost ~]# ab -n 1000 -c 400 http://forum2.icst.org.tw/phpbb/index.php
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 forum2.icst.org.tw (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
apr_socket_recv: Connection refused (111)
Total of 758 requests completed

順利跑完的只有 758 個 request,再跑一次

[root@localhost ~]# ab -n 1000 -c 400 http://forum2.icst.org.tw/phpbb/index.php
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 forum2.icst.org.tw (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
apr_socket_recv: Connection reset by peer (104)
Total of 481 requests completed
[root@localhost ~]#

情況相同,也就是大約最多可以承受約 300 ~ 400 人同時上線 (因為測試機只是台 VM)

要找精確的 Break Point (BreakPoint) 值,可用二分法測試
測試 -n 1000 -c 350,如果順利,增加 -c 值,取 (350+400)/2 = 375 測試;
不順利則降低 -c 值,取 (300+350)/2 = 325 測試;

因為每次測試結果不同,相同 -c 值應該多測試幾次,且 Break Point 應該無法精確到個位數,甚至十位數也不敢保證

(完)

沒有留言:

張貼留言