public
Description: This is where my memcached work lives before svn munges the changes.
Homepage: http://www.danga.com/memcached/
Clone URL: git://github.com/dustin/memcached.git
Search Repo:
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.


git-svn-id: http://code.sixapart.com/svn/memcached/trunk/server@740 
b0b603af-a30f-0410-a34e-baf09ae79d0b
dormando (author)
Sun Mar 02 21:08:36 -0800 2008
commit  5800f57352255391656cf0fbb6f80af03e9c75e5
tree    4aa0d63aabfd1d1cc17ad379c78fc78db2ad23ef
parent  424543b721e7d68536a982444ac7154d63b4d5c1
...
27
28
29
 
 
 
 
 
30
31
 
32
33
34
35
 
36
37
38
...
97
98
99
100
 
 
 
 
101
102
103
...
106
107
108
109
 
 
 
 
110
111
112
113
114
115
116
 
 
 
 
 
117
118
119
120
121
122
123
 
 
 
 
124
125
126
...
311
312
313
314
 
315
316
317
...
324
325
326
327
328
 
 
 
 
 
 
 
329
330
331
...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
...
104
105
106
 
107
108
109
110
111
112
113
...
116
117
118
 
119
120
121
122
123
124
125
 
 
 
 
126
127
128
129
130
131
132
133
134
135
136
 
137
138
139
140
141
142
143
...
328
329
330
 
331
332
333
334
...
341
342
343
 
 
344
345
346
347
348
349
350
351
352
353
0
@@ -27,12 +27,19 @@ static uint64_t get_cas_id();
0
 #define ITEM_UPDATE_INTERVAL 60
0
 
0
 #define LARGEST_ID 255
0
+typedef struct {
0
+ unsigned int evicted;
0
+ unsigned int outofmemory;
0
+} itemstats_t;
0
+
0
 static item *heads[LARGEST_ID];
0
 static item *tails[LARGEST_ID];
0
+static itemstats_t itemstats[LARGEST_ID];
0
 static unsigned int sizes[LARGEST_ID];
0
 
0
 void item_init(void) {
0
     int i;
0
+ memset(itemstats, 0, sizeof(itemstats_t) * LARGEST_ID);
0
     for(i = 0; i < LARGEST_ID; i++) {
0
         heads[i] = NULL;
0
         tails[i] = NULL;
0
@@ -97,7 +104,10 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
0
          * we're out of luck at this point...
0
          */
0
 
0
- if (settings.evict_to_free == 0) return NULL;
0
+ if (settings.evict_to_free == 0) {
0
+ itemstats[id].outofmemory++;
0
+ return NULL;
0
+ }
0
 
0
         /*
0
          * try to get one off the right LRU
0
@@ -106,21 +116,28 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
0
          * tries
0
          */
0
 
0
- if (tails[id] == 0) return NULL;
0
+ if (tails[id] == 0) {
0
+ itemstats[id].outofmemory++;
0
+ return NULL;
0
+ }
0
 
0
         for (search = tails[id]; tries > 0 && search != NULL; tries--, search=search->prev) {
0
             if (search->refcount == 0) {
0
- if (search->exptime == 0 || search->exptime > current_time) {
0
- STATS_LOCK();
0
- stats.evictions++;
0
- STATS_UNLOCK();
0
+ if (search->exptime == 0 || search->exptime > current_time) {
0
+ itemstats[id].evicted++;
0
+ STATS_LOCK();
0
+ stats.evictions++;
0
+ STATS_UNLOCK();
0
                 }
0
                 do_item_unlink(search);
0
                 break;
0
             }
0
         }
0
         it = slabs_alloc(ntotal, id);
0
- if (it == 0) return NULL;
0
+ if (it == 0) {
0
+ itemstats[id].outofmemory++;
0
+ return NULL;
0
+ }
0
     }
0
 
0
     assert(it->slabs_clsid == 0);
0
@@ -311,7 +328,7 @@ char *do_item_cachedump(const unsigned int slabs_clsid, const unsigned int limit
0
 }
0
 
0
 char *do_item_stats(int *bytes) {
0
- size_t bufleft = (size_t) LARGEST_ID * 80;
0
+ size_t bufleft = (size_t) LARGEST_ID * 160;
0
     char *buffer = malloc(bufleft);
0
     char *bufcurr = buffer;
0
     rel_time_t now = current_time;
0
@@ -324,8 +341,13 @@ char *do_item_stats(int *bytes) {
0
 
0
     for (i = 0; i < LARGEST_ID; i++) {
0
         if (tails[i] != NULL) {
0
- linelen = snprintf(bufcurr, bufleft, "STAT items:%d:number %u\r\nSTAT items:%d:age %u\r\n",
0
- i, sizes[i], i, now - tails[i]->time);
0
+ linelen = snprintf(bufcurr, bufleft,
0
+ "STAT items:%d:number %u\r\n"
0
+ "STAT items:%d:age %u\r\n"
0
+ "STAT items:%d:evicted %u\r\n"
0
+ "STAT items:%d:outofmemory %u\r\n",
0
+ i, sizes[i], i, now - tails[i]->time, i,
0
+ itemstats[i].evicted, i, itemstats[i].outofmemory);
0
             if (linelen + sizeof("END\r\n") < bufleft) {
0
                 bufcurr += linelen;
0
                 bufleft -= linelen;

Comments

    No one has commented yet.