Skip to content

Commit

Permalink
* Add patch to collect eviction statistics from
Browse files Browse the repository at this point in the history
  Jean-Francois BUSTARRET <[email protected]>.
* Updated docs, added new test cases for t/stats.t



git-svn-id: http://code.sixapart.com/svn/memcached/trunk/server@476 b0b603af-a30f-0410-a34e-baf09ae79d0b
  • Loading branch information
plindner committed Mar 20, 2007
1 parent b89fe61 commit 4f0d730
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 8 deletions.
5 changes: 4 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
2007-03-18 Paul Lindner <[email protected]>
2007-03-20 Paul Lindner <[email protected]>
* Add patch to collect eviction statistics from
Jean-Francois BUSTARRET <[email protected]>.

* Updated docs, added new test cases for t/stats.t

2007-03-18 Paul Lindner <[email protected]>

Expand Down
10 changes: 6 additions & 4 deletions doc/protocol.txt
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,14 @@ total_connections 32u Total number of connections opened since
the server started running
connection_structures 32u Number of connection structures allocated
by the server
cmd_get 32u Cumulative number of retrieval requests
cmd_set 32u Cumulative number of storage requests
get_hits 32u Number of keys that have been requested and
cmd_get 64u Cumulative number of retrieval requests
cmd_set 64u Cumulative number of storage requests
get_hits 64u Number of keys that have been requested and
found present
get_misses 32u Number of items that have been requested
get_misses 64u Number of items that have been requested
and not found
evictions 64u Number of items removed from cache because
they passed their expiration time
bytes_read 64u Total number of bytes read by this server
from network
bytes_written 64u Total number of bytes sent by this server to
Expand Down
2 changes: 2 additions & 0 deletions items.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ item *item_alloc(char *key, const size_t nkey, const int flags, const rel_time_t

for (search = tails[id]; tries>0 && search; tries--, search=search->prev) {
if (search->refcount==0) {
if (search->exptime > current_time)
stats.evictions++;
item_unlink(search);
break;
}
Expand Down
5 changes: 3 additions & 2 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,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.get_cmds = stats.set_cmds = stats.get_hits = stats.get_misses = 0;
stats.get_cmds = stats.set_cmds = stats.get_hits = stats.get_misses = stats.evictions = 0;
stats.curr_bytes = stats.bytes_read = stats.bytes_written = 0;

/* make the time we started always be 2 seconds before we really
Expand All @@ -162,7 +162,7 @@ static void stats_init(void) {

static void stats_reset(void) {
stats.total_items = stats.total_conns = 0;
stats.get_cmds = stats.set_cmds = stats.get_hits = stats.get_misses = 0;
stats.get_cmds = stats.set_cmds = stats.get_hits = stats.get_misses = stats.evictions = 0;
stats.bytes_read = stats.bytes_written = 0;
}

Expand Down Expand Up @@ -829,6 +829,7 @@ static void process_stat(conn *c, token_t* tokens, const size_t ntokens) {
pos += sprintf(pos, "STAT cmd_set %llu\r\n", stats.set_cmds);
pos += sprintf(pos, "STAT get_hits %llu\r\n", stats.get_hits);
pos += sprintf(pos, "STAT get_misses %llu\r\n", stats.get_misses);
pos += sprintf(pos, "STAT evictions %llu\r\n", stats.evictions);
pos += sprintf(pos, "STAT bytes_read %llu\r\n", stats.bytes_read);
pos += sprintf(pos, "STAT bytes_written %llu\r\n", stats.bytes_written);
pos += sprintf(pos, "STAT limit_maxbytes %llu\r\n", (unsigned long long) settings.maxbytes);
Expand Down
1 change: 1 addition & 0 deletions memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct stats {
unsigned long long set_cmds;
unsigned long long get_hits;
unsigned long long get_misses;
unsigned long long evictions;
time_t started; /* when the process was started */
unsigned long long bytes_read;
unsigned long long bytes_written;
Expand Down
48 changes: 47 additions & 1 deletion t/stats.t
Original file line number Diff line number Diff line change
@@ -1,11 +1,57 @@
#!/usr/bin/perl

use strict;
use Test::More skip_all => "Tests not written."; # tests => 1
use Test::More tests => 16;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;

my $server = new_memcached();
my $sock = $server->sock;


## Output looks like this:
##
## STAT pid 16293
## STAT uptime 7
## STAT time 1174419597
## STAT version 1.2.1
## STAT pointer_size 32
## STAT rusage_user 0.012998
## STAT rusage_system 0.119981
## STAT curr_items 0
## STAT total_items 0
## STAT bytes 0
## STAT curr_connections 1
## STAT total_connections 2
## STAT connection_structures 2
## STAT cmd_get 0
## STAT cmd_set 0
## STAT get_hits 0
## STAT get_misses 0
## STAT evictions 0
## STAT bytes_read 7
## STAT bytes_written 0
## STAT limit_maxbytes 67108864

my $stats = mem_stats($sock);

# Test number of keys
is(scalar(keys(%$stats)), 21, "21 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)) {
is($stats->{$key}, 0, "initial $key is zero");
}

# Do some operations

print $sock "set foo 0 0 6\r\nfooval\r\n";
is(scalar <$sock>, "STORED\r\n", "stored foo");
mem_get_is($sock, "foo", "fooval");

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");
}

0 comments on commit 4f0d730

Please sign in to comment.