diff options
author | dormando <dormando@rydia.net> | 2009-03-25 00:55:19 -0700 |
---|---|---|
committer | Dustin Sallings <dustin@spy.net> | 2009-03-30 14:06:31 -0700 |
commit | 534466e0dcbc7e385585ebd456a35d0beded2f47 (patch) | |
tree | 01f5045ea4e4bf1ad0f97c353c844005c1abbd42 | |
parent | b8d997e532ffbb562d01f82bc19e09dd5f106195 (diff) | |
download | memcached-534466e0dcbc7e385585ebd456a35d0beded2f47.tar.gz |
add a cmd_flush stat
shouldn't add much lock contention for just this.
I want to add this one stat (mayb a few more?) since it's happened more than
once that folks think memcached is broken when a cron or something is calling
'flush_all' once a minute.
-rw-r--r-- | memcached.c | 8 | ||||
-rw-r--r-- | memcached.h | 5 | ||||
-rwxr-xr-x | t/stats.t | 15 | ||||
-rw-r--r-- | thread.c | 3 |
4 files changed, 27 insertions, 4 deletions
diff --git a/memcached.c b/memcached.c index 7666511..0464825 100644 --- a/memcached.c +++ b/memcached.c @@ -159,7 +159,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.get_cmds = stats.set_cmds = stats.get_hits = stats.get_misses = stats.evictions = 0; stats.curr_bytes = 0; /* make the time we started always be 2 seconds before we really @@ -2209,6 +2209,7 @@ static char *server_stats(uint32_t (*add_stats)(char *buf, const char *key, APPEND_STAT("connection_structures", "%u", stats.conn_structs); APPEND_STAT("cmd_get", "%llu", (unsigned long long)thread_stats.get_cmds); APPEND_STAT("cmd_set", "%llu", (unsigned long long)slab_stats.set_cmds); + APPEND_STAT("cmd_flush", "%llu", (unsigned long long)thread_stats.flush_cmds); APPEND_STAT("get_hits", "%llu", (unsigned long long)slab_stats.get_hits); APPEND_STAT("get_misses", "%llu", (unsigned long long)thread_stats.get_misses); APPEND_STAT("delete_misses", "%llu", (unsigned long long)thread_stats.delete_misses); @@ -2223,6 +2224,7 @@ static char *server_stats(uint32_t (*add_stats)(char *buf, const char *key, APPEND_STAT("bytes_read", "%llu", (unsigned long long)thread_stats.bytes_read); APPEND_STAT("bytes_written", "%llu", (unsigned long long)thread_stats.bytes_written); APPEND_STAT("limit_maxbytes", "%llu", (unsigned long long)settings.maxbytes); + APPEND_STAT("bytes_written", "%llu", (unsigned long long)thread_stats.bytes_written); APPEND_STAT("threads", "%d", settings.num_threads); if(*buflen > 0 && (buf = malloc(*buflen)) == NULL) { @@ -2916,6 +2918,10 @@ static void process_command(conn *c, char *command) { set_noreply_maybe(c, tokens, ntokens); + STATS_LOCK(); + c->thread->stats.flush_cmds++; + STATS_UNLOCK(); + if(ntokens == (c->noreply ? 3 : 2)) { settings.oldest_live = current_time - 1; item_flush_expired(); diff --git a/memcached.h b/memcached.h index 2692ca1..b6c4113 100644 --- a/memcached.h +++ b/memcached.h @@ -91,6 +91,7 @@ struct thread_stats { uint64_t cas_misses; uint64_t bytes_read; uint64_t bytes_written; + uint64_t flush_cmds; struct slab_stats slab_stats[MAX_NUMBER_OF_SLAB_CLASSES]; }; @@ -102,6 +103,10 @@ struct stats { unsigned int curr_conns; unsigned int total_conns; unsigned int conn_structs; + uint64_t get_cmds; + uint64_t set_cmds; + uint64_t get_hits; + uint64_t get_misses; uint64_t evictions; }; @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; -use Test::More tests => 89; +use Test::More tests => 91; use FindBin qw($Bin); use lib "$Bin/lib"; use MemcachedTest; @@ -25,6 +25,7 @@ my $sock = $server->sock; ## STAT curr_connections 1 ## STAT total_connections 2 ## STAT connection_structures 2 +## STAT cmd_flush 0 ## STAT cmd_get 0 ## STAT cmd_set 0 ## STAT get_hits 0 @@ -46,10 +47,12 @@ my $sock = $server->sock; my $stats = mem_stats($sock); # Test number of keys -is(scalar(keys(%$stats)), 31, "31 stats values"); +is(scalar(keys(%$stats)), 32, "32 stats values"); # Test initial state -foreach my $key (qw(curr_items total_items bytes cmd_get cmd_set get_hits evictions get_misses bytes_written delete_hits delete_misses incr_hits incr_misses decr_hits decr_misses)) { +foreach my $key (qw(curr_items total_items bytes cmd_get cmd_set get_hits evictions get_misses + bytes_written delete_hits delete_misses incr_hits incr_misses decr_hits + decr_misses)) { is($stats->{$key}, 0, "initial $key is zero"); } @@ -171,3 +174,9 @@ is(0, $stats->{'cas_misses'}); is(0, $stats->{'cas_hits'}); is(0, $stats->{'cas_badval'}); is(0, $stats->{'evictions'}); + +print $sock "flush_all\r\n"; +is(scalar <$sock>, "OK\r\n", "flushed"); + +my $stats = mem_stats($sock); +is($stats->{cmd_flush}, 1, "after one flush cmd_flush is 1"); @@ -476,6 +476,7 @@ void threadlocal_stats_reset(void) { threads[ii].stats.cas_misses = 0; threads[ii].stats.bytes_read = 0; threads[ii].stats.bytes_written = 0; + threads[ii].stats.flush_cmds = 0; for(sid = 0; sid < MAX_NUMBER_OF_SLAB_CLASSES; sid++) { threads[ii].stats.slab_stats[sid].set_cmds = 0; @@ -502,6 +503,7 @@ void threadlocal_stats_aggregate(struct thread_stats *stats) { stats->cas_misses = 0; stats->bytes_written = 0; stats->bytes_read = 0; + stats->flush_cmds = 0; memset(stats->slab_stats, 0, sizeof(struct slab_stats) * MAX_NUMBER_OF_SLAB_CLASSES); @@ -517,6 +519,7 @@ void threadlocal_stats_aggregate(struct thread_stats *stats) { stats->cas_misses += threads[ii].stats.cas_misses; stats->bytes_read += threads[ii].stats.bytes_read; stats->bytes_written += threads[ii].stats.bytes_written; + stats->flush_cmds += threads[ii].stats.flush_cmds; for (sid = 0; sid < MAX_NUMBER_OF_SLAB_CLASSES; sid++) { stats->slab_stats[sid].set_cmds += |