Rails: what happens when memcached goes down

I tried to figure out how rails reacts to the fact that memcached goes down. Unfortunately there is no god documentation about this besides saying that everything will be fine. Also there are couple misleading posts in different forums saying that rails will never rediscover memcached server that went down and came back again. Here’s what is actually happening…

Since no good documentation on subject is provided I ran couple tests with memcached in verbose mode:
memcached -vvv
So my tests started when everything was working fine and my rails app was happily hitting the cache. Then I killed memcached (with simple ^C) and refreshed the page again. With no noticeable lag rails figured out that memcached is down. It refreshed the page just like if all the keys it requested from cache missed. Then I brought memcached back to live and refreshed the page again. Rails didn’t hit memcached (and thus most probably lead some people to false assumption Rails will never figure out that memcached is back). So I kept refreshing the page and, oh miracle, 20 seconds later Rails decided to ping memcached, found it is alive and started using it again.
Apparently the same thing is happening when rails app starts before memcached. So the documentation is right and everything will be figured out by rails and memcached automagically, you do not need to worry about this. Awesome pair of technologies!

Leave a Reply