2

This project has around 150k skus with stock management enabled, most of them are configurable products... We've been live with 256Mb php memory_limit, but during last weeks we're having allowed memory errors during checkout

Errors come when last available unit of a configurable child is sold (stock status change)

We've fixed this raising memory_limit to 512Mb, but I'd like to see which data is consuming so much memory, the concrete piece of code firing the error is the setNewData() line in mergePreviousData() method, in Mage_Index_Model_Event class

public function mergePreviousData($data)
{
    if (!empty($data['event_id'])) {
        $this->setId($data['event_id']);
        $this->setCreatedAt($data['created_at']);
    }

    if (!empty($data['new_data'])) {
        $previousNewData = unserialize($data['new_data']);
        $currentNewData  = $this->getNewData(false);
        $currentNewData = $this->_mergeNewDataRecursive($previousNewData, $currentNewData);
        $this->setNewData(serialize($currentNewData));
    }
    return $this;
}

I've checked $currentNewData in DB, and it is a very simple and light object, with just some properties... so I suspect problem must be with that _mergeNewDataRecursive() previous line, but I am not sure which part of the checkout request is consuming so much memory

Any ideas?

3
+100

Honestly, it's hard to guess which line consumes the most memory.

I suggest you use the profile to find out exactly which line is the culprit.

First enable the profiler.

Then update the code with the following:

public function mergePreviousData($data)
{
    if (!empty($data['event_id'])) {
        $this->setId($data['event_id']);
        $this->setCreatedAt($data['created_at']);
    }

    if (!empty($data['new_data'])) {
        Varien_Profiler::start('unserialize');
        $previousNewData = unserialize($data['new_data']);
        Varien_Profiler::stop('unserialize');
        Varien_Profiler::start('getNewData');
        $currentNewData  = $this->getNewData(false);
        Varien_Profiler::stop('getNewData');
        Varien_Profiler::start('_mergeNewDataRecursive');
        $currentNewData = $this->_mergeNewDataRecursive($previousNewData, $currentNewData);
        Varien_Profiler::stop('_mergeNewDataRecursive');
        Varien_Profiler::start('setNewData');
        $this->setNewData(serialize($currentNewData));
        Varien_Profiler::stop('setNewData');
    }
    return $this;
}

Trigger this code (according to your question by selling the last available unit of a configurable child) and check the results.

I know this is not a fix but when you deal with a lot of skus and when you're not on EE, those memory issues are hard to track down.

  • This is not what I was expecting (I'd expect to see a trace of all methods fired during checkout for the concrete case, as I guess this is related to the painful way Magento gets simple products of a configurable product) when adding the bounty points, but surely you're right. I'll wait a few & give you the points – Raul Sanchez Nov 29 '16 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.