"Fossies" - the Fresh Open Source Software Archive

Member "memcached-1.6.15/t/slabs-reassign2.t" (16 Jul 2020, 3900 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 => 12;
    6 use FindBin qw($Bin);
    7 use lib "$Bin/lib";
    8 use MemcachedTest;
    9 use Data::Dumper qw/Dumper/;
   10 
   11 my $server = new_memcached('-m 60 -o slab_reassign,slab_automove,lru_crawler,lru_maintainer,slab_automove_window=3');
   12 my $sock = $server->sock;
   13 
   14 my $value = "B"x11000;
   15 my $keycount = 5000;
   16 
   17 my $res;
   18 for (1 .. $keycount) {
   19     print $sock "set nfoo$_ 0 0 11000 noreply\r\n$value\r\n";
   20 }
   21 
   22 my $todelete = 0;
   23 {
   24     my $stats = mem_stats($sock);
   25     cmp_ok($stats->{curr_items}, '>', 4000, "stored at least 4000 11k items");
   26     $todelete = $stats->{curr_items};
   27 #    for ('evictions', 'reclaimed', 'curr_items', 'cmd_set', 'bytes') {
   28 #        print STDERR "$_: ", $stats->{$_}, "\n";
   29 #    }
   30 }
   31 
   32 # Make room in old class so rescues can happen when we switch slab classes.
   33 for (1 .. $todelete) {
   34     next unless $_ % 2 == 0;
   35     print $sock "delete nfoo$_ noreply\r\n";
   36 }
   37 
   38 {
   39     my $tries;
   40     for ($tries = 20; $tries > 0; $tries--) {
   41         sleep 1;
   42         my $stats = mem_stats($sock);
   43         if ($stats->{slab_global_page_pool} > 24) {
   44             last;
   45         }
   46     }
   47     cmp_ok($tries, '>', 0, 'some pages moved back to global pool');
   48 }
   49 
   50 $value = "B"x7000;
   51 for (1 .. $keycount) {
   52     print $sock "set ifoo$_ 0 0 7000 noreply\r\n$value\r\n";
   53 }
   54 
   55 my $missing = 0;
   56 my $hits = 0;
   57 for (1 .. $keycount) {
   58     print $sock "get ifoo$_\r\n";
   59     my $body = scalar(<$sock>);
   60     my $expected = "VALUE ifoo$_ 0 7000\r\n$value\r\nEND\r\n";
   61     if ($body =~ /^END/) {
   62         $missing++;
   63     } else {
   64         $body .= scalar(<$sock>) . scalar(<$sock>);
   65         if ($body ne $expected) {
   66             print STDERR "Something terrible has happened: $expected\nBODY:\n$body\nDONETEST\n";
   67         } else {
   68             $hits++;
   69         }
   70     }
   71 }
   72 #print STDERR "HITS: $hits, MISSES: $missing\n";
   73 
   74 {
   75     my $stats = mem_stats($sock);
   76     cmp_ok($stats->{evictions}, '<', 2000, 'evictions were less than 2000');
   77 #    for ('evictions', 'reclaimed', 'curr_items', 'cmd_set', 'bytes') {
   78 #        print STDERR "$_: ", $stats->{$_}, "\n";
   79 #    }
   80 }
   81 
   82 # Force reassign evictions by moving too much memory manually.
   83 {
   84     my $s = mem_stats($sock, 'slabs');
   85     my $max_pages = 0;
   86     my $scls = 0;
   87     for my $k (keys %$s) {
   88         next unless $k =~ m/^(\d+)\:total_pages/;
   89         if ($s->{$k} > $max_pages) {
   90             $max_pages = $s->{$k};
   91             $scls = $1;
   92         }
   93     }
   94     my $tries;
   95     for ($tries = 10; $tries > 0; $tries--) {
   96         print $sock "slabs reassign $scls 1\r\n";
   97         my $res = <$sock>;
   98         sleep 1;
   99         my $s = mem_stats($sock);
  100         last if $s->{slab_reassign_evictions_nomem} > 0;
  101     }
  102     cmp_ok($tries, '>', 0, 'some reassign evictions happened');
  103 }
  104 cmp_ok($hits, '>', 2000, 'were able to fetch back some of the small keys');
  105 my $stats_done = mem_stats($sock);
  106 cmp_ok($stats_done->{slab_reassign_rescues}, '>', 0, 'some reassign rescues happened');
  107 
  108 print $sock "flush_all\r\n";
  109 is(scalar <$sock>, "OK\r\n", "did flush_all");
  110 my $tries;
  111 for ($tries = 20; $tries > 0; $tries--) {
  112     sleep 1;
  113     my $stats = mem_stats($sock);
  114     if ($stats->{slab_global_page_pool} > 50) {
  115         last;
  116     }
  117 }
  118 cmp_ok($tries, '>', 0, 'reclaimed at least 50 pages before timeout');
  119 
  120 {
  121     my $stats = mem_stats($sock, "slabs");
  122     is($stats->{total_malloced}, 62914560, "total_malloced is what we expect");
  123 }
  124 
  125 # Set into an entirely new class. Overload a bit to try to cause problems.
  126 $value = "B"x4096;
  127 for (1 .. $keycount * 4) {
  128     print $sock "set jfoo$_ 0 0 4096 noreply\r\n$value\r\n";
  129 }
  130 
  131 {
  132     my $stats = mem_stats($sock);
  133     cmp_ok($stats->{curr_items}, '>', 10000, "stored at least 10000 4k items");
  134     is($stats->{slab_global_page_pool}, 0, "drained the global page pool");
  135 }
  136 
  137 {
  138     my $stats = mem_stats($sock, "slabs");
  139     is($stats->{total_malloced}, 62914560, "total_malloced is same after re-assignment");
  140 }