Coeus Blue Managed Web Hosting

866.847.8171

Very fast magento caching with apc and memcached

There is no single documentation regarding Magento's caching options in the local.xml and many of the posts that do exist today have not been updated in some time.  We have had a great deal of success using this in a no disk cache configuration.

<config>
<global>
<SNIP OUT INSTALL DETAILS ETC>
<cache>
<backend>Apc</backend>
<slow_backend>Memcached</slow_backend>
<fast_backend>Apc</fast_backend>
<slow_backend_options>
<servers><!-- The code supports using more than 1 server but it seems to hurt performance -->
<server>
<host><![CDATA[127.0.0.1]]></host>
<port><![CDATA[11211]]></port>
<persistent><![CDATA[1]]></persistent>
</server>
</servers>
<compression><![CDATA[]]></compression>
<cache_dir><![CDATA[]]></cache_dir>
<hashed_directory_level><![CDATA[]]></hashed_directory_level>
<hashed_directory_umask><![CDATA[]]></hashed_directory_umask>
<file_name_prefix><![CDATA[]]></file_name_prefix>
</slow_backend_options>

<memcached>
<servers>
<server>
<host><![CDATA[127.0.0.1]]></host>
<port><![CDATA[11211]]></port>
<persistent><![CDATA[1]]></persistent>
</server>
</servers>
<compression><![CDATA[]]></compression>
<cache_dir><![CDATA[]]></cache_dir>
<hashed_directory_level><![CDATA[]]></hashed_directory_level>
<hashed_directory_umask><![CDATA[]]></hashed_directory_umask>
<file_name_prefix><![CDATA[]]></file_name_prefix>
</memcached>
</cache>
<SNIP OUT RESOURCES SECTION>

</global>
<SNIP OUT ADMIN CONFIG SECTION>
</config>

A busy site will use a few hundred meg of APC cache and less than 100 meg of memcached cache.  At very high traffic levels memcache cannot keep up as the fast backend which is why this 2 tier method is being used.

This has been tested fairly heavily using nginx and php-fpm (both the 5.2 with patch and 5.3 native). You will need to use shared memory in apc to see the most gain.

If you have any questions or problems please feel free to post them.