Node.jsとApacheでabテスト
Mac Lion上のMAMPのApacheとNode.jsでabによるテストを行ってみました。
他のプロセスが色々動いていたり、あまり正確とは言えませんので、参考まで。
サクッとテストしたいところですが、Macでabテストをしようとすると、いくつか問題があったので、事前準備をします。
abコマンドの更新
テストをしていると以下のエラーが発生する時があります。
apr_socket_recv: Connection reset by peer (54)
これは付属のabコマンドのバージョンが古いためのようですので、最新のソースを取得してビルドします。
$ wget http://apache.mirrors.pair.com//httpd/httpd-2.4.2.tar.bz2
$ brew install pcre
$ tar zxf httpd-2.4.2.tar.bz2
$ cd httpd-2.4.2
$ ./configure
$ make
abコマンド自体はhttpd-2.4.2/support/にビルドされています。/usr/sbin/にある、付属のabに上書きコピーしても良いと思います。
ちなみに、http://localhostではテストできなかったので、127.0.0.1で実行しました。
ファイルデスクリプタの上限値を変更
abコマンドで一定数以上の接続を試みると、こちらでも以下のようにエラーが出てエラーになってしまいます。
$ ./ab -c 1000 -n 1000 http://127.0.0.1/ 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 127.0.0.1 (be patient) socket: Too many open files (24)
制限値を確認してみます。
$ ulimit -n 256
一時的に制限値を上げます。
$ sudo ulimit -n 1024
Node.jsでテスト
上記の準備をしても、エラーでテストできない場合があります。何度か試しての結果です。
# ./ab -c 1000 -n 1000 http://127.0.0.1:8000/ 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 127.0.0.1 (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: Server Hostname: 127.0.0.1 Server Port: 8000 Document Path: / Document Length: 24 bytes Concurrency Level: 1000 Time taken for tests: 0.287 seconds Complete requests: 1000 Failed requests: 224 (Connect: 7, Receive: 0, Length: 217, Exceptions: 0) Write errors: 0 Non-2xx responses: 783 Total transferred: 776812 bytes HTML transferred: 686935 bytes Requests per second: 3486.90 [#/sec] (mean) Time per request: 286.788 [ms] (mean) Time per request: 0.287 [ms] (mean, across all concurrent requests) Transfer rate: 2645.18 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 18 16.9 8 46 Processing: 7 56 22.2 45 87 Waiting: 7 42 19.5 40 81 Total: 25 74 30.0 77 124 Percentage of the requests served within a certain time (ms) 50% 77 66% 86 75% 90 80% 115 90% 116 95% 117 98% 117 99% 124 100% 124 (longest request)
Requests per secondは3500〜3900くらいは出ました。
Apacheでテスト
900リクエストあたりでConnection reset by peer (54)が多発してしまいましたが、こちらも何度か試して出た結果です。
# ./ab -c 1000 -n 1000 http://127.0.0.1/ 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 127.0.0.1 (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/2.2.21 Server Hostname: 127.0.0.1 Server Port: 80 Document Path: / Document Length: 3076 bytes Concurrency Level: 1000 Time taken for tests: 0.190 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 3369000 bytes HTML transferred: 3076000 bytes Requests per second: 5260.53 [#/sec] (mean) Time per request: 190.095 [ms] (mean) Time per request: 0.190 [ms] (mean, across all concurrent requests) Transfer rate: 17307.34 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 5 11.8 0 37 Processing: 2 18 3.9 19 24 Waiting: 2 18 3.9 19 24 Total: 16 23 9.3 20 54 Percentage of the requests served within a certain time (ms) 50% 20 66% 21 75% 21 80% 22 90% 42 95% 49 98% 52 99% 53 100% 54 (longest request)
と、ここまでやってNode.jsはCPU分立ち上げないと意味ないんだっけというのを思い出した次第。