diff options
author | Trond Norbye <Trond.Norbye@sun.com> | 2009-03-06 12:26:54 +0100 |
---|---|---|
committer | Trond Norbye <Trond.Norbye@sun.com> | 2009-03-06 12:26:54 +0100 |
commit | e2da37827dcae8f7fd35f9a3176b97a4b735af99 (patch) | |
tree | 782d996f4cf8e2ef95b8124ac41b9633dfbd63d3 | |
parent | d9220d64213c7ff9ccd492abeb9f13076dfe9192 (diff) | |
download | memcached-e2da37827dcae8f7fd35f9a3176b97a4b735af99.tar.gz |
Moved bytes_read and bytes_written to threadlocal stats
-rw-r--r-- | memcached.c | 37 | ||||
-rw-r--r-- | memcached.h | 4 | ||||
-rw-r--r-- | thread.c | 6 |
3 files changed, 26 insertions, 21 deletions
diff --git a/memcached.c b/memcached.c index ec01c94..a147df5 100644 --- a/memcached.c +++ b/memcached.c @@ -141,7 +141,7 @@ static rel_time_t realtime(const time_t exptime) { static void stats_init(void) { stats.curr_items = stats.total_items = stats.curr_conns = stats.total_conns = stats.conn_structs = 0; stats.evictions = 0; - stats.curr_bytes = stats.bytes_read = stats.bytes_written = 0; + stats.curr_bytes = 0; /* make the time we started always be 2 seconds before we really did, so time(0) - time.started is never zero. if so, things @@ -155,7 +155,6 @@ static void stats_reset(void) { STATS_LOCK(); stats.total_items = stats.total_conns = 0; stats.evictions = 0; - stats.bytes_read = stats.bytes_written = 0; stats_prefix_clear(); STATS_UNLOCK(); threadlocal_stats_reset(); @@ -2167,13 +2166,13 @@ static char *server_stats(uint32_t (*add_stats)(char *buf, const char *key, pos += nbytes; *buflen += nbytes; - vlen = sprintf(val, "%llu", (unsigned long long)stats.bytes_read); + vlen = sprintf(val, "%llu", (unsigned long long)thread_stats.bytes_read); nbytes = add_stats(pos, "bytes_read", strlen("bytes_read"), val, vlen, (void *)c); pos += nbytes; *buflen += nbytes; - vlen = sprintf(val, "%llu", (unsigned long long)stats.bytes_written); + vlen = sprintf(val, "%llu", (unsigned long long)thread_stats.bytes_written); nbytes = add_stats(pos, "bytes_written", strlen("bytes_written"), val, vlen, (void *)c); pos += nbytes; @@ -2986,9 +2985,9 @@ static int try_read_udp(conn *c) { 0, &c->request_addr, &c->request_addr_size); if (res > 8) { unsigned char *buf = (unsigned char *)c->rbuf; - STATS_LOCK(); - stats.bytes_read += res; - STATS_UNLOCK(); + pthread_mutex_lock(&c->thread->stats.mutex); + c->thread->stats.bytes_read += res; + pthread_mutex_unlock(&c->thread->stats.mutex); /* Beginning of UDP packet is the request ID; save it. */ c->request_id = buf[0] * 256 + buf[1]; @@ -3050,9 +3049,9 @@ static int try_read_network(conn *c) { int avail = c->rsize - c->rbytes; res = read(c->sfd, c->rbuf + c->rbytes, avail); if (res > 0) { - STATS_LOCK(); - stats.bytes_read += res; - STATS_UNLOCK(); + pthread_mutex_lock(&c->thread->stats.mutex); + c->thread->stats.bytes_read += res; + pthread_mutex_unlock(&c->thread->stats.mutex); gotdata = 1; c->rbytes += res; if (res == avail) { @@ -3136,9 +3135,9 @@ static int transmit(conn *c) { res = sendmsg(c->sfd, m, 0); if (res > 0) { - STATS_LOCK(); - stats.bytes_written += res; - STATS_UNLOCK(); + pthread_mutex_lock(&c->thread->stats.mutex); + c->thread->stats.bytes_written += res; + pthread_mutex_unlock(&c->thread->stats.mutex); /* We've written some of the data. Remove the completed iovec entries from the list of pending writes. */ @@ -3291,9 +3290,9 @@ static void drive_machine(conn *c) { /* now try reading from the socket */ res = read(c->sfd, c->ritem, c->rlbytes); if (res > 0) { - STATS_LOCK(); - stats.bytes_read += res; - STATS_UNLOCK(); + pthread_mutex_lock(&c->thread->stats.mutex); + c->thread->stats.bytes_read += res; + pthread_mutex_unlock(&c->thread->stats.mutex); if (c->rcurr == c->ritem) { c->rcurr += res; } @@ -3340,9 +3339,9 @@ static void drive_machine(conn *c) { /* now try reading from the socket */ res = read(c->sfd, c->rbuf, c->rsize > c->sbytes ? c->sbytes : c->rsize); if (res > 0) { - STATS_LOCK(); - stats.bytes_read += res; - STATS_UNLOCK(); + pthread_mutex_lock(&c->thread->stats.mutex); + c->thread->stats.bytes_read += res; + pthread_mutex_unlock(&c->thread->stats.mutex); c->sbytes -= res; break; } diff --git a/memcached.h b/memcached.h index 7b527f8..4a4964e 100644 --- a/memcached.h +++ b/memcached.h @@ -65,6 +65,8 @@ struct thread_stats { uint64_t set_cmds; uint64_t get_hits; uint64_t get_misses; + uint64_t bytes_read; + uint64_t bytes_written; }; struct stats { @@ -76,8 +78,6 @@ struct stats { unsigned int total_conns; unsigned int conn_structs; uint64_t evictions; - uint64_t bytes_read; - uint64_t bytes_written; }; #define MAX_VERBOSITY_LEVEL 2 @@ -540,6 +540,8 @@ void threadlocal_stats_reset(void) { 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; pthread_mutex_unlock(&threads[ii].stats.mutex); } @@ -552,6 +554,8 @@ void threadlocal_stats_aggregate(struct thread_stats *stats) { stats->set_cmds = 0; stats->get_hits = 0; stats->get_misses = 0; + stats->bytes_written = 0; + stats->bytes_read = 0; for (ii = 0; ii < settings.num_threads; ++ii) { pthread_mutex_lock(&threads[ii].stats.mutex); @@ -560,6 +564,8 @@ void threadlocal_stats_aggregate(struct thread_stats *stats) { 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; pthread_mutex_unlock(&threads[ii].stats.mutex); } |