summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDustin Sallings <dustin@spy.net>2009-03-06 20:52:57 -0800
committerDustin Sallings <dustin@spy.net>2009-03-06 21:02:27 -0800
commita77d12b0d8f6a49f33e6a5e0a7e420173750f0e6 (patch)
tree245b8b08ddc55ac9efb7c546e337fa4b208813aa
parente71ea432b9ccfbdd7dc52a01365ec06e91119154 (diff)
downloadmemcached-a77d12b0d8f6a49f33e6a5e0a7e420173750f0e6.tar.gz
Added stats for delete commands.
This includes both misses and per-slab hits.
-rw-r--r--memcached.c21
-rw-r--r--memcached.h2
-rw-r--r--slabs.c7
-rwxr-xr-xt/stats.t21
-rw-r--r--thread.c8
5 files changed, 57 insertions, 2 deletions
diff --git a/memcached.c b/memcached.c
index 3f3eabb..7c5bce9 100644
--- a/memcached.c
+++ b/memcached.c
@@ -2166,6 +2166,18 @@ 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.delete_misses);
+ nbytes = add_stats(pos, "delete_misses", strlen("delete_misses"), val, vlen,
+ (void *)c);
+ pos += nbytes;
+ *buflen += nbytes;
+
+ vlen = sprintf(val, "%llu", (unsigned long long)slab_stats.delete_hits);
+ nbytes = add_stats(pos, "delete_hits", strlen("delete_hits"), val, vlen,
+ (void *)c);
+ pos += nbytes;
+ *buflen += nbytes;
+
vlen = sprintf(val, "%llu", (unsigned long long)thread_stats.bytes_read);
nbytes = add_stats(pos, "bytes_read", strlen("bytes_read"), val, vlen,
(void *)c);
@@ -2700,10 +2712,19 @@ static void process_delete_command(conn *c, token_t *tokens, const size_t ntoken
it = item_get(key, nkey);
if (it) {
MEMCACHED_COMMAND_DELETE(c->sfd, ITEM_key(it), it->nkey);
+
+ pthread_mutex_lock(&c->thread->stats.mutex);
+ c->thread->stats.slab_stats[it->slabs_clsid].delete_hits++;
+ pthread_mutex_unlock(&c->thread->stats.mutex);
+
item_unlink(it);
item_remove(it); /* release our reference */
out_string(c, "DELETED");
} else {
+ pthread_mutex_lock(&c->thread->stats.mutex);
+ c->thread->stats.delete_misses++;
+ pthread_mutex_unlock(&c->thread->stats.mutex);
+
out_string(c, "NOT_FOUND");
}
}
diff --git a/memcached.h b/memcached.h
index fa845ab..d16d52f 100644
--- a/memcached.h
+++ b/memcached.h
@@ -70,12 +70,14 @@ typedef unsigned int rel_time_t;
struct slab_stats {
uint64_t set_cmds;
uint64_t get_hits;
+ uint64_t delete_hits;
};
struct thread_stats {
pthread_mutex_t mutex;
uint64_t get_cmds;
uint64_t get_misses;
+ uint64_t delete_misses;
uint64_t bytes_read;
uint64_t bytes_written;
struct slab_stats slab_stats[MAX_NUMBER_OF_SLAB_CLASSES];
diff --git a/slabs.c b/slabs.c
index 8faef57..360f285 100644
--- a/slabs.c
+++ b/slabs.c
@@ -455,6 +455,13 @@ static char *do_slabs_stats(uint32_t (*add_stats)(char *buf, const char *key,
linelen += nbytes;
bufcurr += nbytes;
+ sprintf(key, "%d:delete_hits", i);
+ sprintf(val, "%llu",
+ (unsigned long long)thread_stats.slab_stats[i].delete_hits);
+ nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
+ linelen += nbytes;
+ bufcurr += nbytes;
+
total++;
}
}
diff --git a/t/stats.t b/t/stats.t
index 222ebc8..1cbc788 100755
--- a/t/stats.t
+++ b/t/stats.t
@@ -1,7 +1,7 @@
#!/usr/bin/perl
use strict;
-use Test::More tests => 18;
+use Test::More tests => 26;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
@@ -29,6 +29,8 @@ my $sock = $server->sock;
## STAT cmd_set 0
## STAT get_hits 0
## STAT get_misses 0
+## STAT delete_misses 0
+## STAT delete_hits 4
## STAT evictions 0
## STAT bytes_read 7
## STAT bytes_written 0
@@ -37,7 +39,7 @@ my $sock = $server->sock;
my $stats = mem_stats($sock);
# Test number of keys
-is(scalar(keys(%$stats)), 22, "22 stats values");
+is(scalar(keys(%$stats)), 24, "24 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)) {
@@ -55,7 +57,22 @@ my $stats = mem_stats($sock);
foreach my $key (qw(total_items curr_items cmd_get cmd_set get_hits)) {
is($stats->{$key}, 1, "after one set/one get $key is 1");
}
+is($stats->{delete_hits}, 0);
+is($stats->{delete_misses}, 0);
my $cache_dump = mem_stats($sock, " cachedump 1 100");
ok(defined $cache_dump->{'foo'}, "got foo from cachedump");
+print $sock "delete foo\r\n";
+is(scalar <$sock>, "DELETED\r\n", "deleted foo");
+
+my $stats = mem_stats($sock);
+is($stats->{delete_hits}, 1);
+is($stats->{delete_misses}, 0);
+
+print $sock "delete foo\r\n";
+is(scalar <$sock>, "NOT_FOUND\r\n", "shouldn't delete foo again");
+
+my $stats = mem_stats($sock);
+is($stats->{delete_hits}, 1);
+is($stats->{delete_misses}, 1);
diff --git a/thread.c b/thread.c
index b4c8715..7d49784 100644
--- a/thread.c
+++ b/thread.c
@@ -536,12 +536,14 @@ void threadlocal_stats_reset(void) {
threads[ii].stats.get_cmds = 0;
threads[ii].stats.get_misses = 0;
+ threads[ii].stats.delete_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;
+ threads[ii].stats.slab_stats[sid].delete_hits = 0;
}
pthread_mutex_unlock(&threads[ii].stats.mutex);
@@ -553,6 +555,7 @@ void threadlocal_stats_aggregate(struct thread_stats *stats) {
/* The struct contains a mutex, so I should probably not memset it.. */
stats->get_cmds = 0;
stats->get_misses = 0;
+ stats->delete_misses = 0;
stats->bytes_written = 0;
stats->bytes_read = 0;
@@ -564,6 +567,7 @@ void threadlocal_stats_aggregate(struct thread_stats *stats) {
stats->get_cmds += threads[ii].stats.get_cmds;
stats->get_misses += threads[ii].stats.get_misses;
+ stats->delete_misses += threads[ii].stats.delete_misses;
stats->bytes_read += threads[ii].stats.bytes_read;
stats->bytes_written += threads[ii].stats.bytes_written;
@@ -572,6 +576,8 @@ void threadlocal_stats_aggregate(struct thread_stats *stats) {
threads[ii].stats.slab_stats[sid].set_cmds;
stats->slab_stats[sid].get_hits +=
threads[ii].stats.slab_stats[sid].get_hits;
+ stats->slab_stats[sid].delete_hits +=
+ threads[ii].stats.slab_stats[sid].delete_hits;
}
pthread_mutex_unlock(&threads[ii].stats.mutex);
@@ -583,10 +589,12 @@ void slab_stats_aggregate(struct thread_stats *stats, struct slab_stats *out) {
out->set_cmds = 0;
out->get_hits = 0;
+ out->delete_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;
+ out->delete_hits += stats->slab_stats[sid].delete_hits;
}
}