本 Blog に PHP のキャッシングモジュール XCache を導入しました。

eAccelerator とどちらにするか迷いましたが、Gentoo Linux の Portage では、eAccelerator も、APC (dev-php5/pecl-apc) も軒並み Masked! 。

あまりがんばりたくもなかったので唯一(?) stable 扱いになっている XCache を利用することにしました。LIGHTTPD プロジェクトの1つというのも素敵ですね。(LIGHTTPD も好きなんだけど今イチ使いどころが無くて今はどのマシンでも稼働させてないなあ。)

インストールはとっても簡単
# emerge xcache
これだけで現在インストールされている Apache の設定にあわせた形で XCache をインストールしてくれます。さすがGentoo、すばらしいですね。

その後、
/etc/php/apache2-php5/ext/xcache.ini
内の設定を一部変えて、
/etc/php/apache2-php5/ext-active/xcache.ini
が、
/etc/php/apache2-php5/ext/xcache.ini
へのシンボリックリンクになっていることを確認して、 Apache をリスタートすればOK 。

それでは、実際にベンチマークを取ってみた結果を。

導入の効果は劇的とまでは行きませんが(現状が遅すぎるので)、単純な AB によるベンチマーク結果でも、

before

Document Path: /
Document Length: 21885 bytes

Concurrency Level: 10
Time taken for tests: 270.102278 seconds
Complete requests: 1000
Failed requests: 36
(Connect: 0, Length: 36, Exceptions: 0)
Write errors: 0
Total transferred: 22011336 bytes
HTML transferred: 21782456 bytes
Requests per second: 3.70 [#/sec] (mean)
Time per request: 2701.023 [ms] (mean)
Time per request: 270.102 [ms] (mean, across all concurrent requests)
Transfer rate: 79.58 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 1
Processing: 253 2537 7116.4 961 96528
Waiting: 243 2076 6671.2 632 96520
Total: 253 2537 7116.4 961 96528

Percentage of the requests served within a certain time (ms)
50% 961
66% 1355
75% 1645
80% 1924
90% 3492
95% 8799
98% 27806
99% 37644
100% 96528 (longest request)

after

Document Path: /
Document Length: 21885 bytes

Concurrency Level: 10
Time taken for tests: 147.682768 seconds
Complete requests: 1000
Failed requests: 19
(Connect: 0, Length: 19, Exceptions: 0)
Write errors: 0
Total transferred: 22158247 bytes
HTML transferred: 21928789 bytes
Requests per second: 6.77 [#/sec] (mean)
Time per request: 1476.828 [ms] (mean)
Time per request: 147.683 [ms] (mean, across all concurrent requests)
Transfer rate: 146.52 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 1
Processing: 138 1465 3576.9 761 54050
Waiting: 134 1067 3010.8 498 41827
Total: 138 1465 3577.0 761 54050

Percentage of the requests served within a certain time (ms)
50% 761
66% 952
75% 1135
80% 1325
90% 2019
95% 3501
98% 12681
99% 17178
100% 54050 (longest request)

と、約2倍近くのパフォーマンスアップです。 改めてバイトコードキャッシングの威力を知る結果となりました。

参考までに同マシンで Typo(Rails) を fastCGI で動かしているサイトに負荷をかけてみると・・・

Document Path: /
Document Length: 6246 bytes

Concurrency Level: 10
Time taken for tests: 5.545925 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 6471000 bytes
HTML transferred: 6246000 bytes
Requests per second: 180.31 [#/sec] (mean)
Time per request: 55.459 [ms] (mean)
Time per request: 5.546 [ms] (mean, across all concurrent requests)
Transfer rate: 1139.40 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.5 0 8
Processing: 3 21 18.6 19 263
Waiting: 0 21 18.6 19 263
Total: 3 21 18.6 19 263

Percentage of the requests served within a certain time (ms)
50% 19
66% 23
75% 24
80% 27
90% 40
95% 44
98% 71
99% 103
100% 263 (longest request)

表示コンテンツに圧倒的な差がある(というか、Typo側は相当に贔屓な設定になっています)とはいえ、rps の桁がここまで違う結果になるとは・・・。やはり PHP は難しいなぁ。

Related posts:

  1. サイト復旧
  2. Blog ツールについて
  3. NotePC に開発環境構築