How do digg (or other high-load sites) store user sessions?

How does digg or any other high-traffic site store user sessions? What do they use to store user sessions? File system, DB (which?), Memcache, or both?

Imagine a simple situation. The recorded user set the Remember Me flag during login. We set a session cookie with an expiration date of 1 year. For example, we save the session in memcache, but we must also record this session in the database (in my version). Only users with the Remember Me flag are stored in the database. Is this the right way to store sessions? I mean sites with high traffic, of course (with two or more application servers, two or more databases, memecache servers, etc.). On small websites, default session storage (on the file system) is fine.

I tried to search on Google, but could not find any information about it. I read some solutions from the book "Advanced PHP Programming", but the main focus was on setting up a session storage handler.

Hope to hear some good ideas or links!

Thanks.

+6
php session scalability high-load
source share
3 answers

They certainly use memcached or equivalents.

+5
source share

In addition to Alix's answer, you may be interested in writing this article:

Short excerpt:

What prompted Memcached how to store sessions:

Shortly after deploying Digg v3, the non-redundant MySQL session storage hardware crashed. This led to a Digg power outage. We always planned that in this case we just (trivial) change to include sessions in Memcached, not MySQL, to see how it went on.


So, before you press db each time for sessions?

Yes.

MySQL was quite capable of keeping up with the insertions and was chosen to work with sessions. Our problem was cleaning old sessions. a script for deleting old sessions, although it is rather difficult in its attempts not to overload the database sessions still affected by it.

We assume that Memcached will delete expired sessions at a lower cost than MySQL.


We used InnoDB for sessions [before memcached]. It was not a table or row level lock. It was OS-level competition. Using Memcached before MySQL would decrease the load and permission of the administrator of the script to do its job, but this emphasizes the question: why is even MySQL behind memcached at all? We do not need or even need non-volatile sessions. (Important note for the reader: you may need or want non-volatile sessions).

"Why is even MySQL behind memcached in general?" ... "We do not need or even need non-volatile sessions."

+6
source share

My execution, when the user clicked to remind me, I added another cookie and assigned it a random value.

I check that non-registered agaist users have this cookie. If it exists, also matches the db entry, I will write them to the log, open a session.

saving to memcache should be great if you are not on shared hosting :)

0
source share

All Articles