Magento – Magento + APCu caching issue. Site is slow and there is more cache misses than hits

cachemagento-1.7PHP

I have a Magento 1.7.0.2 installation running on LEMP Stack; Nginx + PHP-FPM (PHP v5.5.6 w/ APCu v4.0.2) + Percona.

I've configured my magento to use APCu caching like this:

app/etc/local.xml

<config>
    <global>
        ...
        <cache>
            <backend>apc</backend>
            <prefix>BDWEB_</prefix>
        </cache>
    </global>
    ...
</config>

and the APC is configured like this:

/etc/php.d/apcu.ini

extension=apcu.so

apc.enabled          = 1
apc.shm_segments     = 1
apc.shm_size         = 512M
apc.ttl              = 7200
apc.user_ttl         = 7200
apc.num_files_hint   = 10240
apc.mmap_file_mask   = /tmp/apc.XXXXXXX
apc.enable_cli       = 1
apc.cache_by_default = 1
apc.max_file_size    = 10M
apc.stat             = 1

and here's the apc info page displaying the huge miss to hit ratio:

enter image description here

Any idea what might be wrong?

Best Answer

You can read more information on why it is happening here: http://magebase.com/magento-tutorials/improving-the-file-cache-backend/

TL;DR;

Don't use APC as a cache Backend for Magento.

In a nutshell, the APC Zend Cache Backend can only be used for the actual cache records.
Magento automatically uses the Zend Two Level Cache Backend in conjunction with the regular File Cache Backend to save the cache meta data (cache tags) when the APC cache backend is configured.

Instead, use https://github.com/colinmollenhour/Cm_Cache_Backend_File for single webserver instances.
It is much faster and scales better by an order of magnitude then the APC-File cache backend combo.
If you are using more then one webserver, use https://github.com/colinmollenhour/Cm_Cache_Backend_Redis, which has also been included in the core (CE+EE) since a couple of versions now.

To benchmark your cache setup I can recommend https://github.com/colinmollenhour/magento-cache-benchmark

Related Topic