Skip to content

Commit

Permalink
per-stat-class tracking of evictions and out of memory conditions.
Browse files Browse the repository at this point in the history
We have an evictions stat, but it doesn't tell us if a particular slab class is hot. Now you can tell.
Can also tell if a particular class is in a weird state if the out of memory errors are high.

Also handy if you're using -M to disable the LRU.


git-svn-id: http://code.sixapart.com/svn/memcached/trunk/server@740 b0b603af-a30f-0410-a34e-baf09ae79d0b
  • Loading branch information
dormando committed Mar 3, 2008
1 parent 424543b commit 5800f57
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions items.c
Expand Up @@ -27,12 +27,19 @@ static uint64_t get_cas_id();
#define ITEM_UPDATE_INTERVAL 60

#define LARGEST_ID 255
typedef struct {
unsigned int evicted;
unsigned int outofmemory;
} itemstats_t;

static item *heads[LARGEST_ID];
static item *tails[LARGEST_ID];
static itemstats_t itemstats[LARGEST_ID];
static unsigned int sizes[LARGEST_ID];

void item_init(void) {
int i;
memset(itemstats, 0, sizeof(itemstats_t) * LARGEST_ID);
for(i = 0; i < LARGEST_ID; i++) {
heads[i] = NULL;
tails[i] = NULL;
Expand Down Expand Up @@ -97,7 +104,10 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
* we're out of luck at this point...
*/

if (settings.evict_to_free == 0) return NULL;
if (settings.evict_to_free == 0) {
itemstats[id].outofmemory++;
return NULL;
}

/*
* try to get one off the right LRU
Expand All @@ -106,21 +116,28 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
* tries
*/

if (tails[id] == 0) return NULL;
if (tails[id] == 0) {
itemstats[id].outofmemory++;
return NULL;
}

for (search = tails[id]; tries > 0 && search != NULL; tries--, search=search->prev) {
if (search->refcount == 0) {
if (search->exptime == 0 || search->exptime > current_time) {
STATS_LOCK();
stats.evictions++;
STATS_UNLOCK();
if (search->exptime == 0 || search->exptime > current_time) {
itemstats[id].evicted++;
STATS_LOCK();
stats.evictions++;
STATS_UNLOCK();
}
do_item_unlink(search);
break;
}
}
it = slabs_alloc(ntotal, id);
if (it == 0) return NULL;
if (it == 0) {
itemstats[id].outofmemory++;
return NULL;
}
}

assert(it->slabs_clsid == 0);
Expand Down Expand Up @@ -311,7 +328,7 @@ char *do_item_cachedump(const unsigned int slabs_clsid, const unsigned int limit
}

char *do_item_stats(int *bytes) {
size_t bufleft = (size_t) LARGEST_ID * 80;
size_t bufleft = (size_t) LARGEST_ID * 160;
char *buffer = malloc(bufleft);
char *bufcurr = buffer;
rel_time_t now = current_time;
Expand All @@ -324,8 +341,13 @@ char *do_item_stats(int *bytes) {

for (i = 0; i < LARGEST_ID; i++) {
if (tails[i] != NULL) {
linelen = snprintf(bufcurr, bufleft, "STAT items:%d:number %u\r\nSTAT items:%d:age %u\r\n",
i, sizes[i], i, now - tails[i]->time);
linelen = snprintf(bufcurr, bufleft,
"STAT items:%d:number %u\r\n"
"STAT items:%d:age %u\r\n"
"STAT items:%d:evicted %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);
if (linelen + sizeof("END\r\n") < bufleft) {
bufcurr += linelen;
bufleft -= linelen;
Expand Down

0 comments on commit 5800f57

Please sign in to comment.