イベント駆動で書くと
クラウド破産を回避できたり、自宅サーバを守れるというメリットがあるらしいので、どうせなら epoll を使ってみようということで。
http://d.hatena.ne.jp/odz/20070507/1178558340 と http://alpha.mixi.co.jp/blog/?p=76 と man が参考に。某所経由で id:koizuka 氏にいろいろ教わり助かりました。
nginx 速すぎで大変悲しい結果に。
ソース
http://d.hatena.ne.jp/odz/20070507/1178558340 の勝手 fork です。問題/間違い等あれば連絡いただければありがたいです。エラー処理は省略気味。
ベンチマーク
それぞれ debian 上で epoll_sample, nginx, Apache2 を実行。nginx, apache2 ともに apt-get install で持ってきて設定はデフォルトのまま。
epoll_sample
# ab -n 10000 -c 50 http://localhost:8080/ This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Server Hostname: localhost Server Port: 8080 Document Path: / Document Length: 7 bytes Concurrency Level: 50 Time taken for tests: 20.125 seconds Complete requests: 10000 Failed requests: 0 Write errors: 0 Total transferred: 710142 bytes HTML transferred: 70014 bytes Requests per second: 496.91 [#/sec] (mean) Time per request: 100.623 [ms] (mean) Time per request: 2.012 [ms] (mean, across all concurrent requests) Transfer rate: 34.46 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 3 46 12.6 46 117 Processing: 9 48 13.8 48 241 Waiting: 0 32 15.2 35 239 Total: 32 95 23.2 94 244 Percentage of the requests served within a certain time (ms) 50% 94 66% 96 75% 99 80% 101 90% 109 95% 135 98% 168 99% 178 100% 244 (longest request)
nginx
# ab -n 10000 -c 50 http://localhost:80/ This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: nginx/0.6.32 Server Hostname: localhost Server Port: 80 Document Path: / Document Length: 151 bytes Concurrency Level: 50 Time taken for tests: 22.493 seconds Complete requests: 10000 Failed requests: 0 Write errors: 0 Total transferred: 3627602 bytes HTML transferred: 1513171 bytes Requests per second: 444.58 [#/sec] (mean) Time per request: 112.465 [ms] (mean) Time per request: 2.249 [ms] (mean, across all concurrent requests) Transfer rate: 157.50 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 3 54 9.6 53 128 Processing: 33 57 11.1 54 139 Waiting: 7 46 12.1 46 134 Total: 64 112 15.2 107 230 Percentage of the requests served within a certain time (ms) 50% 107 66% 111 75% 113 80% 114 90% 119 95% 146 98% 171 99% 182 100% 230 (longest request)
Apache2
# ab -n 10000 -c 50 http://localhost:80/ This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Apache/2.2.9 Server Hostname: localhost Server Port: 80 Document Path: / Document Length: 45 bytes Concurrency Level: 50 Time taken for tests: 31.275 seconds Complete requests: 10000 Failed requests: 0 Write errors: 0 Total transferred: 3204993 bytes HTML transferred: 452115 bytes Requests per second: 319.74 [#/sec] (mean) Time per request: 156.377 [ms] (mean) Time per request: 3.128 [ms] (mean, across all concurrent requests) Transfer rate: 100.07 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 46 74 16.8 70 194 Processing: 51 81 16.9 81 211 Waiting: 3 52 28.2 53 172 Total: 138 155 20.2 149 401 Percentage of the requests served within a certain time (ms) 50% 149 66% 153 75% 156 80% 158 90% 169 95% 198 98% 230 99% 238 100% 401 (longest request)