Memcached Session Approaches

I was thinking of using memcached to store sessions instead of mySQL, which at first seemed like a good idea.

When it comes to the fault-tolerant part of using memcached servers, a little worry is that my sessions will stop working if memcached is disconnected. This will certainly affect my users.

There are several methods that we have already used to reduce fault tolerance, including having a pool of servers available to compensate for downtime, using stunning / consistent hashing in the server pool, etc. We will also do some graceful degradation that tells users that something went wrong and that they can log back in if they are thrown out due to a memcached server failure.

So, how do people usually deal with these issues when storing sessions on memcached servers?

+7
php memcached session
source share
3 answers

You can create a safe method using both db and memcached. Make sure your memcached object is in memory, and save the session in db, then create a memcache instance. Just make sure that when you log out / log out, it clears / removes memcached ...

So first check memcached, if it fails, check db ... :)

+3
source share

First, if you only put something in memcache, you should be fine by losing it. For everything else, there is persistent storage.

Secondly, memcached simply does not work very often. No moving parts, such as disc plates. The only times I ever lost a session were caused by a restart of kernel updates. But the loss of these sessions was not a big problem because of the first point.

So, to answer your question directly, if the zero date is ok to lose, saving it in the memcache session is only ok. If you fail to lose, save it to persistent storage and possibly cache it in memcache for speed.

+9
source share

Anyone considering this should read the Dormando session post . He received all the necessary details.

+3
source share

All Articles