Thursday, September 13, 2007

CakePHP Performance Tuning

Use JMeter, I created a load test with 5 simultaneous users hitting our login, home and logout pages. Each user had between 1 to 2 seconds delay between each step during the load test. This yelled a 3.5 request/second throughput on the server.
Before the basic performance tuning, our server response time for the home page is about 2,600ms per request. We did following tuning and reduce the page response time to 9ms.
1. Enable APC -- Alternative PHP Cache caches opcode and reduce interpreter workload during runtime. This reduce the response time by 10%.
2. Enable CakePHP cache -- CackePHP can cache a controller's result, so when a controller is requested, the view will directly render the result instead of going to the database. We simply enabled the view without make any changes to the code. This actually eliminated all the table describe code. Again, this step yelled 10% performance gain.
3. html->link function -- This is the most interesting part of this performance tuning. K.S. wrote an awesome code to profile CakePHP code. He found out that each html->link functions takes 50 to 100ms to return. When we render many links on a page, the time would add up. Instead of using fancy CakePHP link function, we just write plain HTML code for links. This gave us almost 50% performance gain.


DragonI said...


Is the $html->link issue with version 1.1 or 1.2?

I'm using 1.2 ;)


CodeSith said...

We found the problem in cake_1.2.0.4798alpha.

DragonI said...

Huh, that sucks!!!

Has this issue been reported?

Thanks again for bring this to light. I guest I better start converting my code.

gwilym said...

Hi there - any chance you can shed some light on what the $html->link was slowing things down (and if it still does) and also any other Cake speed tips you have? Your post is dang useful :-)

CodeSith said...

We haven't yet updated to the latest version of cake. However, from what I can read in cake's source code repository, I don't think the problem is addressed yet. The link helper or image helper is useful if you want to have certain level of abstraction of how you map you code. In our case, we use apache mod_rewrite to achieve the same result.

Nick said...

I know it's probably pretty obvious that this would have been looked at by now, but I thought I'd just comment to say that in my tests (Cake 1.2.5), the HtmlHelper::link() function takes about 1ms per call.