CakePHP and data sets.

Today I was charged with rolling out new features to one of our sweepstakes systems that we have in house. It is a very simple application, built on the CakePHP framework and has performed wonderfully today. While rolling out the application I noticed that on one particular sweepstakes the loading time was less than spectacular. Looked at the error logs for Apache and noticed that the page load was running out of memory. I increased the memory allocation to sixty four megabytes and the page load was barely skating bye...

Digging a little bit deeper I thought about the relationships that Cake is building. Apparently in the model it was trying to associate all the entries of the sweepstakes on page load for any of the actions that a sweepstakes could do. This could range from 1700 entries to 10000 based on the sweepstakes in the system. To alleviate the stress on the server you can limit the data that is called in the actions of your objects. By default the recursive level is set to 1 (please see http://book.cakephp.org/view/439/recursive for more details).

Simply do:

$this->Model->recursive = -1;

And it will only grab the data of the object that you are currently working with. Unnecessary collection of data not relevant to your page view will slow down your app immensely.


0 Responses to CakePHP and data sets.

  1. There are currently no comments.

Leave a Reply



About

User