summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2017-05-08 15:17:23 -0700
committerdormando <dormando@rydia.net>2017-06-04 13:26:36 -0700
commit1a8373c9b2eb3fc23cdd160c0a57728dd1c25497 (patch)
tree4d8a310cff3743834d9cdd6564cb30f2e924f2f7
parent7de9c6cf9991ae8885646fa6b7abb5c692a1efab (diff)
downloadmemcached-1a8373c9b2eb3fc23cdd160c0a57728dd1c25497.tar.gz
per-LRU hits breakdown
no actual speed loss. emulate the slab_stats "get_hits" by totalling up the per-LRU get_hits. could sub-LRU many stats but should use a different command/interface for that.
-rw-r--r--doc/protocol.txt4
-rw-r--r--items.c32
-rw-r--r--memcached.c4
-rw-r--r--memcached.h1
-rw-r--r--thread.c9
5 files changed, 48 insertions, 2 deletions
diff --git a/doc/protocol.txt b/doc/protocol.txt
index d3652d6..ca13f1b 100644
--- a/doc/protocol.txt
+++ b/doc/protocol.txt
@@ -865,6 +865,10 @@ moves_within_lru Number of times active items were bumped within
HOT or WARM.
direct_reclaims Number of times worker threads had to directly pull LRU
tails to find memory for a new item.
+hits_to_hot
+hits_to_warm
+hits_to_cold
+hits_to_temp Number of get_hits to each sub-LRU.
Note this will only display information about slabs which exist, so an empty
cache will return an empty set.
diff --git a/items.c b/items.c
index 556ba5a..f3db9e8 100644
--- a/items.c
+++ b/items.c
@@ -39,6 +39,10 @@ typedef struct {
uint64_t moves_to_warm;
uint64_t moves_within_lru;
uint64_t direct_reclaims;
+ uint64_t hits_to_hot;
+ uint64_t hits_to_warm;
+ uint64_t hits_to_cold;
+ uint64_t hits_to_temp;
rel_time_t evicted_time;
} itemstats_t;
@@ -663,6 +667,8 @@ void item_stats_totals(ADD_STAT add_stats, void *c) {
}
void item_stats(ADD_STAT add_stats, void *c) {
+ struct thread_stats thread_stats;
+ threadlocal_stats_aggregate(&thread_stats);
itemstats_t totals;
int n;
for (n = 0; n < MAX_NUMBER_OF_SLAB_CLASSES; n++) {
@@ -707,6 +713,20 @@ void item_stats(ADD_STAT add_stats, void *c) {
}
if (lru_type_map[x] == COLD_LRU)
totals.evicted_time = itemstats[i].evicted_time;
+ switch (lru_type_map[x]) {
+ case HOT_LRU:
+ totals.hits_to_hot = thread_stats.lru_hits[i];
+ break;
+ case WARM_LRU:
+ totals.hits_to_warm = thread_stats.lru_hits[i];
+ break;
+ case COLD_LRU:
+ totals.hits_to_cold = thread_stats.lru_hits[i];
+ break;
+ case TEMP_LRU:
+ totals.hits_to_temp = thread_stats.lru_hits[i];
+ break;
+ }
pthread_mutex_unlock(&lru_locks[i]);
}
if (size == 0)
@@ -758,6 +778,18 @@ void item_stats(ADD_STAT add_stats, void *c) {
"%llu", (unsigned long long)totals.moves_within_lru);
APPEND_NUM_FMT_STAT(fmt, n, "direct_reclaims",
"%llu", (unsigned long long)totals.direct_reclaims);
+ APPEND_NUM_FMT_STAT(fmt, n, "hits_to_hot",
+ "%llu", (unsigned long long)totals.hits_to_hot);
+
+ APPEND_NUM_FMT_STAT(fmt, n, "hits_to_warm",
+ "%llu", (unsigned long long)totals.hits_to_warm);
+
+ APPEND_NUM_FMT_STAT(fmt, n, "hits_to_cold",
+ "%llu", (unsigned long long)totals.hits_to_cold);
+
+ APPEND_NUM_FMT_STAT(fmt, n, "hits_to_temp",
+ "%llu", (unsigned long long)totals.hits_to_temp);
+
}
}
diff --git a/memcached.c b/memcached.c
index e31de8a..2f1c4c1 100644
--- a/memcached.c
+++ b/memcached.c
@@ -1499,7 +1499,7 @@ static void process_bin_get_or_touch(conn *c) {
c->thread->stats.slab_stats[ITEM_clsid(it)].touch_hits++;
} else {
c->thread->stats.get_cmds++;
- c->thread->stats.slab_stats[ITEM_clsid(it)].get_hits++;
+ c->thread->stats.lru_hits[it->slabs_clsid]++;
}
pthread_mutex_unlock(&c->thread->stats.mutex);
@@ -3398,7 +3398,7 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens,
/* item_get() has incremented it->refcount for us */
pthread_mutex_lock(&c->thread->stats.mutex);
- c->thread->stats.slab_stats[ITEM_clsid(it)].get_hits++;
+ c->thread->stats.lru_hits[it->slabs_clsid]++;
c->thread->stats.get_cmds++;
pthread_mutex_unlock(&c->thread->stats.mutex);
*(c->ilist + i) = it;
diff --git a/memcached.h b/memcached.h
index 65d8f60..9ef3e53 100644
--- a/memcached.h
+++ b/memcached.h
@@ -274,6 +274,7 @@ struct thread_stats {
THREAD_STATS_FIELDS
#undef X
struct slab_stats slab_stats[MAX_NUMBER_OF_SLAB_CLASSES];
+ uint64_t lru_hits[POWER_LARGEST];
};
/**
diff --git a/thread.c b/thread.c
index 0656cb5..646b235 100644
--- a/thread.c
+++ b/thread.c
@@ -641,6 +641,8 @@ void threadlocal_stats_reset(void) {
memset(&threads[ii].stats.slab_stats, 0,
sizeof(threads[ii].stats.slab_stats));
+ memset(&threads[ii].stats.lru_hits, 0,
+ sizeof(uint64_t) * POWER_LARGEST);
pthread_mutex_unlock(&threads[ii].stats.mutex);
}
@@ -666,6 +668,13 @@ void threadlocal_stats_aggregate(struct thread_stats *stats) {
#undef X
}
+ for (sid = 0; sid < POWER_LARGEST; sid++) {
+ stats->lru_hits[sid] +=
+ threads[ii].stats.lru_hits[sid];
+ stats->slab_stats[CLEAR_LRU(sid)].get_hits +=
+ threads[ii].stats.lru_hits[sid];
+ }
+
pthread_mutex_unlock(&threads[ii].stats.mutex);
}
}