Skip to main content

Multi Instance Memcache Server on Ubuntu 10.04

Back-end Development
Drupal

Running Memcached on a web server is nothing extrodinary and neither is running multiple instaces of memcached to manage different types of cached content.  However the default installation of memcached installed via aptitude is configured for running only one instance.  Here are the files that need to change in order to make memcache start up and maintain multiple daemons.

You can find all the code for these changes here: https://gist.github.com/mbopp/5957231

By default you have one memcache configuration file in /etc/ called memcache.conf.  What we want is to have one .conf file for every instance.  So use the naming convention /etc/memcache_*.conf.  We will then change our startup script to loop over these conf files rather than assuming there is just one.

Here is an example: https://gist.github.com/mbopp/5957231#file-etc-memcache_instance-conf

The next change is to your /etc/init.d/memcached startup script. As I mentioned we need this script to loop over all available memcache_*.conf files and start a seperate instance/daemon for each.

https://gist.github.com/mbopp/5957231#file-etc-init-d-memcache

Lastly, and also the least obvious change needed is to the bootstrap perl script located at /usr/share/memcached/scripts/start-memcached which is called by our init.d memcached script and is resonsible for parsing our .conf files.  We want to change this file to accept a parameter for the /etc/ file rather than assume it is just the one memcache.conf.  Specifically we are just adding two lines around line 26... 

if (scalar(@ARGV) == 2) {
  $etcfile = shift(@ARGV);
	$pidfile = shift(@ARGV);
}

Here is the whole file: https://gist.github.com/mbopp/5957231#file-usr-share-memcached-scripts-start-memcached

Need a fresh perspective on a tough project?

Let’s talk about how RDG can help.

Contact Us