diff options
author | Dustin Sallings <dustin@spy.net> | 2009-03-06 17:27:05 -0800 |
---|---|---|
committer | Dustin Sallings <dustin@spy.net> | 2009-03-06 20:54:26 -0800 |
commit | 25b5189c6adfb2c44ec6a958ac521fba32333c89 (patch) | |
tree | 5b3e502925de4470daa2311ce028ec68c8309d8a | |
parent | 7173856af5532b7dfccefe38fca16f7e3ea94a89 (diff) | |
download | memcached-25b5189c6adfb2c44ec6a958ac521fba32333c89.tar.gz |
Push hit and set stats down into per-slab stats.
-rw-r--r-- | memcached.c | 32 | ||||
-rw-r--r-- | memcached.h | 21 | ||||
-rw-r--r-- | thread.c | 36 |
3 files changed, 62 insertions, 27 deletions
diff --git a/memcached.c b/memcached.c index cfa1541..3f3eabb 100644 --- a/memcached.c +++ b/memcached.c @@ -821,7 +821,7 @@ static void complete_nread_ascii(conn *c) { enum store_item_type ret; pthread_mutex_lock(&c->thread->stats.mutex); - c->thread->stats.set_cmds++; + c->thread->stats.slab_stats[it->slabs_clsid].set_cmds++; pthread_mutex_unlock(&c->thread->stats.mutex); if (strncmp(ITEM_data(it) + it->nbytes - 2, "\r\n", 2) != 0) { @@ -1109,7 +1109,7 @@ static void complete_update_bin(conn *c) { item *it = c->item; pthread_mutex_lock(&c->thread->stats.mutex); - c->thread->stats.set_cmds++; + c->thread->stats.slab_stats[it->slabs_clsid].set_cmds++; pthread_mutex_unlock(&c->thread->stats.mutex); /* We don't actually receive the trailing two characters in the bin @@ -1195,7 +1195,7 @@ static void process_bin_get(conn *c) { pthread_mutex_lock(&c->thread->stats.mutex); c->thread->stats.get_cmds++; - c->thread->stats.get_hits++; + c->thread->stats.slab_stats[it->slabs_clsid].get_hits++; pthread_mutex_unlock(&c->thread->stats.mutex); MEMCACHED_COMMAND_GET(c->sfd, ITEM_key(it), it->nkey, @@ -2073,6 +2073,8 @@ static char *server_stats(uint32_t (*add_stats)(char *buf, const char *key, struct thread_stats thread_stats; threadlocal_stats_aggregate(&thread_stats); + struct slab_stats slab_stats; + slab_stats_aggregate(&thread_stats, &slab_stats); #ifndef WIN32 struct rusage usage; @@ -2147,12 +2149,12 @@ static char *server_stats(uint32_t (*add_stats)(char *buf, const char *key, pos += nbytes; *buflen += nbytes; - vlen = sprintf(val, "%llu", (unsigned long long)thread_stats.set_cmds); + vlen = sprintf(val, "%llu", (unsigned long long)slab_stats.set_cmds); nbytes = add_stats(pos, "cmd_set", strlen("cmd_set"), val, vlen, (void *)c); pos += nbytes; *buflen += nbytes; - vlen = sprintf(val, "%llu", (unsigned long long)thread_stats.get_hits); + vlen = sprintf(val, "%llu", (unsigned long long)slab_stats.get_hits); nbytes = add_stats(pos, "get_hits", strlen("get_hits"), val, vlen, (void *)c); pos += nbytes; @@ -2333,15 +2335,17 @@ static void process_stat(conn *c, token_t *tokens, const size_t ntokens) { static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens, bool return_cas) { char *key; size_t nkey; - int i = 0; + int i = 0, sid = 0; item *it; token_t *key_token = &tokens[KEY_TOKEN]; char *suffix; int stats_get_cmds = 0; - int stats_get_hits = 0; int stats_get_misses = 0; + int stats_get_hits[MAX_NUMBER_OF_SLAB_CLASSES]; assert(c != NULL); + memset(&stats_get_hits, 0, sizeof(stats_get_hits)); + do { while(key_token->length != 0) { @@ -2351,8 +2355,10 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens, if(nkey > KEY_MAX_LENGTH) { pthread_mutex_lock(&c->thread->stats.mutex); c->thread->stats.get_cmds += stats_get_cmds; - c->thread->stats.get_hits += stats_get_hits; c->thread->stats.get_misses += stats_get_misses; + for(sid = 0; sid < MAX_NUMBER_OF_SLAB_CLASSES; sid++) { + c->thread->stats.slab_stats[sid].get_hits += stats_get_hits[sid]; + } pthread_mutex_unlock(&c->thread->stats.mutex); out_string(c, "CLIENT_ERROR bad command line format"); return; @@ -2404,8 +2410,10 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens, if (suffix == NULL) { pthread_mutex_lock(&c->thread->stats.mutex); c->thread->stats.get_cmds += stats_get_cmds; - c->thread->stats.get_hits += stats_get_hits; c->thread->stats.get_misses += stats_get_misses; + for(sid = 0; sid < MAX_NUMBER_OF_SLAB_CLASSES; sid++) { + c->thread->stats.slab_stats[sid].get_hits += stats_get_hits[sid]; + } pthread_mutex_unlock(&c->thread->stats.mutex); out_string(c, "SERVER_ERROR out of memory making CAS suffix"); item_remove(it); @@ -2441,7 +2449,7 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens, fprintf(stderr, ">%d sending key %s\n", c->sfd, ITEM_key(it)); /* item_get() has incremented it->refcount for us */ - stats_get_hits++; + stats_get_hits[it->slabs_clsid]++; item_update(it); *(c->ilist + i) = it; i++; @@ -2491,8 +2499,10 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens, pthread_mutex_lock(&c->thread->stats.mutex); c->thread->stats.get_cmds += stats_get_cmds; - c->thread->stats.get_hits += stats_get_hits; c->thread->stats.get_misses += stats_get_misses; + for(sid = 0; sid < MAX_NUMBER_OF_SLAB_CLASSES; sid++) { + c->thread->stats.slab_stats[sid].get_hits += stats_get_hits[sid]; + } pthread_mutex_unlock(&c->thread->stats.mutex); return; diff --git a/memcached.h b/memcached.h index 5d521bf..fa845ab 100644 --- a/memcached.h +++ b/memcached.h @@ -66,14 +66,19 @@ /** Time relative to server start. Smaller than time_t on 64-bit systems. */ typedef unsigned int rel_time_t; +/* Stats stored per slab (and per thread). */ +struct slab_stats { + uint64_t set_cmds; + uint64_t get_hits; +}; + struct thread_stats { - pthread_mutex_t mutex; - uint64_t get_cmds; - uint64_t set_cmds; - uint64_t get_hits; - uint64_t get_misses; - uint64_t bytes_read; - uint64_t bytes_written; + pthread_mutex_t mutex; + uint64_t get_cmds; + uint64_t get_misses; + uint64_t bytes_read; + uint64_t bytes_written; + struct slab_stats slab_stats[MAX_NUMBER_OF_SLAB_CLASSES]; }; struct stats { @@ -370,7 +375,7 @@ void STATS_LOCK(void); void STATS_UNLOCK(void); void threadlocal_stats_reset(void); void threadlocal_stats_aggregate(struct thread_stats *stats); - +void slab_stats_aggregate(struct thread_stats *stats, struct slab_stats *out); enum store_item_type store_item(item *item, int comm, conn *c); @@ -530,45 +530,65 @@ void STATS_UNLOCK() { } void threadlocal_stats_reset(void) { - int ii; + int ii, sid; for (ii = 0; ii < settings.num_threads; ++ii) { pthread_mutex_lock(&threads[ii].stats.mutex); threads[ii].stats.get_cmds = 0; - threads[ii].stats.set_cmds = 0; - threads[ii].stats.get_hits = 0; threads[ii].stats.get_misses = 0; threads[ii].stats.bytes_read = 0; threads[ii].stats.bytes_written = 0; + for(sid = 0; sid < MAX_NUMBER_OF_SLAB_CLASSES; sid++) { + threads[ii].stats.slab_stats[sid].set_cmds = 0; + threads[ii].stats.slab_stats[sid].get_hits = 0; + } + pthread_mutex_unlock(&threads[ii].stats.mutex); } } void threadlocal_stats_aggregate(struct thread_stats *stats) { - int ii; + int ii, sid; /* The struct contains a mutex, so I should probably not memset it.. */ stats->get_cmds = 0; - stats->set_cmds = 0; - stats->get_hits = 0; stats->get_misses = 0; stats->bytes_written = 0; stats->bytes_read = 0; + memset(stats->slab_stats, 0, + sizeof(struct slab_stats) * MAX_NUMBER_OF_SLAB_CLASSES); + for (ii = 0; ii < settings.num_threads; ++ii) { pthread_mutex_lock(&threads[ii].stats.mutex); stats->get_cmds += threads[ii].stats.get_cmds; - stats->set_cmds += threads[ii].stats.set_cmds; - stats->get_hits += threads[ii].stats.get_hits; stats->get_misses += threads[ii].stats.get_misses; stats->bytes_read += threads[ii].stats.bytes_read; stats->bytes_written += threads[ii].stats.bytes_written; + for (sid = 0; sid < MAX_NUMBER_OF_SLAB_CLASSES; sid++) { + stats->slab_stats[sid].set_cmds += + threads[ii].stats.slab_stats[sid].set_cmds; + stats->slab_stats[sid].get_hits += + threads[ii].stats.slab_stats[sid].get_hits; + } + pthread_mutex_unlock(&threads[ii].stats.mutex); } } +void slab_stats_aggregate(struct thread_stats *stats, struct slab_stats *out) { + int sid; + + out->set_cmds = 0; + out->get_hits = 0; + + for (sid = 0; sid < MAX_NUMBER_OF_SLAB_CLASSES; sid++) { + out->set_cmds += stats->slab_stats[sid].set_cmds; + out->get_hits += stats->slab_stats[sid].get_hits; + } +} /* * Initializes the thread subsystem, creating various worker threads. |