2010年6月20日 星期日

PHP MVC Framework Performance – Part 1

As part of my assessment of PHP MVC Frameworks which I blogged about in Choosing the best PHP MVC Framework I decided to do a compare performance of the various PHP MVC Frameworks I was considering. I did this using Apache Bench with ab -t 30 -c 10 http://testserver/framework/index.php as this is common and did the basic Hello World test where each framework just put out Hello World in an empty HTML document. Here are the results…

The test server was a Windows XP machine with T7200 2.00GHz CPU and 2GB RAM running WAMP with PHP 5.2.6, Apache 2.2.8. No opcache was used in this test altough that’s something I will probably use for another test.

The latest version of every framework was used and all features like DB access were disabled for the test to give a true comparison.

All tests were run 5 times and any results there weren’t around the average of other results were removed and the test run was repeated, to avoid skewing results.

It’s pretty pointless to provide figures in requests per second as every machine is different and everyone will hence get different results, but it makes a lot of sense to compare all frameworks against a common base. For that base I chose to use performance of raw PHP, which on my test machine did an average of 740 req/s. A test with a HTML test on the same machine did 850 req/s (so not a huge difference). I should also note that the exact file being requested was always used (e.g. index.php or index.html), as just referencing the directory further decreased performance because Apache had to work out which file to show for the directory index.

Here are the results:

Raw PHP - 740 req/sec – 100%
PHP Pro MVC 0.0.4 - 200 req/sec – 27%
DooPHP 1.2 – 170 req/sec – 23%
Yii Framework 1.1.1 – 130 req/sec – 18%
Kohana PHP 2.3.4 – 55 req/sec – 7.5%
CodeIgniter 1.7.2 – 38 req/sec – 5%
Zend Framework 1.10 – 24 req/sec – 3%
So what does this all mean, let’s analyse the results…

Firstly PHP Pro MVC is a minimalistic MVC framwork written as an example of how to write an MVC framework and is used by OpenCart (with some modifications). I used it in the comparison to get an understanding how how any sort of even a basic PHP framework would impact performance.

As claimed on their website DooPHP is indeed the fastest of the frameworks, but it’s nowhere near as fast as they claim to be as compared to other frameworks. I also wouldn’t recommend using it because it’s not very logically structured compared to some others. Speed isn’t everything.

Yii is also indeed quite fast and to my surprise was significantly faster than Kohana or Code Igniter! However I tested v1.1.1 and Yii Framework Performance Bencharks were done on version 1.0.2. As I’ve said before I quite like Yii Framework because it just feels natural and logical.

Kohana was a bit faster than Code Igniter but in the same ballpark. As I’ve also pointed out I think that Yii is better than Kohana because code completion in PHP IDEs doesn’t work with Kohana and that’s a major issue.

Code Igniter was a bit slower than I would have hoped it would be, but that’s understandable because of all the interoperability code that doesn’t really need to be there if you’re using PHP5 only. This is consistent with Kohana vs Code Igniter Perofmance results obtained by other people.

Zend Framework is the slowest of the lot, which is understandable given how heavy the framework is and how many files get loaded just to render a template from a controller. This is also something that’s been pointed out in tests by other people.

I didn’t bother testing Cake PHP or Symfony as it’s well know that they are even slower than Zend Framework.

Now, here’s something VERY IMPORTANT!

You can compare performance of frameworks on Hello World tests all you want, but in a real life situation the performance of your framework will be dwarfed into insignificance by the following 2 factors:

Database Access
File System Access
Database Access and File System Access are the two slowest operations there are so how quick the actual code runs matters very little. In fact, the reason why Zend is so much slower than others is because it splits the code between so many files and it’s not even the parsing that’s the biggest problem, but file access, as I was running without opcode caching. With opcode caching you can expect the performance to improve to a point where the performance difference between frameworks will be insignificant in comparison to database access operations.

So, based on all of this my recommendation are as follows:

Choose the framework that best suits your needs and don’t worry so much about raw performance (unless the framework is split between many many files and you’re not using opcode caching, in which case file system access becomes a limiting factor). You should consider other factors when about the PHP Framework as I’ve outlined in Choosing the best PHP MVC Framework.
Try to use opcode caching wherever possible to avoid file system access becoming a limiting factor.
Make sure you optimise your database performance (read queries and indexes) and try to minimise the number of database accesses (especially in loops) by using joins and retrieving multiple rows with a single query. This one thing will dwarf any difference you may see in PHP MVC Framework performance!

摘自:http://www.sheldmandu.com/php/php-mvc-frameworks/php-mvc-framework-performance-part-1

2 則留言:

Unknown 提到...

Are you using any op code cache like APC, Xcache or Eaccelerator with PHP? It makes a huge difference and it is more practical to benchmark with the use of opcode cache. Without it PHP sucks in performance.

Ryoko 提到...

I usually use PHP Eaccelerator,
without PHP Eaccelerator,the performance is really bad~

wibiya widget