IT井戸端会議

IT井戸端会議

インフラ、ネットワーク、アプリケーション開発、IT界隈の話等々を東京都千代田区界隈から発信します。

Apache Bench のインストール手順

インストール

abのインストールにはApcheをインストールする必要があります。

$ sudo yum -y install httpd

負荷テストのやり方

負荷テストを実行するコマンドについて説明します。 ターミナルからコマンドを実行する事でサーバーに負荷をかけていきます。 構文はこのようになります

    $ ab [-OPTION] URL

例) 10人の同時接続を100回実行するコマンド

$ ab -n 100 -c 10 http://example.com/

abオプション一覧

コマンドで使えるオプションの一覧です。

オプション説明
-n 数値テストで発行するリクエストの回数を数値で指定
-c 数値テストで同時に発行するリクエストの数を数値で指定
-t 数値サーバからのレスポンスの待ち時間(秒)を数値で指定
-p ファイル名サーバへ送信するファイルがある場合に指定
-t コンテンツタイプサーバへ送信するコンテンツヘッダを指定
-v 数値指定した数値に応じた動作情報を表示
-w結果をhtmlで出力(出力をファイルに保存すればwebブラウザで表組みされたものが見られる)
-x 属性html出力のtableタグに属性を追加(borderなど)
-y 属性html出力のtrタグに属性を追加
-z 属性html出力のtdまたはthタグに属性を追加
-c ‘cookie名称=値’cookie値を渡してテストする
-a ユーザー名:パスワードベーシック認証が必要なコンテンツにテストする
-p ユーザー名:パスワード認証の必要なプロキシを通じてテストする
-x プロキシサーバ名:ポート番号プロキシ経由でリクエストする場合に指定
-vabのバージョン番号を表示
-khttp/1.1のkeepaliveを有効にしてテストする
-habのヘルプを表示


負荷テストを実行

負荷テストを実行してみます。 テストが完了すると、下のように結果がコンソールに出力されます。

$ ab -n 1000 -c 100 http://www.exapmle.com/
This is ApacheBench, Version 2.3 <$Revision: 1178079 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
 
Benchmarking www.exapmle.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


Server Software:        Apache
Server Hostname:        exapmle.com
Server Port:            80

Document Path:          /
Document Length:        18634 bytes

Concurrency Level:      100
Time taken for tests:   53.471 seconds
Complete requests:      1000
Failed requests:        308
   (Connect: 0, Receive: 0, Length: 308, Exceptions: 0)
Write errors:           0
Non-2xx responses:      308
Total transferred:      13305317 bytes
HTML transferred:       13061664 bytes
Requests per second:    18.70 [#/sec] (mean)
Time per request:       5347.142 [ms] (mean)
Time per request:       53.471 [ms] (mean, across all concurrent requests)
Transfer rate:          243.00 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       37  562 629.6    322    4898
Processing:    63 3184 6009.8    540   52827
Waiting:       47 1524 3194.3    438   42777
Total:        108 3746 6167.5   1011   53471

Percentage of the requests served within a certain time (ms)
  50%   1011
  66%   2388
  75%   4347
  80%   5581
  90%  10652
  95%  15672
  98%  23009
  99%  28869
 100%  53471 (longest request)

特に確認すべき内容は下の3点です。

Failed requests

NGリクエストの数。ここが多いほど処理能力をオーバーしています。

Requests per second

1秒間に処理出来るリクエスト数が判ります。数字が大きいほど制能が良いです。

Connection Times Connect/Processing/Waiting

リクエスト当たりの処理の内訳を示す。 測定したリクエスト全体でのばらつきやリクエスト当たりの処理の内訳を見極るための指標にします。

出力結果の見方

Server SoftwareApacheのバージョン
Server Hostnameサーバマシン名
Server Portポート番号
Document Pathアクセス先ファイル
Document Lengthアクセス先ファイルサイズ
Concurrency Level同時送信リクエスト数
Time taken for testsリクエスト完了に要した処理時間
Complete requests総リクエスト数
Failed requests失敗したリクエスト回数
Total transferredファイルの総容量
HTML transferredアクセス先ファイルの容量
Requests per second1秒あたりに処理されたリクエスト数
Time per request1秒あたりに処理された所要時間
Time per request(mean, across all concurrent requests)1秒あたりに処理された所要時間
Transfer rate1秒あたりに受信された容量
Connnection Times (ms)上から順に接続(Connect)、処理(Processing)、待ち時間(Wait)を集計し、最小値、平均、最大値、平均で表している
Percentage of the requests served within a certain time (ms)処理時間の推移


負荷テストには他にもApache JMeterなどがありますが、 単一ページのテストを行いたいのであればApache Benchが1番だと思います。