object deletion

Steven Grimm sgrimm at facebook.com
Tue Mar 20 18:25:51 UTC 2007


The simple answer is that it's an LRU cache. The least recently accessed 
object will be deleted to make room for a new one.

The more accurate answer is that it is a series of independent LRU 
caches organized by ranges of object sizes. When a new object needs to 
evict an old one, an object of roughly the same size is evicted (even if 
there were objects of other sizes that were accessed less recently). The 
downside is that it's not pure LRU, but the upside is that you are 
guaranteed that at most one object will ever be evicted to make room for 
a new one.

But in the vast majority of cases you can think of it as a simple LRU 
cache and you'll be close enough.

-Steve


Dmitry Koterov wrote:
> By the way, where can I found a description of memcached deletion 
> algorythm?
> What elements are deleted and in what order?
>
> On 3/20/07, *Steven Grimm* < sgrimm at facebook.com 
> <mailto:sgrimm at facebook.com>> wrote:
>
>     What's the problem you're trying to solve? You want to see why cache
>     entries are vanishing, I imagine? If so, then you're right, just
>     logging
>     it will be easiest, especially if you have multiple clients. The
>     server
>     doesn't do that out of the box, but it'd be pretty easy to hack in. I
>     think the following would do it (output will only happen if you
>     run the
>     server with "-vv"):
>
>     --- a/src/items.c
>     +++ b/src/items.c
>     @@ -100,6 +100,8 @@ item *do_item_alloc(char *key, size_t nkey, int
>     flags, rel_time_t expti
>
>              for (search = tails[id]; tries>0 && search; tries--,
>     search=search->prev) {
>                  if (search->refcount==0) {
>     +                if (settings.verbose > 1)
>     +                    printf("evicting item %s\n", ITEM_key(search));
>                      do_item_unlink(search);
>                      break;
>                  }
>
>     That's against the MT version of the code but should apply to the
>     vanilla 1.2.x code too (maybe even 1.1.x).
>
>     -Steve
>
>
>     Cristian Rusu wrote:
>     > Hello
>     >
>     > Is there any way to make the server call a specified client API
>     > function on object deletion when that happens in order to release
>     > resources for new objects? It will be useful at least for debug
>     purposes?
>     >
>     > Something I can set as a callback just before using add or set
>     > API...to return all keys deleted.
>     > Or to set a dump file if not....
>     >
>     >
>     > --
>     > Sincerely
>     > Cristian Rusu
>     > Web Programmer & Electronic publisher
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20070320/664764cc/attachment-0001.html


More information about the memcached mailing list