Reputation: 2654
I am trying to pinpoint why apache some of my apache processes are using up nearly 250mb of memory. i have 4gb allocated to server and 4gb swap. halfway through the day it uses up swap space. i believe it is the php using up the memory. the following action i have found produces 96.5mb
public function actionView($id)
{
$model = $this->loadModel($id);
$client=null;
$obj =new GlobalController(); // preparing object
if(strlen($model->cache(CACHE_TIMEOUT)->oRDERNO->CONTACTID) < 6){
$client = Contacts::model()->cache(CACHE_TIMEOUT)->findByPk($model->cache(CACHE_TIMEOUT)->oRDERNO->CONTACTID);;
}else{
$dependency = new CDbCacheDependency('SELECT count(*) FROM sugarcrm6.contacts');
$client = SugarContacts::model()->cache(CACHE_TIMEOUT,$dependency)->findByPk($model->cache(CACHE_TIMEOUT)->oRDERNO->CONTACTID);
}
// addressestransmittals
$addressestransmittals = Addressestransmittals::model()->cache(CACHE_TIMEOUT)->findByPk($model->ORDERNO);
//addressesconsultants
$addressesconsultants = Addressesconsultants::model()->cache(CACHE_TIMEOUT)->findAll(array("condition"=>"ORDERNO = {$model->ORDERNO}"));
$contactList = $obj->getContactList(array("condition"=>"(first_name is not null || (first_name is not null && last_name is not null) ) && deleted = 0", "order"=>"first_name"));
Yii::log((memory_get_peak_usage(true))/1024/1024 . "MB",CLogger::LEVEL_INFO, __METHOD__);
$this->render('view',array(
'model'=>$model,
'client'=>$client,
'addressestransmittals'=>$addressestransmittals,
'addressesconsultants'=>$addressesconsultants,
'contactList'=>$contactList
));
}
What is the best way to reduce memory usage?
I place the following just before the render
to log the memory
Yii::log((memory_get_peak_usage(true))/1024/1024 . "MB",CLogger::LEVEL_INFO, __METHOD__);
Upvotes: 1
Views: 797
Reputation: 2654
I found the culprit it was the following line
$contactList = $obj->getContactList(array("condition"=>"(first_name is not null || (first_name is not null && last_name is not null) ) && deleted = 0", "order"=>"first_name"));
it was querying for all records in sugarcrm
database, seems like sugarcrm is not properly indexed, used up 70MB
Upvotes: 2