"Fossies" - the Fresh Open Source Software Archive 
Member "memcached-1.6.15/t/slabs-reassign-chunked.t" (16 Jul 2020, 4019 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 => 8;
6 use FindBin qw($Bin);
7 use lib "$Bin/lib";
8 use MemcachedTest;
9
10 my $server = new_memcached('-m 60 -o slab_reassign,slab_automove,lru_crawler,lru_maintainer,slab_chunk_max=4096');
11 my $sock = $server->sock;
12
13 sub dump_stats {
14 my $s = shift;
15 my $filter = shift || '';
16 for my $k (sort keys %$s) {
17 if ($filter) {
18 next unless $k =~ m/$filter/;
19 }
20 print STDERR "STAT: $k = ", $s->{$k}, "\n";
21 }
22 }
23
24 my $value;
25 {
26 my @chars = ("C".."Z");
27 for (1 .. 11000) {
28 $value .= $chars[rand @chars];
29 }
30 }
31 my $keycount = 5100;
32
33 my $res;
34 for (1 .. $keycount) {
35 # print STDERR "HI $_\n";
36 print $sock "set nfoo$_ 0 0 11000 noreply\r\n$value\r\n";
37 # print $sock "set nfoo$_ 0 0 11000\r\n$value\r\n";
38 # my $res = scalar <$sock>;
39 # print STDERR "RES: $res\n";
40 }
41
42 my $todelete = 0;
43 {
44 my $stats = mem_stats($sock);
45 cmp_ok($stats->{curr_items}, '>', 4000, "stored at least 4000 11k items");
46 $todelete = $stats->{curr_items} / 2;
47 # for ('evictions', 'reclaimed', 'curr_items', 'cmd_set', 'bytes') {
48 # print STDERR "$_: ", $stats->{$_}, "\n";
49 # }
50 }
51
52 {
53 my $s = mem_stats($sock, 'slabs');
54 my $sid;
55 # Find the highest ID to source from.
56 for my $k (keys %$s) {
57 next unless $k =~ m/^(\d+):/;
58 $sid = $s->{$k} if $s->{$k} > $1;
59 }
60 for (my $x = 0; $x < 3; $x++) {
61 print $sock "slabs reassign 17 0\r\n";
62 my $res = scalar <$sock>;
63 chomp $res;
64 # print STDERR "SLABS REASSIGN RESULT: $res\n";
65 sleep 1;
66 }
67 }
68
69 # Make room in old class so rescues can happen when we switch slab classes.
70 #for (1 .. $todelete) {
71 # print $sock "delete nfoo$_ noreply\r\n";
72 #}
73
74 # Give LRU mover some time to reclaim slab chunks.
75 #sleep 1;
76
77 {
78 my $stats = mem_stats($sock);
79 cmp_ok($stats->{slab_global_page_pool}, '>', 0, 'global page pool > 0');
80 cmp_ok($stats->{slab_reassign_chunk_rescues}, '>', 0, 'some chunk rescues happened');
81 }
82
83 {
84 my $hits = 0;
85 for (1 .. $keycount) {
86 print $sock "get nfoo$_\r\n";
87 my $body = scalar(<$sock>);
88 my $expected = "VALUE nfoo$_ 0 11000\r\n$value\r\nEND\r\n";
89 if ($body =~ /^END/) {
90 next;
91 } else {
92 $body .= scalar(<$sock>) . scalar(<$sock>);
93 if ($body ne $expected) {
94 die "Something terrible has happened: $expected\nBODY:\n$body\nDONETEST\n";
95 }
96 $hits++;
97 }
98 }
99 cmp_ok($hits, '>', 0, "fetched back $hits values after reassignment");
100 }
101
102 $value = "A"x3000;
103 for (1 .. $keycount) {
104 print $sock "set ifoo$_ 0 0 3000 noreply\r\n$value\r\n";
105 }
106
107 my $missing = 0;
108 my $hits = 0;
109 for (1 .. $keycount) {
110 print $sock "get ifoo$_\r\n";
111 my $body = scalar(<$sock>);
112 my $expected = "VALUE ifoo$_ 0 3000\r\n$value\r\nEND\r\n";
113 if ($body =~ /^END/) {
114 $missing++;
115 } else {
116 $body .= scalar(<$sock>) . scalar(<$sock>);
117 if ($body ne $expected) {
118 print STDERR "Something terrible has happened: $expected\nBODY:\n$body\nDONETEST\n";
119 } else {
120 $hits++;
121 }
122 }
123 }
124 #print STDERR "HITS: $hits, MISSES: $missing\n";
125
126 {
127 my $stats = mem_stats($sock);
128 cmp_ok($stats->{evictions}, '<', 2000, 'evictions were less than 2000');
129 # for ('evictions', 'reclaimed', 'curr_items', 'cmd_set', 'bytes') {
130 # print STDERR "$_: ", $stats->{$_}, "\n";
131 # }
132 }
133
134 cmp_ok($hits, '>', 4000, 'were able to fetch back 2/3rds of 8k keys');
135 my $stats_done = mem_stats($sock);
136 cmp_ok($stats_done->{slab_reassign_chunk_rescues}, '>', 0, 'some reassign chunk rescues happened');
137 # Reassign rescues won't happen here because the headers are of a different
138 # size and we aren't moving pages out of that slab class
139 #cmp_ok($stats_done->{slab_reassign_rescues}, '>', 0, 'some reassign rescues happened');
140 cmp_ok($stats_done->{slab_reassign_evictions_nomem}, '>', 0, 'some reassign evictions happened');
141