記事内に広告が含まれています

【ワレコの実験】ApacheBenchで負荷テストをやってみた

この記事は約11分で読めます。
スポンサーリンク

どうも、今使っているWindows VPSレンタルサーバーの反応が遅いのでどうにかして速くしたいのだが、WordPressのキャッシュプラグインなど各種試したのだが改善しない。

で、サーバーの性能を定量的に評価する手法を探していて、ApacheBench というツールを見つけた。

ApacheBench とは、Apache サーバーに標準で付属している負荷テスト用のツールらしい。

ワテの場合、Windows7 なので Apache 用のツールなら Linux でないと使えないのかなと一瞬思ったのだが、良く考えてみると Windows7 には、Xampp をインストールしているので、そこに Apache が入っているはずだ。

当記事は、ApacheBenchで負荷テストをやってみた備忘録

では、本題に入ろう。

ちなみに、その遅いWindows VPSは解約して、現在ワテが使っているWindows VPSはこれだ。

もしレンタルサーバー関連で質問がある方は、末尾のコメント欄からお気軽にお問い合わせ下さい。

では、本題に入ろう。

スポンサーリンク
スポンサーリンク

ApacheBenchを試す

ApacheBenchはXamppにも入っている

早速、DOS のコンソールを開いてApacheにインストールフォルダを確認してみた。

そうすると、

C:\xampp\apache\bin>

の中に、

ab.exe

という、ApacheBenchツールが有るではないか!

ネットの情報を参考に早速使ってみた。

ab -n 100 -c 100 http://www.example.com/

とすると、100 ユーザが同時に http://www.example.com/ に 1 リクエストを発行した場合の性能テストができる。

ab -n 10000 -c 100 http://www.example.com/

とすると、100 ユーザが同時に http://www.example.com/ に 100 リクエストを発行した場合の性能テストができる。

トータルで 同時に 10000リクエストだ。

つまり -n 数字 「数字」は、1ユーザーのリクエストではなくて、-c で指定した全ユーザーのトータルのリクエスト数を指定するようだ。

何故そうなっているのか知らないが。

普通の感覚なら、

-n ユーザー当たりのリクエスト

-c ユーザーの数

みたいなパラメータにしそうなのに。

兎に角 ApacheBenchを使ってみた

まあ、パラメータの指定方法の件はどうでも良いので早速ApacheBenchをやってみた。

C:\xampp\apache\bin>ab -n 100 -c 100 http://www.example.com
ab: invalid URL
Usage: ab [options] [http://]hostname[:port]/path
Options are:
-n requests     Number of requests to perform
-c concurrency  Number of multiple requests to make at a time
-t timelimit    Seconds to max. to spend on benchmarking
This implies -n 50000
-s timeout      Seconds to max. wait for each response
Default is 30 seconds
-b windowsize   Size of TCP send/receive buffer, in bytes
-B address      Address to bind to when making outgoing connections
-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 to use for POST/PUT data, 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.
-q              Do not show progress when doing more than 150 requests
-l              Accept variable document length (use this for dynamic pages)
-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.
-m method       Method name
-h              Display usage information (this message)

ApacheBenchがエラーした

いきなりエラーしてヘルプが出た。

末尾の / スラッシュを忘れていたようだ。

スラッシュを付けて再度実行すると実行出来た。

今度は成功

C:\xampp\apache\bin>ab -n 100 -c 100 http://www.example.com/
This is ApacheBench, Version 2.3 <$Revision: 1638069 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

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

Server Software:        ECS
Server Hostname:        www.example.com
Server Port:            80

Document Path:          /
Document Length:        1270 bytes

Concurrency Level:      100
Time taken for tests:   16.267 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      161000 bytes
HTML transferred:       127000 bytes
Requests per second:    6.15 [#/sec] (mean)
Time per request:       16266.930 [ms] (mean)
Time per request:       162.669 [ms] (mean, across all concurrent requests)
Transfer rate:          9.67 [Kbytes/sec] received

Connection Times (ms)
min  mean[+/-sd] median   max
Connect:      117  161  57.4    146     543
Processing:   123 7850 4664.7   8034   15604
Waiting:      122 7846 4665.5   8031   15602
Total:        257 8011 4669.9   8156   16147

Percentage of the requests served within a certain time (ms)
50%   8156
66%  10564
75%  12267
80%  13019
90%  14517
95%  15219
98%  15603
99%  16147
100%  16147 (longest request)

C:\xampp\apache\bin>

データの見方

取りあえず実行は出来た。

Complete requests:      100
Failed requests:        0

なので、現状は問題なく実行出来ているようだ。

リクエストを増やしていくと、ある時点でエラーが発生するのかな。

また、

Requests per second:    6.15 [#/sec] (mean)
Time per request:       16266.930 [ms] (mean)

の辺りの数字が、サーバー性能の指針となる数字のようだ。

 

今回はここまで。

今後、より詳細に実行結果データの見方を調査予定だ。

 

なお、重要な注意点を一つ紹介しておく。

重要な注意点を一つ

このApacheBenchのabコマンドを実行するとDOS攻撃とみなされる場合が有るようなので、注意が必要だ。

 

ちなみにワテがこのブログに使っているレンタルサーバーはこれだ。

レンタルサーバーでWordPressブログやるならエックスサーバーが無難


 

一方、Windows VPSを借りてVisual Studio でASP.NETのサイトを作るなら以下がお勧め。

Windows/Linux VPSでWEBサーバー運営ならエイブルネットがお勧め

もしレンタルサーバー関連で質問がある方は、末尾のコメント欄からお気軽にお問い合わせ下さい。

スポンサーリンク
コメント募集

この記事に関して何か質問とか補足など有りましたら、このページ下部にあるコメント欄からお知らせ下さい。

IISInternetVPS
スポンサーリンク
シェアする
warekoをフォローする
スポンサーリンク

コメント