1

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?

6
  • memcached is distributed by nature, you don't need/want a shared central instance.
    – Andy
    Sep 5 '14 at 13:46
  • Nope, I don't want a shared central instance. I'd like a failover instance so our Drupal sites don't bork if they can't contact memcached. I'm not bothered about whether the standby instance is cold or not.
    – batfastad
    Sep 9 '14 at 9:38
  • I was mainly wondering what the reason was for being able to specify an array of memcached servers in settings.php
    – batfastad
    Sep 9 '14 at 10:07
  • That's because it's a distributed cache - check out the memcache module's readme and maybe something about consistent hashing.
    – Andy
    Sep 16 '14 at 8:47
  • You may also consider redis.
    – kenorb
    Nov 30 '15 at 12:08
1

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' => 'default',
  '10.0.0.2:11212' => 'default',
  '10.0.0.3:11212' => 'default'
);
$conf['memcache_bins'] = array('cache' => '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.

0

Looks like you're wanting memcache replication. My recommendation is to use MySQL's memcache plugin to accomplish this replication. Also recommend using MySQL 5.7 if you're comfortable with using a non GA release for your caches.

1
  • Funnily enough I did think about that. I'm not really bothered about making sure the memcached content is persistent though. All I want to do is be able to have a cold failover memcached available should the primary go down. I think I will probably set it up through our haproxy load balancer and let haproxy take care of the failover to another instance.
    – batfastad
    Sep 9 '14 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.