Drupal web cluster with memcached. memcached failover? Running Drupal 7 sites (under Aegir) and I'm investigating a method to scale out the web boxes horizontally, so that any Apache server can process a request for any Drupal site. We're currently at ~50 Drupal sites on our platform. All sites also run through Varnish.

At the moment with our single-server setup I have memcached installed locally on the Apache box.

If we add further Apache boxes and each has their own memcached instance, it's likely that cached content in memcached will be different on each different host.
The way around this is to run memcached on our Varnish or database instance, though on our Varnish box makes most sense.

From the settings.php config I can presumably specify multiple memcached servers in the memcache_servers array:  

// make MemCacheDrupal the default cache class
$conf['cache_default_class'] = 'MemCacheDrupal';

// Key Prefix: edit this for multisite use.
$conf['memcache_key_prefix'] = $databases['default']['default']['username'];

$conf['memcache_servers'] = array(
    '127.0.0.1:11211' => 'default',
);

How does Drupal choose which memcached server to use from this array?

What I'm looking for is the ability to specify a failover memcached server. So if the primary "shared" memcached instance is down, say we take our Varnish VM down for maintenance, then it starts using another cold memcached instance.

Or as an alternative is there a way for Drupal to failover to using the database cache instead of memcached?
If you might want to setup a memcache cluster, consisting of multiple servers. The idea is that you have more than one server in the cluster and if one of the servers is offline for some reason the others will be used.

This is fairly easy to setup and is documented in the memcache module as well, the config could look something like this:

$conf['memcache_servers'] = array(
  '10.0.0.1:11212' =&gt; 'default',
  '10.0.0.2:11212' =&gt; 'default',
  '10.0.0.3:11212' =&gt; 'default'
);
$conf['memcache_bins'] = array('cache' =&gt; 'default');


PHP will handle the clustering, so you wouldn't need to do anything. This means that if a server dies, that cache wont be available, but will automatically be generated on one of the other servers.

One of the ideas with memcache is that you can pool the memory of multiple servers to create a single shared pool.

In your example, you could also use your webservers as a memcache cluster, but that would require that the webservers can talk to each other. Usually when you require multiple servers, you also want to have separate memcache servers, so you can optimize the servers for their specific task.