I firmly believe this topic will attract some people, as it should examine Yii performance capabilities.
We all know, it is very hard to keep benchmark results near to numbers shown in performance chart, but we can do our best to achieve maximum performance without aggressively caching every function return value.
I made quite an impressive progress in my website development, so I was able to measure a couple of things.
-
Apache 2.2.11
-
PHP 5.3.0 TS, VC6
-
MySQL 5.1.36
-
2 Gb ram
-
Intel Dual-Core 1.86 Ghz
-
Windows 7 x64 (psst!)
-
Latest wampserver (2.0i)
-
Caching & APC disabled
I always measured real usage. Please see the corresponding manual page to see what that means.
My findings were:
-
Because PHP was not in CGI mode by default, approximately 0.5 Mb memory consumption showed up in the very beginning of each request. This may change due to enabled php extensions (I have xdebug for example). I substracted its value from the final result.
-
I configured my urlManager to have 27 url rules so far. According to the guide this can cause performance loss when lots and lots of urls are auto-generated. This, at least in theory, only increases the time spent to generate output, and basically doesn’t have effect on memory usage. Apart from this, I don’t have many components (db, dummy cache, 3 log routes, session).
-
Instead of onBeginRequest, I used beginProfile at the top of my config file. This might better represent the data we want to examine, because it covers more script. However, I was not able to put endProfile beyond onEndRequest without extending base classes.
-
Db-less pageviews normally render within 65ms - 90ms. Others need 100ms - 300ms.
-
Memory usage vary upon action complexity and classes involved. Peak usage measured at onEndRequest is very near (or equal in many cases) to current usage at onEndRequest. This probably means that Yii does not free up unnecessary class instances. After all, it’s a job of onEndRequest (or ultimately PHP’s garbage collector), but I’m quite sure there are ways to lower memory consumption.
-
Overall memory needed to perform each request was between 3,6-5,5 Mb in my case, which sounds reasonable.
-
I also ran some ab tests, my front page performed between 9-13 requests/second, which is a bit worrying.
Apart from the tips in the guide, I look for Yii-specific advices to reach the speed of the light.
In this attempt, I’d also love to hear your opinions. Not only numbers and benchmark results, but ideas to keep Yii in its best condition.
If this is possible, I would also like to measure the core performance and remove all bottlenecks before the next major version gets released.