APC (Alternative PHP Cache) で WordPress を高速化できるらしい。PHP コンテンツならなんでも効果が見込めると思う。
ビフォー性能測定
まずは APC が入っていない状態で ab をかけてみる。
$ ab -n 100 -c 5 http://pooh.gr.jp/ : Server Software: Apache Server Hostname: pooh.gr.jp Server Port: 80 Document Path: / Document Length: 23768 bytes Concurrency Level: 5 Time taken for tests: 18.102739 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 2396400 bytes HTML transferred: 2376800 bytes Requests per second: 5.52 [#/sec] (mean) Time per request: 905.137 [ms] (mean) Time per request: 181.027 [ms] (mean, across all concurrent requests) Transfer rate: 129.26 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 7 16 15.0 12 121 Processing: 356 877 388.6 817 3424 Waiting: 284 715 331.5 653 2608 Total: 365 894 389.5 834 3432 Percentage of the requests served within a certain time (ms) 50% 834 66% 948 75% 1020 80% 1050 90% 1287 95% 1468 98% 2137 99% 3432 100% 3432 (longest request)
APC をインストール
まずは php-pear をインストールして pecl を使えるようにする。
$ sudo yum -y install php-pear
APC をインストール … しようとするも iptables のせいでウェブサーバーに接続できなくて失敗。
$ pecl install apc No releases available for package "pecl.php.net/apc" Cannot initialize 'apc', invalid or missing package file Package "apc" is not valid install failed $ host pecl.php.net pecl.php.net is an alias for pair12.php.net. pair12.php.net has address 76.75.200.106 $ sudo /sbin/iptables -I OUTPUT -d 76.75.200.106 -j ACCEPT
APC をインストール … しようとするも root 権限がなくて失敗。
$ pecl install apc downloading APC-3.0.19.tgz ... Starting to download APC-3.0.19.tgz (115,735 bytes) ................done: 115,735 bytes ERROR: failed to mkdir /usr/share/pear/test/APC/tests
APC をインストール … しようとするも apxs (httpd-devel) がなくて失敗。
$ sudo pecl install apc downloading APC-3.0.19.tgz ... Starting to download APC-3.0.19.tgz (115,735 bytes) .........................done: 115,735 bytes 47 source files, building : checking whether apc needs to get compiler flags from apxs... Sorry, I was not able to successfully run APXS. Possible reasons: 1. Perl is not installed; 2. Apache was not compiled with DSO support (--enable-module=so); 3. 'apxs' is not in your path. Try to use --with-apxs=/path/to/apxs The output of apxs follows /tmp/tmpX2Ky3j/APC-3.0.19/configure: line 3232: apxs: command not found configure: error: Aborting ERROR: `/tmp/tmpX2Ky3j/APC-3.0.19/configure --with-apxs' failed $ sudo yum -y install httpd-devel
APC をインストール … 成功例。
$ sudo pecl install apc : install ok: channel://pecl.php.net/APC-3.0.19 You should add "extension=apc.so" to php.ini
php 設定で APC モジュールを有効化。
$ sudo bash -c "echo \"extension=apc.so\" > /etc/php.d/apc.ini"
httpd 再起動。
$ sudo /sbin/service httpd graceful
アフター性能測定
もう一度測ってみる。
$ ab -n 100 -c 5 http://pooh.gr.jp/ : Server Software: Apache Server Hostname: pooh.gr.jp Server Port: 80 Document Path: / Document Length: 23768 bytes Concurrency Level: 5 Time taken for tests: 10.387544 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 2396400 bytes HTML transferred: 2376800 bytes Requests per second: 9.63 [#/sec] (mean) Time per request: 519.377 [ms] (mean) Time per request: 103.875 [ms] (mean, across all concurrent requests) Transfer rate: 225.27 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 7 16 10.8 11 84 Processing: 260 497 184.4 459 1452 Waiting: 179 357 142.3 318 1049 Total: 270 513 183.1 476 1461 Percentage of the requests served within a certain time (ms) 50% 476 66% 533 75% 596 80% 610 90% 699 95% 872 98% 1273 99% 1461 100% 1461 (longest request)
結果
性能が 2 倍くらいになった気がする。テスト時間 (Time taken for tests) が 18.102739 seconds から 10.387544 seconds に。43% 減。1 秒あたりの処理数 (Requests per second) が 5.52/sec から 9.63/sec に。74% 増。