Skip to content

Configuring APC correctly to optimise Magento performance

Magento is a wonderful way of quickly and inexpensively creating an ecommerce website, but it does have some major downsides. The complexity of theming it is well know, as is the extremely mediocre performance on typically web hosting. There are any number of methods of speeding things up, but on the face of it the most straightforward method is to enable the Magento cache to use APC.  Switching the caching mechanism from using the filesystem (which stores cached data in /var/cache) to use APC (which caches in memory) should lead to a doubling in the number of pages served per second.

However, when I was running some tests I was actually seeing a decrease in performance with APC enabled in comparison to the default setup. This was odd, as in the past I’ve used APC with custom web applications that I have created and have never seen performance decrease. APC comes with a useful monitoring console which you can use to view the current state of the cache (shown below).

image showing healthy APC stats when running Magento

In an ideal world you will have a very high percentage of cache hits, very little memory fragmentation and a reasonable number of free MB. In my case APC only had 32MB RAM available, which meant that the Cache was constantly “churning”. As a minimum you should have 64MB memory available to APC when running Magento, otherwise performance will drop, rather than increase.

Having problems with slow performance on your Magento web site? Need some help squeezing some extra speed out of it? Why not get in touch?

This entry was posted in Magento and tagged , , , , . Bookmark the permalink.

3 Responses to Configuring APC correctly to optimise Magento performance

  1. I have a strange issue with Magento/APC.

    The cache is enabled in local.xml, there’s plenty of SHM (90MB), I’ve cleared the various cache’s with the admin tool and by manually deleting var/cache, I’ve restarted Apache etc etc.

    The user cache gets populated with the items i’m familiar with from var/cache but the number of hits for each remains at 0 after browsing through the site. Apache bench shows about the same requests per second with and without APC as the cache backend. V strange.

    I’ve notices that some dirs are still being created in var/cache (although not all – mage–0, mage–1, mage–c, mage–d, mage–f).

    I’m using Centos5/PHP 5.2.6/MySQL 5.0/APC 3.0.19 (default PECL install)/Magento

    Any advice would be appreciated. Thanks

  2. addendum…

    It looks like, from the Last Accessed/Modified/Created stats, that each cache entriy is being recreated/overwritten for every request. Could it be a Magento bug or am I doing something wrong?

  3. Hummm. There are others better qualified than I to comment about your problem, but I’ll try to give some intelligent suggestions.

    It does sound like a bad case of cache churning – which is odd considering that you say you’ve got 90MB RAM available for APC. Are you sure that RAM is actually available to APC? Recently I was setting 64MB RAM to APC in my php.ini file, but due to a typo this wasn’t getting parsed correctly and APC was actually resetting to default, which is 32MB.

    What are you using to measure performance? Siege?

    A copy of my apc module config is shown below:

    apc.ttl = 7200