Skip to content

Commit

Permalink
new per-slab item stat evicted_nonzero
Browse files Browse the repository at this point in the history
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
dormando authored and dustin committed Oct 7, 2009
1 parent c94c940 commit 6beee74
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/protocol.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions items.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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",
Expand Down
31 changes: 31 additions & 0 deletions t/evictions.t
Original file line number Diff line number Diff line change
@@ -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.