[memcached] plindner, r487: Merge up changes from trunk, add STATS_L...

commits at code.sixapart.com commits at code.sixapart.com
Sun Apr 8 15:21:13 UTC 2007


Merge up changes from trunk, add STATS_LOCK()/STATS_UNLOCK() for
new stats counter calls.  Command used:
  svn merge -r 473:486 http://code.sixapart.com/svn/memcached/trunk


U   branches/multithreaded/server/ChangeLog
U   branches/multithreaded/server/doc/protocol.txt
U   branches/multithreaded/server/items.c
U   branches/multithreaded/server/memcached.c
U   branches/multithreaded/server/memcached.h
U   branches/multithreaded/server/t/maxconns.t
U   branches/multithreaded/server/t/stats.t


Modified: branches/multithreaded/server/ChangeLog
===================================================================
--- branches/multithreaded/server/ChangeLog	2007-04-05 22:06:33 UTC (rev 486)
+++ branches/multithreaded/server/ChangeLog	2007-04-08 15:21:12 UTC (rev 487)
@@ -1,6 +1,19 @@
-2007-03-18  Paul Lindner  <lindner at mirth.inuus.com>
+2007-04-04  Paul Lindner  <lindner at inuus.com>
 
+	* Add clarification of flush_all in the protocol docs
+	  from Elizabeth Mattijsen <liz at dijkmat.nl>
 
+2007-03-31  Paul Lindner  <lindner at inuus.com>
+
+	* Add patch from Eli Bingham <eli at pandora.com> to 
+	  re-enable the -n switch to memcached.
+
+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>
 
 	* Add more test cases using larger buffer sizes up to and greater

Modified: branches/multithreaded/server/doc/protocol.txt
===================================================================
--- branches/multithreaded/server/doc/protocol.txt	2007-04-05 22:06:33 UTC (rev 486)
+++ branches/multithreaded/server/doc/protocol.txt	2007-04-08 15:21:12 UTC (rev 487)
@@ -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 
@@ -376,6 +378,18 @@
 update time is earlier than the time at which flush_all was set to be
 executed to be ignored for retrieval purposes.
 
+The intent of flush_all with a delay, was that in a setting where you
+have a pool of memcached servers, and you need to flush all content,
+you have the option of not resetting all memcached servers at the
+same time (which could e.g. cause a spike in database load with all
+clients suddenly needing to recreate content that would otherwise
+have been found in the memcached daemon).
+
+The delay option allows you to have them reset in e.g. 10 second
+intervals (by passing 0 to the first, 10 to the second, 20 to the
+third, etc. etc.).
+
+
 "version" is a command with no arguments:
 
 version\r\n

Modified: branches/multithreaded/server/items.c
===================================================================
--- branches/multithreaded/server/items.c	2007-04-05 22:06:33 UTC (rev 486)
+++ branches/multithreaded/server/items.c	2007-04-08 15:21:12 UTC (rev 487)
@@ -107,6 +107,11 @@
 
         for (search = tails[id]; tries>0 && search; tries--, search=search->prev) {
             if (search->refcount==0) {
+               if (search->exptime > current_time) {
+                       STATS_LOCK();
+                       stats.evictions++;
+                       STATS_UNLOCK();
+                }
                 do_item_unlink(search);
                 break;
             }

Modified: branches/multithreaded/server/memcached.c
===================================================================
--- branches/multithreaded/server/memcached.c	2007-04-05 22:06:33 UTC (rev 486)
+++ branches/multithreaded/server/memcached.c	2007-04-08 15:21:12 UTC (rev 487)
@@ -146,7 +146,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
@@ -160,7 +160,7 @@
 static void stats_reset(void) {
     STATS_LOCK();
     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;
     stats_prefix_clear();
     STATS_UNLOCK();
@@ -865,6 +865,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);
@@ -2424,7 +2425,7 @@
     setbuf(stderr, NULL);
 
     /* process arguments */
-    while ((c = getopt(argc, argv, "bp:s:U:m:Mc:khirvdl:u:P:f:t:D:")) != -1) {
+    while ((c = getopt(argc, argv, "bp:s:U:m:Mc:khirvdl:u:P:f:s:n:t:D:")) != -1) {
         switch (c) {
         case 'U':
             settings.udpport = atoi(optarg);

Modified: branches/multithreaded/server/memcached.h
===================================================================
--- branches/multithreaded/server/memcached.h	2007-04-05 22:06:33 UTC (rev 486)
+++ branches/multithreaded/server/memcached.h	2007-04-08 15:21:12 UTC (rev 487)
@@ -54,6 +54,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: branches/multithreaded/server/t/maxconns.t
===================================================================
--- branches/multithreaded/server/t/maxconns.t	2007-04-05 22:06:33 UTC (rev 486)
+++ branches/multithreaded/server/t/maxconns.t	2007-04-08 15:21:12 UTC (rev 487)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 10;
+use Test::More tests => 21;
 
 use FindBin qw($Bin);
 use lib "$Bin/lib";
@@ -18,15 +18,19 @@
 ok(defined($sock), 'Connection 0');
 push (@sockets, $sock);
 
-foreach my $conn (1..20) {
+
+foreach my $conn (1..10) {
   $sock = $server->new_sock;
-  if ($conn > 10) {
-    ok(!defined($sock), "Failed Connection $conn $sock");
-  } else {
-    ok(defined($sock), "Connection $conn");
-    push(@sockets, $sock);
-  }    
+  ok(defined($sock), "Made connection $conn");
+  push(@sockets, $sock);
 }
 
-mem_stats($sock, '');
-sleep(100);
+TODO: {
+local $TODO = "Need to decide on what -c semantics are";
+
+foreach my $conn (11..20) {
+  $sock = $server->new_sock;
+  ok(defined($sock), "Connection $conn");
+  push(@sockets, $sock);
+}
+}

Modified: branches/multithreaded/server/t/stats.t
===================================================================
--- branches/multithreaded/server/t/stats.t	2007-04-05 22:06:33 UTC (rev 486)
+++ branches/multithreaded/server/t/stats.t	2007-04-08 15:21:12 UTC (rev 487)
@@ -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)), 22, "22 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