"Fossies" - the Fresh Open Source Software Archive

Member "memcached-1.6.15/t/chunked-extstore.t" (30 Mar 2022, 5910 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. See also the latest Fossies "Diffs" side-by-side code changes report for "chunked-extstore.t": 1.6.14_vs_1.6.15.

    1 #!/usr/bin/perl
    2 # Networked logging tests.
    3 
    4 use strict;
    5 use warnings;
    6 
    7 use Test::More;
    8 use FindBin qw($Bin);
    9 use lib "$Bin/lib";
   10 use MemcachedTest;
   11 
   12 my $ext_path;
   13 
   14 if (!supports_extstore()) {
   15     plan skip_all => 'extstore not enabled';
   16     exit 0;
   17 }
   18 
   19 $ext_path = "/tmp/extstore.$$";
   20 
   21 my $server = new_memcached("-m 64 -U 0 -o ext_page_size=8,ext_wbuf_size=2,ext_threads=1,ext_io_depth=2,ext_item_size=512,ext_item_age=2,ext_recache_rate=0,ext_max_frag=0,ext_path=$ext_path:64m,slab_chunk_max=16384,slab_automove=0,ext_max_sleep=100000");
   22 my $sock = $server->sock;
   23 
   24 # Only able to disable compaction at runtime.
   25 # FIXME: -1 for disabled? :(
   26 print $sock "extstore compact_under 0\r\n";
   27 my $res = <$sock>;
   28 
   29 # Wait until all items have flushed
   30 sub wait_for_ext {
   31     my $sum = 1;
   32     while ($sum != 0) {
   33         my $s = mem_stats($sock, "items");
   34         $sum = 0;
   35         for my $key (keys %$s) {
   36             if ($key =~ m/items:(\d+):number/) {
   37                 # Ignore classes which can contain extstore items
   38                 next if $1 < 3;
   39                 $sum += $s->{$key};
   40             }
   41         }
   42         sleep 1 if $sum != 0;
   43     }
   44 }
   45 
   46 # We're testing to ensure item chaining doesn't corrupt or poorly overlap
   47 # data, so create a non-repeating pattern.
   48 my @parts = ();
   49 for (1 .. 8000) {
   50     push(@parts, $_);
   51 }
   52 my $pattern = join(':', @parts);
   53 my $plen = length($pattern);
   54 
   55 print $sock "set pattern 0 0 $plen\r\n$pattern\r\n";
   56 is(scalar <$sock>, "STORED\r\n", "stored pattern successfully");
   57 # Stash two more for later test
   58 print $sock "set pattern2 0 0 $plen noreply\r\n$pattern\r\n";
   59 print $sock "set pattern3 0 0 $plen noreply\r\n$pattern\r\n";
   60 wait_for_ext();
   61 mem_get_is($sock, "pattern", $pattern);
   62 
   63 for (1..5) {
   64     my $size = 400 * 1024;
   65     my $data = "x" x $size;
   66     print $sock "set foo$_ 0 0 $size\r\n$data\r\n";
   67     my $res = <$sock>;
   68     is($res, "STORED\r\n", "stored some big items");
   69 }
   70 wait_for_ext();
   71 
   72 {
   73     my $max = 1024 * 1024;
   74     my $big = "a big value that's > .5M and < 1M. ";
   75     while (length($big) * 2 < $max) {
   76         $big = $big . $big;
   77     }
   78     my $biglen = length($big);
   79 
   80     for (1..40) {
   81         print $sock "set toast$_ 0 0 $biglen\r\n$big\r\n";
   82         is(scalar <$sock>, "STORED\r\n", "stored big");
   83     }
   84     wait_for_ext();
   85 
   86     for (1..40) {
   87         mem_get_is($sock, "toast$_", $big);
   88     }
   89 
   90     my $stats = mem_stats($sock);
   91     cmp_ok($stats->{extstore_page_allocs}, '>', 0, 'at least one page allocated');
   92     cmp_ok($stats->{extstore_objects_written}, '>', 25, 'some objects written');
   93     cmp_ok($stats->{extstore_bytes_written}, '>', $max * 2, 'some bytes written');
   94     cmp_ok($stats->{get_extstore}, '>', 5, 'multiple objects fetched');
   95     cmp_ok($stats->{extstore_objects_read}, '>', 0, 'one object read');
   96     cmp_ok($stats->{extstore_bytes_read}, '>', $max * 2, 'some bytes read');
   97     is($stats->{badcrc_from_extstore}, 0, 'CRC checks successful');
   98 }
   99 
  100 # fill to eviction
  101 {
  102     my $keycount = 1250;
  103     for (1 .. $keycount) {
  104         print $sock "set mfoo$_ 0 0 $plen noreply\r\n$pattern\r\n";
  105         wait_for_ext() if $_ % 500 == 0;
  106     }
  107     # because item_age is set to 2s.
  108     wait_for_ext();
  109 
  110     my $stats = mem_stats($sock);
  111     is($stats->{evictions}, 0, 'memory evictions should still be zero');
  112     cmp_ok($stats->{extstore_page_evictions}, '>', 0, 'at least one page evicted');
  113     cmp_ok($stats->{extstore_objects_evicted}, '>', 0, 'at least one object evicted');
  114     cmp_ok($stats->{extstore_bytes_evicted}, '>', 0, 'some bytes evicted');
  115     cmp_ok($stats->{extstore_pages_free}, '<', 2, 'most pages are used');
  116     is($stats->{miss_from_extstore}, 0, 'no misses');
  117 
  118     # original "pattern" key should be gone.
  119     cmp_ok($stats->{recache_from_extstore}, '<', 1, 'no recaching happening');
  120     cmp_ok($stats->{extstore_compact_rescues}, '<', 1, 'no compaction rescues happened');
  121     mem_get_is($sock, "pattern", undef, "original pattern key is gone");
  122     $stats = mem_stats($sock);
  123     is($stats->{miss_from_extstore}, 1, 'one extstore miss');
  124 
  125     print $sock "get pattern2 pattern3\r\n";
  126     is(scalar <$sock>, "END\r\n", "multiget double miss");
  127     $stats = mem_stats($sock);
  128     is($stats->{miss_from_extstore}, 3, 'three extstore misses');
  129 }
  130 
  131 # Let compaction run.
  132 {
  133     for (1..40) {
  134         print $sock "delete toast$_ noreply\r\n" if $_ % 2 == 0;
  135     }
  136 
  137     for (1..1250) {
  138         # Force a read so objects don't get skipped.
  139         print $sock "add mfoo$_ 0 0 1 noreply\r\n1\r\n" if $_ % 2 == 1;
  140     }
  141     for (1..1250) {
  142         # Delete lots of objects to trigger compaction.
  143         print $sock "delete mfoo$_ noreply\r\n" if $_ % 2 == 0;
  144     }
  145     print $sock "extstore compact_under 4\r\n";
  146     my $res = <$sock>;
  147     is($res, "OK\r\n", 'set compact_under');
  148     print $sock "extstore drop_under 3\r\n";
  149     $res = <$sock>;
  150     is($res, "OK\r\n", 'set drop_under');
  151     print $sock "extstore max_frag 0.9\r\n";
  152     $res = <$sock>;
  153     is($res, "OK\r\n", 'set max_frag');
  154 
  155     # Give compaction some time to run.
  156     for (1 .. 30) {
  157         my $stats = mem_stats($sock);
  158         last if $stats->{extstore_pages_free} > 2;
  159         sleep 1;
  160     }
  161 
  162     my $stats = mem_stats($sock);
  163     cmp_ok($stats->{extstore_pages_free}, '>', 2, 'some pages now free');
  164     cmp_ok($stats->{extstore_compact_rescues}, '>', 0, 'some compaction rescues happened');
  165 
  166     # Some of the early items got evicted
  167     for (750..1250) {
  168         # everything should validate properly.
  169         mem_get_is($sock, "mfoo$_", $pattern) if $_ % 2 == 1;
  170     }
  171 }
  172 
  173 # test recache
  174 {
  175     print $sock "extstore recache_rate 1\r\n";
  176     is(scalar <$sock>, "OK\r\n", "upped recache rate");
  177 
  178     for (1150..1250) {
  179         mem_get_is($sock, "mfoo$_", $pattern) if $_ % 2 == 1;
  180     }
  181 
  182     my $stats = mem_stats($sock);
  183     cmp_ok($stats->{recache_from_extstore}, '>', 25, 'recaching happening');
  184 }
  185 
  186 done_testing();
  187 
  188 END {
  189     unlink $ext_path if $ext_path;
  190 }