読者です 読者をやめる 読者になる 読者になる

ApacheBenchによる負荷テスト

ApacheBench(以下、ab)はApacheに付属する負荷テストツールです。負荷テストツールとしてはJMeterなどが有名ですが、abはApacheがインストールされていれば使えるという手軽さから、ちょっとした性能測定に重宝します。

よく使うオプションは同時接続数とリクエスト数です。

$ ab -c <同時接続数> -n <リクエスト数> <接続先URL>

同時接続数100、リクエスト数100でテストしてみました。接続先URLは/で終わっている必要があります。

$ ab -c 100 -n 100 http://www.tetsuyai.com/
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking www.tetsuyai.com (be patient).....done


Server Software:        Apache/2.2.3
Server Hostname:        www.tetsuyai.com
Server Port:            80

Document Path:          /
Document Length:        27 bytes

Concurrency Level:      100
Time taken for tests:   0.779089 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Non-2xx responses:      100
Total transferred:      37104 bytes
HTML transferred:       2700 bytes
Requests per second:    128.36 [#/sec] (mean)
Time per request:       779.089 [ms] (mean)
Time per request:       7.791 [ms] (mean, across all concurrent requests)
Transfer rate:          46.21 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    4   2.0      5       8
Processing:   158  467 127.2    435     774
Waiting:      157  466 127.1    434     773
Total:        158  471 128.1    440     775

Percentage of the requests served within a certain time (ms)
  50%    440
  66%    495
  75%    604
  80%    617
  90%    644
  95%    751
  98%    768
  99%    775
 100%    775 (longest request)

オプションなしで起動するとヘルプが表示されます。

$ 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
    -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)