Changeset 740

Show
Ignore:
Timestamp:
03/03/08 05:08:36 (6 months ago)
Author:
dormando
Message:

per-stat-class tracking of evictions and out of memory conditions.
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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/server/items.c

    r739 r740  
    2828 
    2929#define LARGEST_ID 255 
     30typedef struct { 
     31    unsigned int evicted; 
     32    unsigned int outofmemory; 
     33} itemstats_t; 
     34 
    3035static item *heads[LARGEST_ID]; 
    3136static item *tails[LARGEST_ID]; 
     37static itemstats_t itemstats[LARGEST_ID]; 
    3238static unsigned int sizes[LARGEST_ID]; 
    3339 
    3440void item_init(void) { 
    3541    int i; 
     42    memset(itemstats, 0, sizeof(itemstats_t) * LARGEST_ID); 
    3643    for(i = 0; i < LARGEST_ID; i++) { 
    3744        heads[i] = NULL; 
     
    98105         */ 
    99106 
    100         if (settings.evict_to_free == 0) return NULL; 
     107        if (settings.evict_to_free == 0) { 
     108            itemstats[id].outofmemory++; 
     109            return NULL; 
     110        } 
    101111 
    102112        /* 
     
    107117         */ 
    108118 
    109         if (tails[id] == 0) return NULL; 
     119        if (tails[id] == 0) { 
     120            itemstats[id].outofmemory++; 
     121            return NULL; 
     122        } 
    110123 
    111124        for (search = tails[id]; tries > 0 && search != NULL; tries--, search=search->prev) { 
    112125            if (search->refcount == 0) { 
    113                if (search->exptime == 0 || search->exptime > current_time) { 
    114                        STATS_LOCK(); 
    115                        stats.evictions++; 
    116                        STATS_UNLOCK(); 
     126                if (search->exptime == 0 || search->exptime > current_time) { 
     127                    itemstats[id].evicted++; 
     128                    STATS_LOCK(); 
     129                    stats.evictions++; 
     130                    STATS_UNLOCK(); 
    117131                } 
    118132                do_item_unlink(search); 
     
    121135        } 
    122136        it = slabs_alloc(ntotal, id); 
    123         if (it == 0) return NULL; 
     137        if (it == 0) { 
     138            itemstats[id].outofmemory++; 
     139            return NULL; 
     140        } 
    124141    } 
    125142 
     
    312329 
    313330char *do_item_stats(int *bytes) { 
    314     size_t bufleft = (size_t) LARGEST_ID * 80; 
     331    size_t bufleft = (size_t) LARGEST_ID * 160; 
    315332    char *buffer = malloc(bufleft); 
    316333    char *bufcurr = buffer; 
     
    325342    for (i = 0; i < LARGEST_ID; i++) { 
    326343        if (tails[i] != NULL) { 
    327             linelen = snprintf(bufcurr, bufleft, "STAT items:%d:number %u\r\nSTAT items:%d:age %u\r\n", 
    328                                i, sizes[i], i, now - tails[i]->time); 
     344            linelen = snprintf(bufcurr, bufleft, 
     345                "STAT items:%d:number %u\r\n" 
     346                "STAT items:%d:age %u\r\n" 
     347                "STAT items:%d:evicted %u\r\n" 
     348                "STAT items:%d:outofmemory %u\r\n", 
     349                    i, sizes[i], i, now - tails[i]->time, i, 
     350                    itemstats[i].evicted, i, itemstats[i].outofmemory); 
    329351            if (linelen + sizeof("END\r\n") < bufleft) { 
    330352                bufcurr += linelen;