cbstats output with memcache bucket

Hello,
maybe somebody will be so kind to clarify a point for me.

Reading around, I seem to understand that expired items should be removed from a bucket *only* on two occasions... in the words of a post in the forums:
- when an expired item is accessed (if your application is doing a get of a key that is expired it will return a not found/null and remove the item from the RAM)
- when the bucket has no RAM left it will automatically remove some expired items to be able to store new items."

Ok. But then, how do I read the cbstats items snippet below? What does the 'reclaimed' figure means? The bucket has plenty of memory left (2.5G free out of 6G total).

items:9:age: 18491993
items:9:evicted: 0
items:9:evicted_nonzero: 0
items:9:evicted_time: 0
items:9:number: 4844507
items:9:outofmemory: 0
items:9:reclaimed: 70041863
items:9:tailrepairs: 0

What I find strange is that the number of items in this bucket oscillates between 5 and 6 M, with a weekly cycle. But if we are not evicting anything (stats zero everywhere) and each deletion due to expiration is followed by a new item being inserted (receive a miss -> fetch the item from a database and re-insert it in cache) , then why is the number of items decreasing? Shouldn't this be constant or always increasing?

Thanks!

1 Answer

« Back to question.

When you store an item into the memcached bucket types it first tries to look at the least recently used objects to see if it is already expired. If that is the case it will grab that object instead of allocating new memory. This will cause the reclaimed counter to increase. If none of the objects in the tail of that list have expired it will try to allocate more memory for the item, but if we've already used all of the memory we're supposed to use it will go back to the tail of the list of the objects and evict one of the objects instead (and that cause the eviction counter to increase).

Hope this helps.

Thanks for your answer, did not find anything documented about this behavior.

I still do not understand why the number of objects is decreasing, though. if we replace only when we insert, then the number of objects should stay constant. Or is the counter only including unexpired items, by any chance?

Thanks again,
Paolo