私は、WordPress をどうしたら速く表示することが出来るか常に考えています。VPS広場は、Nginx + PHP-FPM + MySQLの構成で動いているのですが、WordPressは大量のPHPで書かれている為、PHPの処理がボトルネックになっています。少しでも速くしたければ、Nginxのキャッシュを使えば簡単で最速の表示ができますが…。
前もって言っておきますが、、、
PHPやMySQLをどんなにチューニングしても、Nginxのキャッシュには絶対に勝てません。
でも、それでは面白くもないし、この程度のサイトでNginxのキャッシュに頼りたくもありません。
じゃ、どうすれば速くできるか。
今回は、PHPの処理をPHP-FPM から HHVM(HipHopVM) に変えて実験をしてみることにしました。早速、テストしてみました。
仮想マシンを3台用意して実験です。(スペック:CPU3個、メモリ2GB)
サーバーA Nginx1.6 + HHVM3.0 + MySQL5.6
サーバーB Nginx1.6 + PHP-FPM + APC + MySQL5.6
サーバーC Nginx1.6(キャッシュ)
※ MySQLは実機並みにチューニング済み。Nginxは当サイトで紹介した設定。HHVMとPHP-FPMはデフォルト設定。WordPressもインストールした状態でプラグインは一切入れていません。
WordPressのトップページを表示した結果
サーバーA(HHVM)

サーバーB(PHP-FPM + APC)

サーバーC(Nginxのキャッシュ)

]
WordPressが素の状態なのであまり参考になりませんが、Nginxのキャッシュには及びませんが、HHVMはかなり速いですね。
WordPressのダッシュボードを表示した結果
サーバーA(HHVM)

サーバーB(PHP-FPM + APC)

ダッシュボードの操作も倍近く速くなりました。管理画面の操作すべてにおいて速くなっています。メディアのアップロードも問題ありませんし、プラグインも問題なくインストール&有効化出来ました。
Apache Benchの結果
サーバーB → サーバーA(HHVM)
ab -c 100 -n 1000 http://サーバーA/
Server Software: nginx
Server Hostname: サーバーA
Server Port: 80
Document Path: /
Document Length: 7970 bytes
Concurrency Level: 100
Time taken for tests: 8.727 seconds
Complete requests: 1000
Failed requests: 414
(Connect: 0, Receive: 0, Length: 414, Exceptions: 0)
Write errors: 0
Non-2xx responses: 414
Total transferred: 5102592 bytes
HTML transferred: 4892738 bytes
Requests per second: 114.59 [#/sec] (mean)
Time per request: 872.687 [ms] (mean)
Time per request: 8.727 [ms] (mean, across all concurrent requests)
Transfer rate: 571.00 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 1.9 1 9
Processing: 1 827 688.4 1143 2281
Waiting: 1 813 676.8 1127 2098
Total: 1 828 688.8 1144 2290
サーバーA → サーバーB(PHP-FPM + APC)
ab -c 100 -n 1000 http://サーバーB/
Server Software: nginx
Server Hostname: サーバーB
Server Port: 80
Document Path: /
Document Length: 7974 bytes
Concurrency Level: 100
Time taken for tests: 32.167 seconds
Complete requests: 1000
Failed requests: 2
(Connect: 0, Receive: 0, Length: 2, Exceptions: 0)
Write errors: 0
Non-2xx responses: 2
Total transferred: 8196026 bytes
HTML transferred: 7959126 bytes
Requests per second: 31.09 [#/sec] (mean)
Time per request: 3216.738 [ms] (mean)
Time per request: 32.167 [ms] (mean, across all concurrent requests)
Transfer rate: 248.82 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 12 94.4 1 1000
Processing: 1 3053 574.0 3187 3543
Waiting: 1 3053 574.0 3187 3543
Total: 2 3065 577.6 3190 4222
サーバーA → サーバーC(Nginxのキャッシュ)
ab -c 100 -n 1000 http://サーバーC/
Server Software: nginx
Server Hostname: サーバーC
Server Port: 80
Document Path: /
Document Length: 7974 bytes
Concurrency Level: 100
Time taken for tests: 0.658 seconds
Complete requests: 1000
Failed requests: 40
(Connect: 0, Receive: 0, Length: 40, Exceptions: 0)
Write errors: 0
Non-2xx responses: 40
Total transferred: 7911520 bytes
HTML transferred: 7676520 bytes
Requests per second: 1520.82 [#/sec] (mean)
Time per request: 65.754 [ms] (mean)
Time per request: 0.658 [ms] (mean, across all concurrent requests)
Transfer rate: 11749.98 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 17 8.5 20 33
Processing: 7 47 15.6 44 95
Waiting: 3 31 17.6 27 74
Total: 20 64 14.3 64 118
- 1秒間辺りに処理が出来る回数
- サーバーA 114.59 [#/sec] (mean)
- サーバーB 31.09 [#/sec] (mean)
- サーバーC 1520.82 [#/sec] (mean)
HHVMの感想
PHP-FPMに比べて、HHVMは2~3倍速くなる結果となりました。HHVMの結果は悪くないですが、WordPress以外でも動くことが実証されてから導入を検討しても良いかもしれませんね。
