今回、新しいWordPressのサイトを立ち上げ、一通りのコンテンツを用意し、速度改善系以外の必要なWordPressプラグインを導入しました。
すると案の定、サイトの表示速度は遅い状態でしたので、予定通り「WP Super Cache」を導入する事にしました。
なお、今回「WP Super Cache」を導入する前後で、apache bench を用いて表示速度の計測を行いましたので、その結果を交えて紹介します。
結果は表題のとおり、キャッシュ効果により17倍もの速度向上となっています。
1.「WP Super Cache」導入前の apache bench 測定結果
ab の測定オプションは「-n 100」、「-c 10」で行いました。同時アクセス数が10で100リクエストを発行、という内容です。
(本投稿の最後のほうに、WP Super Cache 導入前後の比較表を記載しています。)
# /usr/local/apache2/bin/ab -n 100 -c 10 http://(調査対象サイトのFQDN)/ This is ApacheBench, (中略) (中略) Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking (調査対象サイトのFQDN) (be patient).....done Server Software: Apache/2.*.* Server Hostname: (調査対象サイトのFQDN) Server Port: 80 Document Path: / Document Length: 30316 bytes Concurrency Level: 10 Time taken for tests: 165.793 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 3072600 bytes HTML transferred: 3031600 bytes Requests per second: 0.60 [#/sec] (mean) Time per request: 16579.298 [ms] (mean) Time per request: 1657.930 [ms] (mean, across all concurrent requests) Transfer rate: 18.10 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.2 0 1 Processing: 455 15462 13615.2 12884 47061 Waiting: 336 15091 13513.5 12636 46408 Total: 455 15462 13615.2 12884 47061 Percentage of the requests served within a certain time (ms) 50% 12884 66% 24783 75% 27245 80% 28091 90% 33501 95% 41392 98% 43905 99% 47061 100% 47061 (longest request) #
注目した点は、赤色太字にしてあります。
かなり遅いです。
2.WP Super Cache の導入
WP Super Cache 1.2 を導入しました。
導入手順はサマリーですが以下になります。
# cd /usr/local/src # wget http://downloads.wordpress.org/plugin/wp-super-cache.1.2.zip # unzip wp-super-cache.1.2.zip # mv wp-super-cache /(WordPress導入ディレクトリ)/wp-content/plugins/ (WordPressプラグイン画面で WP Super Cache を有効化) # chmod 777 /(WordPress導入ディレクトリ)/wp-content (←パーミッションを一時的に変更) # vi /(WordPress導入ディレクトリ)/wp-config.php (←WP_CACHE設定を追加) # chmod 777 /(WordPress導入ディレクトリ)/wp-config.php (←パーミッションを一時的に変更) (WordPressの WP Super Cache 設定画面を再読み込み) # vi /(WordPress導入ディレクトリ)/wp-config.php (←WPCACHEHOMEが WP-Cache Manager によって自動追記された事を確認) # chmod 644 /(WordPress導入ディレクトリ)/wp-config.php # chmod 755 /(WordPress導入ディレクトリ)/wp-content
あとは、WP Super Cache 設定画面で必要な設定を行います。
その後、apache bench での測定対象URLのキャッシュを取得しておく為、ブラウザで表示しておきます。
3.「WP Super Cache」導入後の apache bench 測定結果
WP Super Cache の導入が終わったので、あらためて ab で測定します。ab のオプション条件は同じものを使います。
(本投稿の最後のほうに、WP Super Cache 導入前後の比較表を記載しています。)
# /usr/local/apache2/bin/ab -n 100 -c 10 http://(調査対象サイトのFQDN)/ This is ApacheBench, (中略) (中略) Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking (調査対象サイトのFQDN) (be patient).....done Server Software: Apache/2.*.* Server Hostname: (調査対象サイトのFQDN) Server Port: 80 Document Path: / Document Length: 30474 bytes Concurrency Level: 10 Time taken for tests: 9.653 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 3081700 bytes HTML transferred: 3047400 bytes Requests per second: 10.36 [#/sec] (mean) Time per request: 965.330 [ms] (mean) Time per request: 96.533 [ms] (mean, across all concurrent requests) Transfer rate: 311.76 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.2 0 1 Processing: 13 781 1065.6 125 3295 Waiting: 12 776 1061.3 124 3286 Total: 13 781 1065.7 125 3295 Percentage of the requests served within a certain time (ms) 50% 125 66% 809 75% 1404 80% 1894 90% 2865 95% 3099 98% 3197 99% 3295 100% 3295 (longest request) #
注目した点は、赤色太字にしてあります。
キャッシュを用いている為、かなり速くなりました。
以下、分かりやすいように比較表にしています。
測定項目 | WP Super Cache 導入前 | WP Super Cache 導入後 |
Time taken for tests | 165.793 seconds | 9.653 seconds |
Requests per second | 0.60 [#/sec] | 10.36 [#/sec] |
Transfer rate | 18.10 [Kbytes/sec] | 311.76 [Kbytes/sec] received |
Connection Times (ms) max | 47061 | 3295 |
キャッシュの導入効果が明らかに出ています。
WP Super Cache 導入前の「Time taken for tests」の値「165.793 seconds」を、WP Super Cache 導入後の値「9.653 seconds」で割ると、17倍以上のキャッシュ効果となっています。
備考
速度は速くなりましたが、キャッシュ系の技術を用いる場合は、デメリットやリスクについてしっかりと把握した上で導入する必要があります。キャッシュ特有の事象や、プラグイン特有の事象があり、考慮しないまま使っていると後で大問題になる可能性もあります。導入を検討する際は良く考慮の上で導入すると良いと思います。