save to disk functionality

Brad Fitzpatrick
Sun, 2 Nov 2003 18:33:32 -0800 (PST)

I don't have much desire to add save-to-disk functionality, for two

1) I hate disks.

2) It's too complicated, especially with 13 memcached servers (as LJ
   has)... getting the state saved/restored atomically.  And a half-ass
   job means we start to imply that memcached is reliable storage, and I don't
   want people to think that.  Look:  already you're using it as reliable
   storage and your users are suffering.  More people would use it like
   that if they thought their data was safe in it.

You should just tweak your session handler backend to always write to both
memcached and the database, and try to read from memcached first, falling
back to the database.

You could even make the db write not painful by doing it after the
client's already been sent the request.  In mod_perl that's the cleanup
handler.  Not sure what they call it in PHP.

Now, all that said... I'm not totally against the idea.  I just don't want
to rush into it without a damn good plan, worrying about all the problems.

- Brad

On Sun, 2 Nov 2003, Justin Matlock wrote:

> Here's something that would be quite useful for me; I don't know about anyone else -- but I can see how it would create some dramatic speed increases for most sites on a memcached restart...
> How about adding "save to disk" functionality to memcached via a command line option?
> When it gets hit by a certain signal (TERM?), it dumps the memory cache to a file specified on the command line.  When it starts up, it reads that cache file and repopulates itself (expiring out any data that expired during the 'downtime').
> I've started experimenting with storing session data in memcached vs. using MySQL.  I've been able to dramatically speed up the site this way, but "Very Bad Things" happen to my logged in members if my memcached server is restarted. PHP has other distributed memory-based session handlers available (msession), but I've found memcached is about 60% faster (!).
> As much as I would love to have memcached on it's own stable dedicated server, I just can't afford to do that yet -- so it runs on all of my webserver machines... there's something strange about my Apache 2.0.47/SSL configuration that occasionally locks up the machine -- it zombie's httpd and refuses to let go of port 443, no matter what I do; I have to initiate a controlled restart.. having memcached be able to start back where it left off would be incredibly useful (and would speed other things up, as it wouldn't have to "rebuild" the cache from the database).
> In the same vein, I suppose there could be a periodic "save to disk" function that will dump the memory cache every "x" minutes, just in case there is a system failure that prevents a normal shutdown.... (I'm just throwing that idea out -- it probably wouldn't be worth it -- I'd bet it would slow memcached down during normal operations).
> Any thoughts?
> Justin