Apache Benchでの速度検証
やりたいこと~Webサイトの速度計測~
CloudFlont + opcacheで速度を上げることに成功した。
しかし、これは体感でめっちゃ早くなった、というだけでは説得力がない気もするのでベンチマークで数字を出し立証してみようという気になった。
色々ツールはあるのだろうが、ググってすぐ出てきたApache Benchというものを利用してみようと思う。
これはApacheをインストールするとabコマンドも使えるようになるので特にコマンドインストールが不要だ。
計測~OPcache無し~
まずはOPcacheのパワーを確認してみた。
index.phpを指定することで、CloudFrontはキャッシュしていない。
純粋にOPcacheの有無での速度差を確認している。
(OPcache無) ab -c 10 -n 10 https://diary.hdora.tokyo/index.php ----- This is ApacheBench, Version 2.3 <$Revision: 1874286 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking diary.hdora.tokyo (be patient).....done Server Software: Apache Server Hostname: diary.hdora.tokyo Server Port: 443 SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128 Server Temp Key: ECDH P-256 256 bits TLS Server Name: diary.hdora.tokyo Document Path: /index.php Document Length: 0 bytes Concurrency Level: 10 Time taken for tests: 5.973 seconds Complete requests: 10 Failed requests: 0 Non-2xx responses: 10 Total transferred: 4550 bytes HTML transferred: 0 bytes Requests per second: 1.67 [#/sec] (mean) Time per request: 5973.411 [ms] (mean) Time per request: 597.341 [ms] (mean, across all concurrent requests) Transfer rate: 0.74 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 6 12 2.4 13 14 Processing: 2930 2984 35.1 2981 3027 Waiting: 2929 2984 35.1 2981 3027 Total: 2939 2997 35.0 2995 3034 Percentage of the requests served within a certain time (ms) 50% 2995 66% 3030 75% 3032 80% 3034 90% 3034 95% 3034 98% 3034 99% 3034 100% 3034 (longest request) -----
計測~OPcache有り~
(OPcache有) ab -c 10 -n 10 https://diary.hdora.tokyo/index.php ----- This is ApacheBench, Version 2.3 <$Revision: 1874286 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking diary.hdora.tokyo (be patient).....done Server Software: Apache Server Hostname: diary.hdora.tokyo Server Port: 443 SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128 Server Temp Key: ECDH P-256 256 bits TLS Server Name: diary.hdora.tokyo Document Path: /index.php Document Length: 0 bytes Concurrency Level: 10 Time taken for tests: 0.526 seconds Complete requests: 10 Failed requests: 0 Non-2xx responses: 10 Total transferred: 4550 bytes HTML transferred: 0 bytes Requests per second: 18.99 [#/sec] (mean) Time per request: 526.460 [ms] (mean) Time per request: 52.646 [ms] (mean, across all concurrent requests) Transfer rate: 8.44 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 7 10 1.6 10 12 Processing: 169 285 47.5 304 337 Waiting: 169 285 47.5 304 337 Total: 179 295 47.5 312 347 Percentage of the requests served within a certain time (ms) 50% 312 66% 314 75% 316 80% 335 90% 347 95% 347 98% 347 99% 347 100% 347 (longest request) -----
なんということだ・・・。
Time per requestやTime taken for testsあたりを見てほしい。
10倍くらい違うぞ・・・。
※OPcacheは初回だとキャッシュしていない為遅いので、一回コマンド打ってキャッシュさせたあとに計測している。
※アクセス総数(-n)は1、並列数(-c)を1でサーバにリクエストを行う。基本的に-nと-cのオプションだけ覚えていれば大丈夫らしい。
CloudFrontもOPcacheも効かせない状態だと遅すぎて話にならない。
計測~CloudFront+OPcache~
最後にCloudflont+OPcacheの結果を張り付けておく。
もうここまでくると普通にEC2のオールインワンサーバのWebサイトより早い。
※わたしの別サイトだとTime per requestは50msぐらい
EFSの遅さを完全にカバーできている。
(CloudFront+OPcache) ab -c 10 -n 10 https://diary.hdora.tokyo/ ----- This is ApacheBench, Version 2.3 <$Revision: 1874286 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking diary.hdora.tokyo (be patient).....done Server Software: Apache Server Hostname: diary.hdora.tokyo Server Port: 443 SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128 Server Temp Key: ECDH P-256 256 bits TLS Server Name: diary.hdora.tokyo Document Path: / Document Length: 28199 bytes Concurrency Level: 10 Time taken for tests: 0.024 seconds Complete requests: 10 Failed requests: 0 Total transferred: 286500 bytes HTML transferred: 281990 bytes Requests per second: 410.93 [#/sec] (mean) Time per request: 24.335 [ms] (mean) Time per request: 2.433 [ms] (mean, across all concurrent requests) Transfer rate: 11497.23 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 6 9 2.4 11 13 Processing: 2 3 0.6 3 4 Waiting: 2 3 0.9 2 4 Total: 9 13 2.1 13 16 WARNING: The median and mean for the waiting time are not within a normal deviation These results are probably not that reliable. Percentage of the requests served within a certain time (ms) 50% 13 66% 14 75% 14 80% 14 90% 16 95% 16 98% 16 99% 16 100% 16 (longest request) -----
宿題
ちなみにabコマンドはマスター、スレーブサーバではなく別インスタンスを立ててそこからコマンドを打っている。
マスター、スレーブからコマンドを打つと、SSL handshake failedエラーが出てしまう。
CloudFlontとNLBを使っていない普通のサイトであれば問題ないのだが・・・。
結局調べても原因が分からず宿題となってしまった。
Benchmarking diary.hdora.tokyo (be patient)...SSL handshake failed (1). 139925075445504:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:794: SSL handshake failed (1).