MemCache Failed - Any alternatives ?

Hi all,

Actually My Rails application configuration is on Apache/Mongrel/Rails.We are using Apache for balancing.We have clustered Mongrel and What we assume is happening is that we have a problem with RoR sessions. Currently, we’re running 3 mongrel servers (let’s call them A, B and C). Now assume a new session is created by Server A and the ID is passed to the client (web browser) as a cookie which will be passed back to the server in subsequent HTTP requests.Now assume such a request is handled by server B. Server B would try to lookup the object in its session store but wouldn’t find anything and hence, it would simply create a new session.Then we are getting Exception because session is not available at that point.We are Using Memcache and we came to a conclusion like we need to use another alternative to memcache for session storage.

So please let me know is there any alternative way to solve this problem? or do we need to chage the entire configuration ? If so, how we need to proceed further.

People said that this group is having expert brains,i forgot to post this question in past and i would be happy if any body gives any link or explain me how to resolve my issue.I would be great to you :slight_smile:

Thanks in Advance !

Cheers, Kishan

What are you using as a shared session store? If you're clustering Rails application servers then they should all see the exact same data.

You should be using DB-based session store. Memcache is for very high- traffic sites, don't bother with it.

zeka wrote:

You should be using DB-based session store. Memcache is for very high- traffic sites, don't bother with it.

There's nothing wrong with using Memcache, the point of it is that it's shared memory.

So, as long as all of your mongrels are pointing towards the same instance of memcache, then they will share that information.

Except, I believe memcache will not persist, so if we restart memcached, you'll lose all the sessions.

So, you only really want to use it if your sessions dont need to persist.

I'd suggest using the :cookie_session_store which is the default session storage in rails 2.1, and stores all the data in the client side cookie, so there is no dependence on db or file system or memcache...

Kishan,

memcached works fine for session storage (although there are
alternatives like db store, cookie store in RoR 2.x, etc.) so you
shouldn't have to switch if memcached is your preferred storage
mechanism... based on your description of the problem, I'd wager that
your various mongrel servers (A, B and C, as you label them) are each
running an isolated instance of memcached, and are not sharing their
content with the other memcached instances in the cluster... you need
to re-configure memcached so that the 3 instances "share" their
content (e.g. the "servers" directive in memcached.yml in case you're
using cache-fu)... also make sure that the firewall on each mongrel
server allows connections on port 11211, which is the default port for
memcached.

Good luck,

Peter