How to find where a memcached key originates from in Magento

110 Views Asked by At

We run Magento EE 1.13 with memcached as our "fast" cache and redis for the "slow" cache. We have a certain memcached key that is getting approximately 70 get requests per second, but 0% hits. This only happens on our production site, which has multiple front end servers and a separate database server.

It seems this particular key is never set, but we can't find where the key is originating from. The key uses a md5 hash "AA_B1B5D70089938E5C32F61E616FD3908D", so that doesn't help to narrow it down.

Where can I look to track down where this key is coming from?

1

There are 1 best solutions below

0
On BEST ANSWER

I was able to figure this out. In app/code/core/Mage/Core/Model/App.php, look for:

public function loadCache($id)
{
    return $this->_cache->load($id);
}

Inside this function is where you want to add your temporary check:

public function loadCache($id)
{
    if (strstr($id, 'b1b5d70')) {
        $currentUrl = Mage::helper('core/url')->getCurrentUrl();
        $cacheId = $this->_cache->load($id);
        $stack = Varien_Debug::backtrace(true, true);
        Mage::log("Mage_Core_Model_App: " . $id, null, "memcacheKeys.log", true);
        Mage::log($currentUrl, null, "memcacheKeys.log", true);
        Mage::log($cacheId, null, "memcacheKeys.log", true);
        Mage::log($stack, null, "memcacheKeys.log", true);
    }
    return $this->_cache->load($id);
}

We are checking for the partial memcached key here, 'b1b5d70'. The key has not yet been converted to uppercase at this point. The prefix defined in local.xml, 'AA_', has also not been added yet.

The backtrace that gets saved to your log should tell you where the key is getting generated. In my case, it traced to 'app/code/core/Mage/Catalog/Block/Product/Price.php'.