色々なPHPフレームワークのパフォーマンスを比較
注意点
環境
今回の環境は、下記のようになっており、MySQLにはpostsテーブルのみ25000レコードがある状態です。
Server: Dell SC440 Pentium Dual CPU E2180 @ 2.00GHz / 2G Memory / SATA HDD OS: Ubuntu11 64bit PHP 5.3.5 with APC3.1.9(shmを300Mにした以外は全てデフォルト設定) Apache 2.2.17 MySQL 5.1.54
postsテーブルのスキーマ
CREATE TABLE IF NOT EXISTS `posts` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `text` text, `created` datetime DEFAULT NULL, `modified` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
計測対象
この状態で、下記フレームワークを同一条件で比較しました。
Agavi 1.0.6 CakePHP 1.3.11 CakePHP 2.0-beta Codeigniter 2.0.2 Lithium 0.10 Pinoco 0.5.2(PHPTALテンプレート) Silex (Doctrine + Twig(キャッシュオプション有効)) Symfony 2.0 Yii 1.1.8 ZendFW 1.11.10
Seigeという計測ツールを使い下記のオプションのように、同時接続数10で3秒間に何アクセスさばけるかという計測を行いました。
siege -b -c 10 -t 3S http://localhost
ちなみに素のPHPで書いたコードで計測すると、
1170 trans/sec
という結果がでました。
結果(一覧表)
細かい結果はこちらのスプレッドシートにまとめています。
https://spreadsheets.google.com/spreadsheet/pub?hl=ja&hl=ja&key=0AlU1p67x75_UdEZ0TmstSHZMaFpBQXR4TkVUdHFoV0E&output=html
結果(スループット)
結果(function call数)
スループット以外に、XHProfというツールを使ってどれだけfunction callが発生したかも計測しました。基本的にはcall数が少ないほうが良いです。
ただ、Yiiはコール数は少ないですがデータ処理周りにボトルネックがありスループットがあまり出ないという結果が分かりました。
計測対象のアプリケーション
各フレームワークのソースコードは下記で公開しています。フレームワークごとに特徴があるのでそれらを比較してみるのも楽しいと思います。
Agavi 1.0.6 https://github.com/MugeSo/Agavi-PerformanceCheckSample
Cake1.3.11 https://github.com/ichikaway/CakePHP-PerformanceCheckSample/tree/master/cake1.3
Cake2.0.0-beta https://github.com/ichikaway/CakePHP-PerformanceCheckSample/tree/master/cake2
CI 2.0.2 https://github.com/ichikaway/Codeigniter2-PerformanceCheckSample
Lithium0.10 https://github.com/ichikaway/Lithium-PerformanceCheckSample
pinoco0.5.2 with phptal https://github.com/ichikaway/Yii_and_Pinoco-PerformanceCheckSample/tree/master/pinoco
Silex twig(with cache option) + doctrine https://github.com/brtriver/silex-sample-application/
Symfony2.0 https://github.com/ichikaway/Symfony2-PerformanceCheckSample
Yii 1.1.8 https://github.com/ichikaway/Yii_and_Pinoco-PerformanceCheckSample/tree/master/app
ZendFW https://github.com/strysd/performance
plain PHP https://github.com/ichikaway/CakePHP-PerformanceCheckSample/blob/master/php/view.php
貢献
最後に
今回はフェーズ1ということで、ある程度やりきれる形をとりました。今後は他のFWも含めて、もう少し複雑なアプリで評価していきたいと思います。
参考
@koriymさんの記事も参考になります。
PHP Hello Worldコールグラフ(2011)
@kenji_sさんがCIのARを使わないパターンで計測しています。
CodeIgniter と Pinoco をベンチーマークしてみた