[memcached] plindner, r476: * Add patch to collect eviction statisti...

commits at code.sixapart.com commits at code.sixapart.com
Tue Mar 20 22:41:14 UTC 2007


* Add patch to collect eviction statistics from
  Jean-Francois BUSTARRET <jfbustarret at wat.tv>.
* Updated docs, added new test cases for t/stats.t



U   trunk/server/ChangeLog
U   trunk/server/doc/protocol.txt
U   trunk/server/items.c
U   trunk/server/memcached.c
U   trunk/server/memcached.h
U   trunk/server/t/stats.t


Modified: trunk/server/ChangeLog
===================================================================
--- trunk/server/ChangeLog	2007-03-20 22:37:43 UTC (rev 475)
+++ trunk/server/ChangeLog	2007-03-20 22:41:13 UTC (rev 476)
@@ -1,5 +1,8 @@
-2007-03-18  Paul Lindner  <lindner at mirth.inuus.com>
+2007-03-20  Paul Lindner  <lindner at inuus.com>
+	* Add patch to collect eviction statistics from
+          Jean-Francois BUSTARRET <jfbustarret at wat.tv>.
 
+        * Updated docs, added new test cases for t/stats.t
 
 2007-03-18  Paul Lindner  <lindner at inuus.com>
 

Modified: trunk/server/doc/protocol.txt
===================================================================
--- trunk/server/doc/protocol.txt	2007-03-20 22:37:43 UTC (rev 475)
+++ trunk/server/doc/protocol.txt	2007-03-20 22:41:13 UTC (rev 476)
@@ -346,12 +346,14 @@
                            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 

Modified: trunk/server/items.c
===================================================================
--- trunk/server/items.c	2007-03-20 22:37:43 UTC (rev 475)
+++ trunk/server/items.c	2007-03-20 22:41:13 UTC (rev 476)
@@ -101,6 +101,8 @@
 
         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;
             }

Modified: trunk/server/memcached.c
===================================================================
--- trunk/server/memcached.c	2007-03-20 22:37:43 UTC (rev 475)
+++ trunk/server/memcached.c	2007-03-20 22:41:13 UTC (rev 476)
@@ -150,7 +150,7 @@
 
 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
@@ -162,7 +162,7 @@
 
 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;
 }
 
@@ -829,6 +829,7 @@
         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);

Modified: trunk/server/memcached.h
===================================================================
--- trunk/server/memcached.h	2007-03-20 22:37:43 UTC (rev 475)
+++ trunk/server/memcached.h	2007-03-20 22:41:13 UTC (rev 476)
@@ -48,6 +48,7 @@
     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;

Modified: trunk/server/t/stats.t
===================================================================
--- trunk/server/t/stats.t	2007-03-20 22:37:43 UTC (rev 475)
+++ trunk/server/t/stats.t	2007-03-20 22:41:13 UTC (rev 476)
@@ -1,7 +1,7 @@
 #!/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;
@@ -9,3 +9,49 @@
 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");
+}




More information about the memcached-commits mailing list