Skip to content

Commit

Permalink
If you're really clever and set all of your items to never expire, yo…
Browse files Browse the repository at this point in the history
…ur evictions stat will skyrocket even when you have plenty of memory left. This added stat to the stats items command gives an extra window into how bad an eviction was without expressly looking at it.
  • Loading branch information
dormando authored and dustin committed Jan 3, 2009
1 parent ca90710 commit 7a2dd7a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions items.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static uint64_t get_cas_id();
#define LARGEST_ID 255
typedef struct {
unsigned int evicted;
rel_time_t evicted_time;
unsigned int outofmemory;
} itemstats_t;

Expand Down Expand Up @@ -124,6 +125,7 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
if (search->refcount == 0) {
if (search->exptime == 0 || search->exptime > current_time) {
itemstats[id].evicted++;
itemstats[id].evicted_time = current_time - search->time;
STATS_LOCK();
stats.evictions++;
STATS_UNLOCK();
Expand Down Expand Up @@ -335,7 +337,7 @@ char *do_item_stats(int *bytes, uint32_t (*add_stats)(char *buf,
const char *key, const char *val, const uint16_t klen,
const uint32_t vlen), bool bin_prot) {

size_t bufleft = (size_t) LARGEST_ID * 160;
size_t bufleft = (size_t) LARGEST_ID * 240;
char *buffer = malloc(bufleft);
char *bufcurr = buffer;
rel_time_t now = current_time;
Expand Down Expand Up @@ -373,6 +375,12 @@ char *do_item_stats(int *bytes, uint32_t (*add_stats)(char *buf,
linelen += nbytes;
bufcurr += nbytes;

sprintf(key, "%d:evicted_time", i);
sprintf(val, "%u", itemstats[i].evicted_time);
nbytes = add_stats(bufcurr, key, val, strlen(key), strlen(val));
linelen += nbytes;
bufcurr += nbytes;

sprintf(key, "%d:outofmemory", i);
sprintf(val, "%u", itemstats[i].outofmemory);
nbytes = add_stats(bufcurr, key, val, strlen(key), strlen(val));
Expand All @@ -391,9 +399,12 @@ char *do_item_stats(int *bytes, uint32_t (*add_stats)(char *buf,
"STAT items:%d:number %u\r\n"
"STAT items:%d:age %u\r\n"
"STAT items:%d:evicted %u\r\n"
"STAT items:%d:evicted_time %u\r\n"
"STAT items:%d:outofmemory %u\r\n",
i, sizes[i], i, now - tails[i]->time, i,
itemstats[i].evicted, i, itemstats[i].outofmemory);
i, sizes[i], i, now - tails[i]->time,
i, itemstats[i].evicted,
i, itemstats[i].evicted_time,
i, itemstats[i].outofmemory);

if (linelen + sizeof("END\r\n") < bufleft) {
bufcurr += linelen;
Expand Down

0 comments on commit 7a2dd7a

Please sign in to comment.