Apacheからnginxに乗り換えた後のWordPressの性能
nginxの設定も一通り終えて、何とか動くようになってきました。いや、実に苦労しました。
設定などは前回同様、以下のサイトを参考にしました。
WordPressを100倍速くする! MySQLの調整やnginx proxy cache – KRAY Inc
さくらVPSのWordPressをチューニングして30倍高速化した方法 – 原宿・表参道.jp
自分はApacheから乗り換えたので、いくつかのパスや設定が上記サイトとは異なります。主にそのせいで苦労したんですが・・・。最終的に性能は出るようになりました。
before
[tsukaby@tsukaby ~]$ ab -c 100 -n 100 https://tech-blog.tsukaby.com/ 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 tsukaby.com (be patient).....done Server Software: Apache Server Hostname: tsukaby.com Server Port: 80 Document Path: /tech_blog/ Document Length: 36056 bytes Concurrency Level: 100 Time taken for tests: 20.823 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 3626300 bytes HTML transferred: 3605600 bytes Requests per second: 4.80 [#/sec] (mean) Time per request: 20823.375 [ms] (mean) Time per request: 208.234 [ms] (mean, across all concurrent requests) Transfer rate: 170.06 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 22 35 10.9 34 55 Processing: 1738 12723 5792.8 13427 20778 Waiting: 1569 11915 5760.4 12425 20519 Total: 1760 12758 5794.9 13478 20819 Percentage of the requests served within a certain time (ms) 50% 13478 66% 15866 75% 18171 80% 19324 90% 20374 95% 20773 98% 20790 99% 20819 100% 20819 (longest request)
after
[root@tsukaby ~]# ab -c 100 -n 100 https://tech-blog.tsukaby.com/ 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 tsukaby.com (be patient).....done Server Software: nginx/1.4.4 Server Hostname: tsukaby.com Server Port: 80 Document Path: /tech_blog/ Document Length: 36371 bytes Concurrency Level: 100 Time taken for tests: 1.317 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 3660600 bytes HTML transferred: 3637100 bytes Requests per second: 75.93 [#/sec] (mean) Time per request: 1317.039 [ms] (mean) Time per request: 13.170 [ms] (mean, across all concurrent requests) Transfer rate: 2714.27 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 22 36 11.4 35 58 Processing: 122 377 182.7 306 1286 Waiting: 19 172 143.9 90 392 Total: 145 413 181.1 345 1315 Percentage of the requests served within a certain time (ms) 50% 345 66% 486 75% 507 80% 518 90% 537 95% 755 98% 1288 99% 1315 100% 1315 (longest request)
初回のabコマンドはキャッシュがないので時間がかかりますが、2回目からのabコマンドは上記のようにすぐに終わります。before、つまり適当に設定したApacheではRequests per second: 4.80 [#/sec] (mean)というように秒間約5リクエストを捌けています。after、つまりキャッシュありのnginxではRequests per second: 75.93 [#/sec] (mean)というように秒間75リクエストを捌けています。
15倍高速化できました。実際Wordpressにアクセスすると早くなったことが体感できました。GoogleのPageSpeed Insightsでもサーバのレスポンスが遅いよ!という指摘が無くなりました。Pingdom Website Speed Testでも以前より早くなったせいか、Your website is faster than 73% of all tested websitesと出るように。前は50%くらいでした。
そんな訳でnginxかなり満足できる結果になりました。Apacheの方が情報量は多いので、自分のようなアマチュア鯖管にはnginxは優しくありませんが、何と言っても早いです。みなさんもぜひお試しあれ。