Tuesday, June 5, 2012

Optimize cakephp 1.3 for models with containable

Hello!

I have a little problem with long execution time request...  I have a few models:

Building - (in database arround 16 records)
Apartament (in database arround 1600 records)
Person -(in database arround 1700 records)
Representative (in database arround 200 records),
Address (in database arround 1700 records),

and relationship between models:

Building has many Apartament,
Apartament has many and belongs to many Person,
Person has many and belongs to many Apartament,
Person belongs to Address,
Person belongs to Repesentative

all models use cointanable behavior and set recursive to -1, cache queires true,


in one action of some controller I want to retrieve data like this:


    $this->Building->contain(array(
                                                    'Apartament'=>array(
                                                    'order' => array('Apartament.number + 0'=> 'asc', 'Apartament.number'=> 'desc'),
                                                    'Person' => array(
                                                        'Corespondency',
                                                        'Representative',
                                                        'PersonApartament',
                                                        'conditions' =>array('Person.member_id >' => '1',)
                                                    ),    
                                                  
                                           ),
                                       
                                        ));

$buildings = $this->Building->find('all');

and that request execution time is 70 seconds... mysql don't report long queries (set to 1s), cakephp debug back a few queries and all in a few ms... 
but when I retrieving data like this:


$this->data['Document']['Buildings'] is selected buildings ids...


         $buildings = array();    
         foreach($this->data['Document']['Buildings'] as $id){    
             $this->Building->contain(array(
                                                    'Apartament'=>array(
                                                    'order' => array('Apartament.number + 0'=> 'asc', 'Apartament.number'=> 'desc'),
                                                    'Person' => array(
                                                        'Corespondency',
                                                        'Representative',
                                                        'PersonApartament',
                                                        'conditions' =>array('Person.member_id >' => '1',),
                                                    ),    
                                                  
                                           ),
                                       
                                        ));
         
             $buildings[]=$this->Building->findById($id);
         }

request execution time is <7s... in this case find data at once is smaller... but when database records grows, request execution time too...

Maybe there is another way to optimize my app or database relationship?


my server is:
i2500k, 16GB, apache+fcgid php 5.3.8, xcache, memcache for cakephp
 
  

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: