CONTACT
お問い合わせ

ApacheBenchの利用方法

ApacheBenchの利用方法について記述する。

目次

ApacheBenchの利用方法

  1. ApacheBench概要
  2. できない事
  3. 利用方法と各種オプション
  4. 実際の動作と結果
  5. 利用時の注意点

1.ApacheBench概要

ApacheBenchとはWebサーバのベンチマークを行うためのツールであり、WEBサーバの実行性能を測定できる。
ApacheWebサーバのインストール時に同時にインストールされ、abコマンド(Windowsの場合はab.exe)として提供されている。

1回のコマンド実行で、単一かつ同一のURLに対するリクエストを簡単に行う事ができる。
また、リクエスト数および並列数の指定が可能であるため、複数ユーザ(端末)からのリクエストと1回のコマンドでシミュレートおよび実行することが可能である。

「1秒間に処理したリクエスト数の平均値」「1リクエストの処理に要した時間の平均値」「異常リクエスト件数」「パーセンタイル値」などを取得する事が可能であるため、
動作性能だけでなく、限界性能(エラーの発生するリクエスト程度)も簡単に確認する事が可能である。

2.できない事

複数のURLに対してリクエストしたい場合や、定められた処理順にリクエストするなどの場合は、ApacheBench自体では難しく、ApacheBench拡張もあるが、Apache Jmeterなどの別のツールを利用するのがベターである。

3.利用方法と各種オプション

[root@Ruby ~]# ab -h
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 ※ファイルのPOST(アップロード)処理
 -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)

4.実際の動作と結果

 例)Webサイト「http://www.a-frontier.jp/」にトータル2,000件のリクエストを10並列で行う

[root@Ruby ~]# ab -n 2000 -c 10 http://www.a-frontier.jp/
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 www.a-frontier.jp (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests

Server Software: Apache
Server Hostname: www.a-frontier.jp
Server Port: 80

Document Path: /
Document Length: 13552 bytes

Concurrency Level: 10  ※同時アクセス数(-cで指定した値)
Time taken for tests: 10.680 seconds
Complete requests: 2000 ※総リクエスト数(-nで指定した値)
Failed requests: 0  ※失敗したリクエスト数 ←この数値がZEROでない場合は処理可能限度を超えているという事となる
Write errors: 0
Total transferred: 27553050 bytes
HTML transferred: 27137601 bytes
Requests per second: 187.27 [#/sec] (mean)  ※1秒当たりの平均処理リクエスト数
Time per request: 53.398 [ms] (mean)  ※全リクエストの処理時間
Time per request: 5.340 [ms] (mean, across all concurrent requests)  ※1リクエストあたりの処理時間
Transfer rate: 2519.48 [Kbytes/sec] received  ※ネットワーク環境の実効速度よりも遅いようであれば、ネットワーク環境のチューニングも考慮

Connection Times (ms)
       min mean[+/-sd] median max
Connect:  14  16   1.5   16   27  ※接続時間(接続確立までにかかった時間)
Processing: 33  37   3.1   37   62 ※処理時間(接続確立からクライアントがレスポンスを受け取るまでにかかった時間)
Waiting:   16  20   2.2   19   44  ※待ち時間(対象サーバ側での処理時間)
Total:    47  53   4.2   53   86

Percentage of the requests served within a certain time (ms)  ※所定時間内に処理されたリクエストの割合
 50% 53  ※「50% 53」は、50%のリクエストが53ms以内に処理されたことを表す
 66% 54
 75% 55
 80% 55
 90% 57
 95% 59
 98% 63
 99% 72
 100% 86 (longest request)

5.利用時の注意点

・ApacheBench自体の動作に相応するCPUやメモリを使用するため、測定対象のサーバとApacheBenchの実行サーバは別にしておく必要がある。
・他者(社)の管理するWebサイトへの負荷テストはDDoSとなり得るため、「刑法第234条の2 電子計算機損壊等業務妨害罪」に引っかかる可能性がある。