2

I read this - How does the lazy expiration mechanism in memcached operate?

So I have a question. Is it possible/recommended to make a program myself that periodically checks for all items in memcached, sending GET requests for each item so that expired items are removed?

The reason I want this is because I want to have a proper control of the used percentage in Memcached. If that percentage is near 100%, I will never be sure if I should add more memory, or if I should not worry because there are many expired items.

I use PHP, and unfortunately this doesn't return all the items in memcached (no clue why):

    $allSlabs = $memcache->getExtendedStats('slabs');
    foreach ($allSlabs as $server => $slabs) {
        foreach ($slabs as $slabId => $slabMeta) {
            $cdump = $memcache->getExtendedStats('cachedump', (int)$slabId);
            foreach ($cdump as $keys => $arrVal) {
                foreach ($arrVal as $key => $v) {
                    echo $key, "\n";
                }
            }
        }
    }
Community
  • 1
  • 1
Nuno
  • 3,082
  • 5
  • 38
  • 58
  • I'm not sure, but I assume the "used percentage" only checks un-expired items. I'm pretty sure my cache has never been near 100%, but if expired items will count toward the use-stats, it should only get bigger. And it doesn't. The percentage fluctuates (up _and_ down). I don't think active purging is neccesairy at all? LRU would only make sense to use _after_ replacing expired items. – Nanne Oct 03 '11 at 11:20
  • That would be good! I'll test myself, adding some junk for some MB, and see if % is still high after the expiration date. Thanks. – Nuno Oct 04 '11 at 05:58
  • So far it didn't decrease yet. It was supposed to decrease after 10 minutes. But I know what you are saying, because I see it fluctuating to me too, but it may take some time then. – Nuno Oct 04 '11 at 16:50

1 Answers1

2

You should just use the eviction rate to see if you need to add more memory. The eviction stats will increase if memcached had to throw out an object in order to make room for storing the next one. (and you can look at the "reclaimed" stat to see the number of times we could reclaim the memory for an item to store a new item.

The code you suggest would jam down the server by dumping its content every now and then.

trondn
  • 379
  • 1
  • 2
  • 1
    Seems my server doesn't show "reclaimed" stat. I know about evictions. I have "0" at this moment (which is good), but my idea was to avoid those at all. Thank you for your help! – Nuno Oct 04 '11 at 05:57