2009年05月13日 16:45 [Edit]

tips - Webサーバーの負荷テストならまずab

abとは何かというと、apacheに標準でついてくる負荷テストツールの名前。apacheが入っている環境であれば、まず間違いなく入っているはず。

引数なしだと、help表示。

~% abab: 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
    -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)

で、実際に使ってみる。keep-aliveあり、同時接続4本で100リクエスト。

% ab -k -c4 -n 100 http://blog.livedoor.jp/dankogai/
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 blog.livedoor.jp (be patient).....done


Server Software:        Apache/2.2.4
Server Hostname:        blog.livedoor.jp
Server Port:            80

Document Path:          /dankogai/
Document Length:        256516 bytes

Concurrency Level:      4
Time taken for tests:   2.272 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Keep-Alive requests:    96
Total transferred:      26107138 bytes
HTML transferred:       26067466 bytes
Requests per second:    44.01 [#/sec] (mean)
Time per request:       90.880 [ms] (mean)
Time per request:       22.720 [ms] (mean, across all concurrent requests)
Transfer rate:          11221.47 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.4      0       8
Processing:    53   89  29.0     89     302
Waiting:        6   10   2.6     10      18
Total:         53   89  29.2     89     302

Percentage of the requests served within a certain time (ms)
  50%     89
  66%     95
  75%     99
  80%    104
  90%    113
  95%    123
  98%    135
  99%    302
 100%    302 (longest request)

こんな感じで、極めてお手軽ながらほとんどの場合において必要十分なテストができる。見てのとおり、apache付属だからといって、ローカルしかテストできないなんてこともない。

上の例では、本blogに対して負荷テストをしてみたが、アメブロ相手だと界王拳になってしまうのだろうか。アメブロユーザーの君、悪用するなよ、絶対悪用するなよ(笑)

Dan the Man with Too Many HTTP Connections to Evaluate


この記事へのトラックバックURL