APC object caching in combination Batcache/memcached page caching?

In the post WordPress Caching Comparisons Part 2 Matt Martz compares different caching setups, among them APC object caching together with Batcache page caching. In his post this combination seems to be the best tradeoff between setup complexity and efficiency. He doesn’t mention memcached so I’m unsure if it’s used or not. From reading Mark Jaquith’s post APC Object Cache Backend for WordPress it seems to me that his plugin works as a drop-in replacement backend to be used in place of memcached which is what the Batcache installation instructions says to use. This is also how it has worked in my experiments with these plugins. I.e. either the APC or memcached backend is used, but not together and in combination.

However, from watching Iliya Polihronov’s High-performance WordPress video (and this is where I started when looking into caching) I got the impression that APC object cache can be used for opcode caching in combination with Batcache/memchached for full page caching, for even better results. (the batcache discussion is at the very end of the video) Is this possible and would there be of any benfit, or am I just confused?

Read More

In my case I’m looking for the best solution for multiple virtual single-WordPress servers (i.e. not multisite) served by a single webserver (nginx). This runs on solid state media (Raspberry Pi/SD-card) so it would be preferable to keep cache in memory. I have full access to the system and have apc, memcache and memcached extensions installed.

edit: From reading the Batcache source my understanding is that Batcache uses whatever is offered by object-cache.php, so it’s either APC or memcached object cache as used exclusively by the respective backend plugins.

Also, I found Matt’s definition of bytecode, object and page caching at the end of his post enlightening.

Related posts

1 comment

  1. The basic rule of thumb for Memcached is: use it if you’re running multiple servers or connecting to multiple databases for the same assets.

    Another more harsh way to put it: If you don’t know what Memcached is, you probably don’t need it.

    Since you have a single server(and probably single DB) you won’t be able to take advantage of several Memcached features.

    Memcached: Distributed memory object caching

    APC: Bytecode optimization

    You can use a combination of APC and Memcached, you can also use APC with Batcache without Memcached or various combinations of plugins, so it’s a bit confusing.

    To clarify Batcache

    Batcache has the ability to support Memcached but if you do not have Memcached installed it will still use WordPress’s object cache which is defined in your config.php using define('WP_CACHE', true); and thus APC will take advantage of that.

    One advantage of Batcache besides supporting complex server setups via Memcached is it does not write to file , this is why services like WordPress.com use it. Imagine if they had to static cache all their sites, it would be billions of files and impossible to manage via file I/O.

    Though Batcache is fairly simple, the execution can be complex, it can be configured as seen by the comments here: http://plugins.trac.wordpress.org/browser/batcache/trunk/advanced-cache.php

    To clarify Memcached

    Memcached is really meant for multiple servers so they can share and use memory in a intelligent way, in essence they will share a virtual pool of memory. Each node can make use of memory from other nodes (a node does not have to be a traditional web server). Memcache does not care what language you are using since it supports most of them. http://memcached.org/about

    To clarify APC

    APC in simple terms is single server and PHP only. It stores all the PHP(bytecode) based compiling in RAM.

    For a single server

    1. APC + Mark Jaquith’s Dropin + static file cache plugin (super-cache,
      w3-total
      , etc, etc) will net you very fast results. In other words
      APC + a static cache is much faster on a single server then just
      Memcached and/or a non static cache. You can of course combine them
      on a single server, I have never tried that, it’s doubtful there
      will be any improvement. Using Memcached on a single server that already has APC would be like trying to tow a car by hitching the front to the back.

    2. The alternative is to use APC + Batcache instead of a static caching
      plugin, this will most likely give you the same results, just make
      sure you have plenty of ram. This is a fine solution but it requires more server monitoring (imo) than just writing static files because servers are still finicky beasts.

    If after doing one of the above and your site is still having issues, then you need to move to a new level with your hardware or start thinking about more complex setups with multiple servers.

    Also bear in mind this is not about just general site “speed” but about speed + concurrency.

    Don’t optimize for the sake of it.. you will get to a point where optimization does nothing unless there is a demand for it.

    Notes:

    Each server setup is different and caching is directly tied into the performance of your CPU, RAM, actual code and configurations, so results will vary…there are a lot of configuration options for both APC and Memcached.

    It’s important to note that https://github.com/zendtech/ZendOptimizerPlus will probably eventually replace APC.

    ps. Test APC out on a dev server before you go live, it often needs fiddling with the configuration or the server might blow up.

Comments are closed.