Home > Magento > Magento ‘Can’t get filling percentage’ memcache issue

Magento ‘Can’t get filling percentage’ memcache issue

This is a known problem for anyone who runs Magento and uses memcache as a caching backend. But it’s actually not a Magento issue, it’s a Zend Framework problem, and it seems that even newer versions of ZF still have the same approach. I suspect this is actually a memcache problem, but even so, one should be able to handle things better in the code.

The idea is that memcached sometimes fails to report its extended stats, thus the “getExtendedStats” method returns false, when in fact it should return an array with all the servers. This should not be a problem though, instead of throwing an exception, why not retry with getStats and then just return 100 (which I guess it means the server is full). Here’s the revised code:

if ($memSize === null || $memUsed === null) {
    $mem = $this->_memcache->getstats();
    if (isset($mem['limit_maxbytes']) && $mem['limit_maxbytes'] > 0) {
        return ((int) (100 * ($mem['bytes'] / $mem['limit_maxbytes'])));
    } else {
        return 100;
    }
 
    //Zend_Cache::throwException('Can\'t get filling percentage');
}

You can get the entire file on github, but please note that this file corresponds to ZF v1.11.1 and Magento CE v1.5.1.0. It can definitely be adapted to any Magento version.

The easiest way to patch this without changing a core file (ie lib/Zend/Cache/Backend/Memcached.php) is to put the modified file in your app/code/local folder:
app/code/local/Zend/Cache/Backend/Memcached.php. since app/code/local comes first in the include path, the patched file will get included before the default one.

Disclaimer: This hasn’t been used in production, use at your own risk. In theory, it should be fine, but since it hasn’t passed any real testing, I don’t recommend doing so.

  1. Cristi
    February 11th, 2015 at 16:03 | #1

    I’m glad it helped! Magento doesn’t handle it because this *shouldn’t* happen at all. It’s a memcached issue, and the workaround is quite slow so i wouldn’t really use it in production. In fact, since this post, I’ve switched most of my Magento stores to Redis – not necessarily because of this issue, but mostly because of how it performs when dealing with thousands of small objects.

  2. February 11th, 2015 at 15:51 | #2

    Thanks! This solved the problem for me. Silly Magento, that it doesn’t handle this error!

  1. No trackbacks yet.