httpサーバの負荷テスト用のツールを探していたら、IIJのサイトで weighttp というツールが紹介されていたので試してみました。検証環境はCentOS7です。
libevのインストール
weighttpでは libev を利用するので、epelレポジトリを追加してから libev と libev-devel をインストールします。
$ yum install -y epel-release
$ yum install libev libev-devel -y
weightttpのソースコードの入手
githubからソースコードを入手します。
$ cd /usr/local/src
$ git clone https://github.com/lighttpd/weighttp.git
weightttpのビルド・インストール
weighttpのビルドとインストールはwafを用いて以下のように行います。
$ cd weighttp
$ ./waf configure
Checking for program gcc,cc : ok /usr/bin/gcc
Checking for program cpp : ok /usr/bin/cpp
Checking for program ar : ok /usr/bin/ar
Checking for program ranlib : ok /usr/bin/ranlib
Checking for gcc : ok
Checking for library ev : ok
Checking for header ev.h : ok
Checking for library pthread : ok
Checking for header pthread.h : ok
Checking for header unistd.h : ok
Checking for header stdint.h : ok
Checking for header fcntl.h : ok
Checking for header inttypes.h : ok
'configure' finished successfully (2.184s)
$ ./waf build
Waf: Entering directory `/usr/local/src/weighttp/build'
[1/4] cc: src/client.c -> build/default/src/client_1.o
[2/4] cc: src/weighttp.c -> build/default/src/weighttp_1.o
[3/4] cc: src/worker.c -> build/default/src/worker_1.o
[4/4] cc_link: build/default/src/client_1.o build/default/src/weighttp_1.o build/default/src/worker_1.o -> build/default/weighttp
Waf: Leaving directory `/usr/local/src/weighttp/build'
'build' finished successfully (0.911s)
$ ./waf install
Waf: Entering directory `/usr/local/src/weighttp/build'
* installing build/default/weighttp as /usr/local/bin/weighttp
Waf: Leaving directory `/usr/local/src/weighttp/build'
'install' finished successfully (0.016s)
動作確認
ビルドが成功したら、動作確認を行います。
まず、パラメタなしで実行して、usage からコマンドの書式を確認します。
$ weighttp
weighttp - a lightweight and simple webserver benchmarking tool
error: missing url argument
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
最後にコマンドの実行例が表示されますが、なぜかコマンド名が間違っているので注意
表示された書式を参考に、localhostのhttpdに対してweighttpを実行すると、以下のような結果が出力されました。
$ weighttp -n 10000 -c 10 -t 2 -k -H "User-Agent: foo" localhost/noindex/css/open-sans.css
weighttp - a lightweight and simple webserver benchmarking tool
starting benchmark...
spawning thread #1: 5 concurrent requests, 5000 total requests
spawning thread #2: 5 concurrent requests, 5000 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 1 sec, 419 millisec and 293 microsec, 7045 req/s, 36911 kbyte/s
requests: 10000 total, 10000 started, 10000 done, 10000 succeeded, 0 failed, 0 errored
status codes: 10000 2xx, 0 3xx, 0 4xx, 0 5xx
traffic: 53646048 bytes total, 2836048 bytes http, 50810000 bytes data
また、httpdのログファイルを確認してみると、weighttpからのアクセスログが記録されていました。
$ tail /var/log/httpd/access_log
127.0.0.1 - - [23/May/2015:19:11:10 +0900] "GET /noindex/css/open-sans.css HTTP/1.1" 200 5081 "-" "foo"
127.0.0.1 - - [23/May/2015:19:11:10 +0900] "GET /noindex/css/open-sans.css HTTP/1.1" 200 5081 "-" "foo"
127.0.0.1 - - [23/May/2015:19:11:10 +0900] "GET /noindex/css/open-sans.css HTTP/1.1" 200 5081 "-" "foo"
127.0.0.1 - - [23/May/2015:19:11:10 +0900] "GET /noindex/css/open-sans.css HTTP/1.1" 200 5081 "-" "foo"
127.0.0.1 - - [23/May/2015:19:11:10 +0900] "GET /noindex/css/open-sans.css HTTP/1.1" 200 5081 "-" "foo"
127.0.0.1 - - [23/May/2015:19:11:10 +0900] "GET /noindex/css/open-sans.css HTTP/1.1" 200 5081 "-" "foo"
127.0.0.1 - - [23/May/2015:19:11:10 +0900] "GET /noindex/css/open-sans.css HTTP/1.1" 200 5081 "-" "foo"
::1 - - [23/May/2015:19:11:11 +0900] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.6 (CentOS) (internal dummy connection)"
::1 - - [23/May/2015:19:11:12 +0900] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.6 (CentOS) (internal dummy connection)"
::1 - - [23/May/2015:19:11:13 +0900] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.6 (CentOS) (internal dummy connection)"
どうやら問題なく動作しているようです