雑多なインフラエンジニア日記

技術ブログでっす~

weighttpでwebサーバの負荷テスト

Apache Bench飽きたし他に何か無いのかな~と探したら、weighttp にたどり着きました。
(SSL未対応ですが・・・)

ほんとは、ApacheJmeterで小難しいシナリオ作ってWebサーバの負荷試験を
行うのがベストだと思いますけどね。


・参考にしたサイト
http://www.iij.ad.jp/company/development/tech/activities/weighttp/index.html#Message-complete
http://matsu911.github.io/waf_book_ja/#_%E3%83%80%E3%82%A6%E3%83%B3%E3%83%AD%E3%83%BC%E3%83%89%E3%81%8A%E3%82%88%E3%81%B3%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB

セットアップ (pythonはインストール済みとする)

・libenvのインストール
wget http://dist.schmorp.de/libev/libev-4.15.tar.gz
tar xfz libev-4.15.tar.gz
cd libev-4.15
./configure
make
make install

・weighttp のインストール
wget http://cgit.lighttpd.net/weighttp.git/snapshot/weighttp-master.tar.gz
tar xfz weighttp-master.tar.gz
cd weighttp-master
./waf configure
gcc -O2 -DVERSION='"0.3"' src/*.c -o weighttp -lev -lpthread

$ ll
total 132
-rw-rw-r-- 1 root root 1081 Feb 23 20:22 COPYING
-rw-rw-r-- 1 root root 687 Feb 23 20:22 README
drwxrwxr-x 2 root root 4096 Feb 23 20:22 src
-rw-rw-r-- 1 root root 111 Feb 23 20:22 TODO
-rwxrwxr-x 1 root root 86338 Feb 23 20:22 waf
-rwxr-xr-x 1 root root 22458 Apr 24 15:23 weighttp
-rw-rw-r-- 1 root root 1883 Feb 23 20:22 wscript
$


参考にしたサイトだと、./waf build で、weighttp がインストールされると書いて
ありましたが、出来なかったのでgccでインストールしてます。
(pythonをソースインストールしているのが原因っぽいけど、その件は放置)

weighttp のコマンドオプション

$ ./weighttp --help
weighttp - a lightweight and simple webserver benchmarking tool

error: unkown option: --
weighttp <options> <url>
  -n num   number of requests    (mandatory)
  -t num   threadcount           (default: 1)
  -c num   concurrent clients    (default: 1)
  -k       keep alive            (default: no)
  -6       use ipv6              (default: no)
  -H str   add header to request
  -h       show help and exit
  -v       show version and exit

example: weighttpd -n 10000 -c 10 -t 2 -k -H "User-Agent: foo" localhost/index.html

$


-k は、1コネクションで複数リクエストを投げる
-n は、リクエストの総数
-c は、同時接続数
-t は、スレッド数

-n 100 -c 10 だと、1接続10リクエスト となります。
-c と -t は同じ値じゃないとエラーになります。
ヘルプの例では値が違うんですけどね。。

※2013/05/03追記
-t ですが、Core数がベターのようです。エラー回避するには
export LIBEV_FLAGS=Core数
が必要っぽいです。


負荷試験

・負荷掛け側 → AWS-東京リージョン m1.xlarge
・負荷掛けられる側 → AWSではないサーバ

 
$ ./weighttp -k -c 100 -n 10000 http://xxxx.jp/
weighttp - a lightweight and simple webserver benchmarking tool

starting benchmark...
spawning thread #1: 100 concurrent requests, 10000 total requests
progress:  10% done
progress:  20% done
progress:  30% done
progress:  40% done
progress:  50% done
progress:  60% done
progress:  70% done
progress:  80% done
progress:  90% done
progress: 100% done

finished in 2 sec, 533 millisec and 184 microsec, 3947 req/s, 1592 kbyte/s
requests: 10000 total, 10000 started, 10000 done, 10000 succeeded, 0 failed, 0 errored
status codes: 0 2xx, 10000 3xx, 0 4xx, 0 5xx
traffic: 4130000 bytes total, 2400000 bytes http, 1730000 bytes data
$


上記の例ですと、
・100接続、10000リクエスト(100リクエスト/1接続)を捌くのに、2.5秒掛かった。
スループットは、3947リクエスト/秒
・全リクエストのステータスコードは、200番
・総トラフィックは、4MB
となります。

負荷を上げていって500番エラーが返って来たら性能限界と判断して良いと
思います。

負荷掛け側が1台だと中々、性能限界が測れないので、複数台同時に
負荷を掛けたほうがベターです。

このような場合にAWSは便利ですね。
ハイスペックマシンからアタックできる&終わったらさくっとTerminate
できるので。

Jmeterよりちょっと使いやすい BadBoy てのもあります。(名前が・・)
http://d.hatena.ne.jp/language_and_engineering/20081018/1224254143
http://www.badboy.com.au/

以上です。