Permalink
Browse files

new per-slab item stat evicted_nonzero

If an item with exptime != 0 (non unlimited) is evicted the evicted_nonzero
counter is incremented.

The number of evicted items with no expire time is (evicted - evicted_nonzero)
  • Loading branch information...
1 parent c94c940 commit 6beee7416102ef3f7e840d7e79bac5281e5ed31f @dormando dormando committed with dustin Oct 7, 2009
Showing with 39 additions and 0 deletions.
  1. +3 −0 doc/protocol.txt
  2. +5 −0 items.c
  3. +31 −0 t/evictions.t
View
@@ -474,6 +474,9 @@ number Number of items presently stored in this class. Expired
age Age of the oldest item in the LRU.
evicted Number of times an item had to be evicted from the LRU
before it expired.
+evicted_nonzero Number of times an item which had an explicit expire
+ time set had to be evicted from the LRU before it
+ expired.
evicted_time Seconds since the last access for the most recent item
evicted from this class. Use this to judge how
recently active your evicted data is.
View
@@ -27,6 +27,7 @@ static void item_unlink_q(item *it);
#define LARGEST_ID POWER_LARGEST
typedef struct {
unsigned int evicted;
+ unsigned int evicted_nonzero;
rel_time_t evicted_time;
unsigned int outofmemory;
unsigned int tailrepairs;
@@ -149,6 +150,8 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
if (search->exptime == 0 || search->exptime > current_time) {
itemstats[id].evicted++;
itemstats[id].evicted_time = current_time - search->time;
+ if (search->exptime != 0)
+ itemstats[id].evicted_nonzero++;
STATS_LOCK();
stats.evictions++;
STATS_UNLOCK();
@@ -394,6 +397,8 @@ void do_item_stats(ADD_STAT add_stats, void *c) {
APPEND_NUM_FMT_STAT(fmt, i, "age", "%u", tails[i]->time);
APPEND_NUM_FMT_STAT(fmt, i, "evicted",
"%u", itemstats[i].evicted);
+ APPEND_NUM_FMT_STAT(fmt, i, "evicted_nonzero",
+ "%u", itemstats[i].evicted_nonzero);
APPEND_NUM_FMT_STAT(fmt, i, "evicted_time",
"%u", itemstats[i].evicted_time);
APPEND_NUM_FMT_STAT(fmt, i, "outofmemory",
View
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+# Test the 'stats items' evictions counters.
+
+use strict;
+use Test::More tests => 92;
+use FindBin qw($Bin);
+use lib "$Bin/lib";
+use MemcachedTest;
+
+my $server = new_memcached("-m 3");
+my $sock = $server->sock;
+my $value = "B"x66560;
+my $key = 0;
+
+# These aren't set to expire.
+for ($key = 0; $key < 40; $key++) {
+ print $sock "set key$key 0 0 66560\r\n$value\r\n";
+ is(scalar <$sock>, "STORED\r\n", "stored key$key");
+}
+
+# These ones would expire in 600 seconds.
+for ($key = 0; $key < 50; $key++) {
+ print $sock "set key$key 0 600 66560\r\n$value\r\n";
+ is(scalar <$sock>, "STORED\r\n", "stored key$key");
+}
+
+my $stats = mem_stats($sock, "items");
+my $evicted = $stats->{"items:31:evicted"};
+isnt($evicted, "0", "check evicted");
+my $evicted_nonzero = $stats->{"items:31:evicted_nonzero"};
+isnt($evicted_nonzero, "0", "check evicted_nonzero");

0 comments on commit 6beee74

Please sign in to comment.