最新のWordPressは、従来のバージョンから大幅な処理速度の高速化が行われています
WordPress の5.2.xはWordPressの4.xに比べて、新規セッション作成を従来比の2.4倍で処理が出来ます。
なお、WordPressの5.2.xはphpの5.6.x もしくはphp 7.xが必要です。
さらに Permalinkの変更が不要なプラグインキャッシュ Simple Cache の導入により、従来比で200倍までの高速化が出来ました。
高速化の3ステップ
- phpのバージョンアップ
- WordPressのバージョンアップ
- キャッシュの導入
WordPress & php 処理速度向上の要因は
- WordPress本体の高速化(4.x –> 5.2)
- phpの高速化(5.2 –> 7.2)
- apcからapcuへの変更(デフォルト)
などに起因します。ここまでの変更で、2.4倍の処理速度が向上します。
キャッシュ
- Simple cache の導入で200倍
の処理速度が向上しました。
WordPressのアップデートの手順
php 7.2へアップデート
WordPressを5.2.xへアップデート
です。php 7.2ではデフォルトでapcuを使用します。
ベンチマーク
同一のWordPressのページへアクセス時のベンチマークです
ハードウエアスペック
memory 2GB / Core x 1 Intel(R) Xeon(R) CPU E3-1230 v6 @ 3.50GHz
Apache Bench ベンチマーク結果-1 (基準)
OS CentOS 7.x / WordPress 4.8.3 / php 5.4.16 /apach 2.4.6 / apc (php-info)
結果 新規 16.66 #/sec
# ab -n 100 -c 10 https://www.xxx.com/blog
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.xxx.com (be patient)…..done
Server Software: Apache
Server Hostname: www.xxx.com/blog
Server Port: 443
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES256-GCM-SHA384,2048,256
Document Path: /blog/
Document Length: 20598 bytes
Concurrency Level: 10
Time taken for tests: 6.001 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 2089000 bytes
HTML transferred: 2059800 bytes
Requests per second: 16.66 #/sec
Time per request: 600.088 ms
Time per request: 60.009 [ms] (mean, across all concurrent requests)
Transfer rate: 339.96 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 2 3 4.3 2 16
Processing: 88 585 67.5 589 822
Waiting: 48 470 58.8 471 710
Total: 90 589 67.1 593 824
Percentage of the requests served within a certain time (ms)
50% 593
66% 601
75% 613
80% 621
90% 633
95% 647
98% 703
99% 824
100% 824 (longest request)
Apache Bench ベンチマーク結果-2 (WordPress 5.2.x / php 7.2 へのバージョンアップ)
OS CentOS 7.x / WordPress 5.2.2 / php 7.2.10 /apach 2.4.6 / apcu (php-info)
結果 新規 39.67 #/sec
# ab -n 100 -c 10 https://www.xxx.com/blog/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.xxx.com (be patient)…..done
Server Software: Apache
Server Hostname: www.xxx.com
Server Port: 443
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES256-GCM-SHA384,2048,256
Document Path: /blog/
Document Length: 20874 bytes
Concurrency Level: 10
Time taken for tests: 2.521 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 2119200 bytes
HTML transferred: 2087400 bytes
Requests per second: 39.67 #/sec
Time per request: 252.104 ms
Time per request: 25.210 [ms] (mean, across all concurrent requests)
Transfer rate: 820.91 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 2 3 4.5 2 17
Processing: 50 244 22.1 248 263
Waiting: 20 181 20.2 180 230
Total: 52 247 22.4 251 271
Percentage of the requests served within a certain time (ms)
50% 251
66% 253
75% 254
80% 255
90% 260
95% 263
98% 268
99% 271
100% 271 (longest request)
今回のケースではWordPressとphpをバージョンアップするだけで、簡単にWordPressの新規セッション(16.66回/秒から39.67回/秒へ)2.4倍のスピードアップが出来ました。
新規に利用の場合には、WordPress 5.2 を利用した方が良さそうです。既存でWordPressの古いバージョンをご利用の場合には、最新版へアップデートするとパフォーマンスの向上が期待できます。
また、phpをバージョンアップ出来ない場合にはWordPressのみを 5.1.x(php は5.4.xのまま)へアップすることでも処理速度の向上が望めます。
キャッシュの導入
WordPressでよく使われているCacheとしては、動的ページを静的ページに生成してくれる
- W3 Total Cache
- WP Super Cache
- WP Fastest Cache
- Cache Enabler
などがあります。どの製品も高機能で良さそうですが
導入時に .htaccess を書き換えたり、permalinkがデフォルト設定では導入&運用出来ない事などがあります。
.htaccessを書き換えるとサーバーによっては、Webサイトを表示出来なくなることがあります。
permalinkについては
基本設定/デフォルト http://www.xxx.com/blog/?p=123
基本設定以外を選択すれば導入が可能です。新規での導入の場合には、基本以外を選択で問題がありません。既存で運用のWordPressのPermalinkを変更すると、投稿やリンクの名称が変更になるので安易には変更が出来ません。(変更をすると、既存の投稿やリンク先へアクセス出来なくなります)
Cacheの選定
「.htaccess を変更しない」 および 「permalink をデフォルトの設定で運用」出来るWordPress のプラグイン Cacheとしては、Simple Cache が使えます。また「.htaccessは変更される」が「permalinkはデフォルトの設定で運用」出来るプラグインとしては、Breezeが使えます。
Simple Cache は導入も簡単
導入時に define ( “WP_CACHE”,True) がwp-config.phpに設定されていない場合には
Attempt Fix ボタンを押すと、wp-config.php を自動で修正してくれます
Simple Cacheの設定パラメータは4か所のみ
- Enable Caching キャッシュを有効にする/ Yes
- キャッシュの有効時間 例 24時間
- 圧縮の適用 Yes or No(適宜選択)
- アドバンストモード Yes or No (適宜選択)
Cache データの確認
外部からWordPressへアクセスするとアクセス先のWebページのデータがキャッシュされます。キャッシュされるのは、WordPressの動的なページを静的なhtmlなファイルとしてキャッシュします。(WordPressの編集画面経由でのアクセスではキャッシュされません)
例 以下のWordPress先にアクセス
- https://www.xxx.com/blog/?m=201504&paged=5
- https://www.xxx.com/blog/?p=2974
- https://www.xxx.com/blog/?p=2989
- https://www.xxx.com/blog/
[root@bulldog-3]# pwd
/wp-content/cache/simple-cache/www.xxx.com/blog <– キャッシュデータの保存先
[root@bulldog-3]# ls
?m=201504&paged=5 ?p=2974 ?p=2989 index.html <– データがキャッシュ
[root@bulldog-3]#
Apache Bench ベンチマーク結果-3 (Simple Cache 利用時)
OS CentOS 7.x / WordPress 5.2.2 / php 7.2.10 /apach 2.4.6 / apcu (php-info)
Simple Cache
結果 新規 360.06 #/sec
[root@bulldog pb-blog2]# ab -n 100 -c 10 https://www.xxx.com/blog/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.xxx.com (be patient)…..done
Server Software: Apache
Server Hostname: www.xxx.com
Server Port: 443
SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES256-GCM-SHA384,2048,256
Document Path: /blog/
Document Length: 23775 bytes
Concurrency Level: 10
Time taken for tests: 0.278 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 2402600 bytes
HTML transferred: 2377500 bytes
Requests per second: 360.06 [#/sec] (mean)
Time per request: 27.774 [ms] (mean)
Time per request: 2.777 [ms] (mean, across all concurrent requests)
Transfer rate: 8447.94 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 3 18 1.6 18 19
Processing: 2 10 1.1 9 12
Waiting: 1 9 1.1 9 11
Total: 5 27 2.5 27 30
Percentage of the requests served within a certain time (ms)
50% 27
66% 27
75% 28
80% 28
90% 30
95% 30
98% 30
99% 30
100% 30 (longest request)
最後に
WordPress を5.2.x / php を 7.x / Cache の導入で、従来比で (16.66–>360.06 #/sec) 200倍までの高速化が出来ました。
さらなる高速化に際しては
- 画像データの最適化
- 画像の遅延表示
- htmlの圧縮
- phpの圧縮‘
- dbのキャッシュ
- 1ページに表示させる量を適切に調整する
などで対応が可能です。