Friday, October 2, 2009

I first read about memcached a year ago or so. It's a brilliantly simple idea. I haven't tried using it though, since I haven't seen any situation where it would be useful.

However, thinking back to about 4-5 years ago, what I was working on then was having performance issues with sessions, and something using memcached might have helped. I don't know what happened since then, but I haven't heard about any problems. I have also heard that the session database was now running on some super fancy hardware.

Besides the performance issues, there was also an occasional stale session issue. The servlet container was configured to save the session to the database when the session state was changed, but also to keep the sessions cached in memory, so that the session didn't have to be read back from the database. The load balancer was configured to make the sessions sticky. However, if the load balancer decided that one box was unavailable, the session would move to another box, which would load the session from the database, and all would be fine. However, if the load balancer decided that the first box was available again, the session would go back to the first box, and if the second box had changed the session, the first box would now have a stale session.

I haven't heard about any stale sessions since then, but back then, there was an effort made to minimize changes in the session. I don't think anything came of that effort, and I'm sure that updates are made to sessions all over the place by code added since then. There were also efforts made to eliminate extraneous bloat from the sessions.

The stale session issue could be solved by using memcached as a shared cache for the sessions instead of each box caching sessions. On the other hand, if moving the sessions back and forth over the network was the performance issue, then memcached would hurt performance. Also, eliminating the local session cache would probably cause a minor increase in garbage, since the sessions would have to be reconstructed for each request.

No comments:

Post a Comment