Redundant Memcache Servers and Rails

Posted by Nathan Kaiser on Wed Jan 07 13:07:00 UTC 2009


In the web 2.0 world, redundancy and scalability are buzzwords you hear every day. At Blue Box Group, we are constantly working with our clients to ensure that their sites are both fast, and available during a failure. During recent testing of a client’s website, it was discovered that in the default installation of Rails 2.2.x (and possibly other versions) are using memcached code that will lock up an installation of Rails if the memcached server dies. Additionally, if you are using multiple memcached installations for redundancy, rails will not gracefully fail over to use the second.

Not good.

However, our friends over at FiveRuns have devised a clever set of patches for the memcache client gem. You can read about their fix in their blog post here. You can install their patched version of memcache client with these commands:

$ sudo gem uninstall memcache-client
$ sudo gem install fiveruns-memcache-client --source http://gems.github.com


Preliminary testing shows that this gem fixes all the associated problems with the existing memcache-client and HA setups.

We will continue to test this configuration in production, but don’t expect to see problems with it.

Thanks to FiveRuns for providing the fix. Hopefully this will be adopted into mainline soon.

  • Jesse Proudman

Blue Box Group