That's correct. memcached doesn't offer a way to dump itself to disk, primarily because the process of listing all of the existing entries is a blocking process.
If you can't find what you're looking for in the lists, you can always mod memcached to do this for you.
Just curious, how much data are you storing in your memcache ?
Here's an idea you could use to avoid maintaining a forked memcache...
Request handling:
generate cache id
if mc->get(id)
serve from cache
else
generate data
serve data (possibly close client connection here)
mc->store(timestamp + data, id)
*store id to a file*
(*This basically becomes the key list that memcache doesn't have. You'd
want to save the id as fast as possible.)
Shutdown:
switch app to use different memcached server
run script to fetch every id in file and save to disk
shutdown memcached
Startup:
start memcached
run script to re-store() all data from disk
for any data you feel is too old (you'll have the timestamp)
generate it now (or just don't store it)
repoint app to use this memcached
If you want to make shutdown/startup quicker you could have a separate
process (not on user time, and throttled down in peak hours) whose job
is to watch the id list and sync memcached data to more permanent storage.
--
Steve Clay
http://mrclay.org/
John any word from legal? I would say just release the damn thing ;)
--
Chris Goffinet
MyBlogLog Senior Performance Engineer
Yahoo!
San Francisco, CA
United States
>
> In that case.. Would anyone be interested in collecting a bounty on
> getting a save/restore feature created that would be accepted into the
> main branch? What would be a fair bounty for something like this?
>
> Option to save all items in memory to hdd on shutdown of memcached.
> Option to load saved items from hdd to memory on start of memcached.
> Option to load, in addition to memory dump, a changes list from a text
> file (some simple to produce format - up to you) on start of
> memcached. Changes would include anything memcached can be asked to
> do.
We are working on creating a "storage interface" to memcached, so that
you can create you own back-end. This sounds like a pretty easy task
to implement in the prototype we have....
Cheers,
Trond
> We are working on creating a "storage interface" to memcached, so that you
> can create you own back-end. This sounds like a pretty easy task to
> implement in the prototype we have....
Indeed, with the pluggable storage engine that is going on, whats
been debated in this thread would be trivial to achieve. I'm sure
heaps of people would like this asap but at the moment, bug fixes and
the binary protocol takes priority so it would be awesome if people
could resist from taking action, such as forking.
One problem with memcached forks is that some forks have really nice
features but most (if not all) forks are unlikely to be
noticed/exposed/trusted/used by a lot of web developers/shops. This is
sad since this means that so much effort and knowledge is going to
waste. We should hopefully be able to eliminate that waste and the
likelihood of people forking memcached with the pluggable storage
engine architecture :)
Cheers,
Toru
- dumping in protocol format is a good idea.
- because you don't have to write code to reload that data.
- and you can edit it.
- but you might have to translate the expires times into explicit dates.
PlumbersStock.com ... if that is your real name, can you please be a
little more polite with the list?
Memcached has a long history (notable excerpts of which have been pasted
for your reading pleasure) of hashing out this feature. While we've agreed
that one adhering to the constraints listed above (ie; no explicit funky
dump/reload format) might be accepted, I would hope you don't view us (and
hope others don't get the impression of us as) a bunch of idiots who don't
understand your problems.
This approach simply doesn't work for most of us. I've already seen some
good suggestions of alternatives you could implement with technology that
exists today, without paying a bounty, and would work just fine. No need
to complain.
One idea would be to actually use an existing fork, like memcachedb. Sure,
our ultimate goal is to fold that feature back in, but hey it exists now
and someone spent some effort into making that fork.
Another method would be to just cache into MySQL and use the
libmemcached-based MySQL UDF's to update memcached. I suspect you've only
got the one box? Maybe two?
If not, it's not terribly hard to switch to a libmemcached based client.
If it is hard you can still do this without the UDF's... They just need to
be consistent on both ends so the key hashing lines up. Which doesn't
matter if you only have the one box.
Anyway, nothing fancy. Just create tables with the key, flags, expiredate,
value. INSERT into MySQL and SET into memcached at the same time. Then
read off of memcached. Then you just need a simple wrapper that SELECT *
FROM table WHERE expiredate > NOW(); and reload your data. From the
description of your awful horrible terrible backend system, it sounds like
it'd benefit you more from being able to fall back to MySQL on a memcached
cache miss anyway.
Most of us view these various scalability tools more like UNIX programs
than a batshit huge enterprise system. The idea is to take simple concepts
and plug them together on until they work.
-Dormando
So at least with the dozens of people I've talked with about this subject,
the demand drops quickly. No big push, no follow up. I guess one or two
people have implemented it, but not gotten the code back to us.
Personally, I still don't see a use for it so I won't be writing that code
myself.
On Wed, 10 Sep 2008, PlumbersStock.com wrote: