"Fossies" - the Fresh Open Source Software Archive

Member "memcached-1.6.15/t/lru-maintainer.t" (16 Jul 2020, 3768 Bytes) of package /linux/www/memcached-1.6.15.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl
    2 
    3 use strict;
    4 use warnings;
    5 use Test::More tests => 226;
    6 use FindBin qw($Bin);
    7 use lib "$Bin/lib";
    8 use MemcachedTest;
    9 
   10 # Regression test for underestimating the size of items after the large memory
   11 # change.
   12 my $server = new_memcached('-m 3 -o lru_maintainer,lru_crawler -l 127.0.0.1');
   13 my $sock = $server->sock;
   14 my $keystub = "X"x200;
   15 for (1 .. 15000) {
   16     print $sock "set $keystub$_ 0 0 2 noreply\r\nok\r\n";
   17 }
   18 # There's probably already an error on the wire, so we'll see that.
   19 $keystub .= "20001";
   20 print $sock "set $keystub 0 0 2\r\nok\r\n";
   21 is(scalar <$sock>, "STORED\r\n", "stored key without OOM");
   22 
   23 # Basic tests
   24 $server = new_memcached('-m 6 -o lru_maintainer,lru_crawler -l 127.0.0.1');
   25 $sock = $server->sock;
   26 
   27 for (1 .. 10) {
   28     print $sock "set ifoo$_ 0 1 2\r\nok\r\n";
   29     is(scalar <$sock>, "STORED\r\n", "stored key");
   30 }
   31 
   32 sleep 3;
   33 
   34 {
   35     my $stats = mem_stats($sock);
   36     is($stats->{reclaimed}, 10, "expired key automatically reclaimed");
   37 }
   38 
   39 my $value = "B"x66560;
   40 
   41 print $sock "set canary 0 0 66560\r\n$value\r\n";
   42 is(scalar <$sock>, "STORED\r\n", "stored canary key");
   43 
   44 # Now flush the slab class with junk.
   45 for (my $key = 0; $key < 100; $key++) {
   46     if ($key == 30) {
   47         my $stats;
   48         for (0..2) {
   49             # Give the juggler some time to move. some platforms suffer at
   50             # this more than others (solaris amd64?)
   51             $stats = mem_stats($sock, "items");
   52             if ($stats->{"items:31:moves_to_cold"} == 0) { sleep 1; next; }
   53             last;
   54         }
   55         isnt($stats->{"items:31:moves_to_cold"}, 0, "moved some items to cold");
   56         # Items need two fetches to become active
   57         mem_get_is($sock, "canary", $value);
   58         mem_get_is($sock, "canary", $value);
   59         $stats = mem_stats($sock);
   60         # The maintainer thread needs to juggle a bit to actually rescue an
   61         # item. If it's slow we could evict after resuming setting.
   62         sleep 1;
   63         for (0..4) {
   64             my $s2 = mem_stats($sock);
   65             if ($s2->{lru_maintainer_juggles} - $stats->{lru_maintainer_juggles} < 5) {
   66                 sleep 1;
   67                 next;
   68             }
   69             last;
   70         }
   71         $stats = mem_stats($sock, "items");
   72         isnt($stats->{"items:31:moves_to_warm"}, 0, "our canary moved to warm");
   73     }
   74     print $sock "set key$key 0 0 66560\r\n$value\r\n";
   75     is(scalar <$sock>, "STORED\r\n", "stored key$key");
   76 }
   77 
   78 {
   79     my $stats = mem_stats($sock);
   80     isnt($stats->{evictions}, 0, "some evictions happened");
   81     use Data::Dumper qw/Dumper/;
   82 }
   83 
   84 # Key should've been saved to the WARM_LRU, and still exists.
   85 mem_get_is($sock, "canary", $value);
   86 
   87 # Test TEMP_LRU
   88 $server = new_memcached('-m 2 -o lru_maintainer,lru_crawler,temporary_ttl=61');
   89 $sock = $server->sock;
   90 
   91 {
   92     my $stats = mem_stats($sock, "settings");
   93     is($stats->{temp_lru}, "yes");
   94 }
   95 
   96 print $sock "set canary 0 30 66560\r\n$value\r\n";
   97 is(scalar <$sock>, "STORED\r\n", "stored temporary canary key");
   98 
   99 {
  100     my $stats = mem_stats($sock, "items");
  101     is($stats->{"items:31:number_hot"}, 0, "item did not go into hot LRU");
  102 }
  103 
  104 # *Not* fetching the key, and flushing the slab class with junk.
  105 # Using keys with higher TTL's here.
  106 for (my $key = 0; $key < 100; $key++) {
  107     print $sock "set key$key 0 3600 66560\r\n$value\r\n";
  108     is(scalar <$sock>, "STORED\r\n", "stored key$key");
  109 }
  110 
  111 {
  112     my $stats = mem_stats($sock, "items");
  113     isnt($stats->{"items:31:evictions"}, 0, "some evictions happened");
  114     isnt($stats->{"items:31:number_hot"}, 0, "high exptime items went into hot LRU");
  115     is($stats->{"items:31:number_temp"}, 1, "still one item in temporary LRU");
  116 }
  117 # Canary should still exist, even unfetched, because it's protected by
  118 # temp LRU
  119 mem_get_is($sock, "canary", $value);