Debian Codegraph @

mysql-test/suite/memcached/include/run_memcached_multithreaded_test.inc

raw
1 source include/not_valgrind.inc;
2 source include/have_memcached_plugin.inc;
3 source include/not_windows.inc;
4
5 --disable_query_log
6 CALL mtr.add_suppression("daemon-memcached-w-batch-size': unsigned");
7 CALL mtr.add_suppression("Could not obtain server's UPN to be used as target service name");
8 CALL mtr.add_suppression("Warning: MySQL is trying to drop");
9 --enable_query_log
10
11 --enable_connect_log
12 SET @transaction_isolation= @@global.transaction_isolation;
13 SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
14
15 # Create the memcached tables
16 --disable_query_log
17 source include/memcache_config.inc;
18 --enable_query_log
19
20 INSERT INTO cache_policies VALUES("cache_policy", "innodb_only",
21 "innodb_only", "innodb_only", "innodb_only");
22
23 INSERT INTO config_options VALUES("separator", "|");
24
25 # describe table for memcache
26 INSERT INTO containers VALUES ("desc_t1", "test", "t1",
27 "c1", "c2", "c3", "c4", "c5", "PRIMARY");
28
29 USE test;
30
31 --disable_warnings
32 DROP TABLE IF EXISTS t1;
33 --enable_warnings
34 CREATE TABLE t1 (c1 VARCHAR(32),
35 c2 VARCHAR(1024),
36 c3 INT, c4 BIGINT UNSIGNED, c5 INT, primary key(c1))
37 ENGINE = INNODB;
38
39 INSERT INTO t1 VALUES ('D', 'Darmstadt', 0, 0, 0);
40 INSERT INTO t1 VALUES ('B', 'Berlin', 0, 0, 0);
41 INSERT INTO t1 VALUES ('C', 'Cottbus', 0, 0 ,0);
42 INSERT INTO t1 VALUES ('H', 'Hamburg', 0, 0, 0);
43
44 # Tables must exist before plugin can be started!
45 --let $memcached_address=$ENV_MEMCACHED_ADDRESS
46 --source ../include/load_daemon_memcached_expecting_success.inc
47
48 # Spawn 3 clients which bombard the server in parallel
49
50
51 perl;
52
53 # Set to 1 if you want to test empty keys (strings of length 0)
54 # which usually leads to server noticing syntax error and causing
55 # handling of which causes a lot of bugs around dangling conn_data
56 # at the price of slowdown of the whole test due to waiting for timeouts
57 # in client after each such failure.
58 my $TEST_EMPTY_KEYS = $ENV{'ENV_TEST_EMPTY_KEYS'};
59
60 # Each test needs a separate server instance
61 my $MEMCACHED_ADDRESS = $ENV{'ENV_MEMCACHED_ADDRESS'};
62
63 # You might want to run bisect on the set of commands used during this test.
64 # Note that some bugs are actually easier to reproduce with the set of
65 # operations restricted to just (1,9,12,16) or (1,5,9,12,16).
66 my $STEPS_SUBSET = $ENV{'ENV_STEPS_SUBSET'};
67 print "TEST EMPTY KEYS: $TEST_EMPTY_KEYS\n";
68 print "MEMCACHED ADDRESS: $MEMCACHED_ADDRESS\n";
69 print "STEPS SUBSET: $STEPS_SUBSET\n";
70
71 sub mt_rand
72 {
73 my $a = shift;
74 my $b = shift;
75 my $c = $b + 1 - $a;
76 return $a + int(rand($c));
77 }
78 sub rand_str
79 {
80 my $maxlengt = shift;
81 my $k=mt_rand(($TEST_EMPTY_KEYS?0:1),$maxlengt);
82
83 my @Chars = ('1'..'9');
84 my $Number = '';
85
86 for (1..$k) {
87 $Number .= $Chars[int rand @Chars];
88 }
89 return $Number;
90 }
91 use DBI;
92 use Cache::Memcached;
93 use Time::HiRes qw(time);
94 use POSIX qw(strftime);
95
96
97 my @steps = $STEPS_SUBSET =~ /\d+/g;
98
99 sub run_single_client
100 {
101 my $worker_id=shift;
102
103 # For debug you might want to change to 1
104 my $VERBOSE = 0;
105 if ($VERBOSE) {
106 open(RESULT_FILE, ">/tmp/$worker_id.worker_log");
107 select(RESULT_FILE);
108 $| = 1;
109 }
110 sub log_print
111 {
112 if ($VERBOSE) {
113 my $msg = shift;
114 my $t = time;
115 my $date = strftime "%F %T", localtime $t;
116 $date .= sprintf ".%06d", ($t-int($t))*1e6;
117
118 print "At $date worker $worker_id: $msg\n";
119 }
120 }
121
122 my $memd = new Cache::Memcached {
123 'servers' => [ $MEMCACHED_ADDRESS ],
124 'connect_timeout' => 20,
125 'select_timeout' => 20
126 };
127
128
129
130 my $key=mt_rand(0,100);
131 my $rounds = 40000 / @steps;
132 log_print "Running $rounds rounds...";
133 for my $i (0..$rounds)
134 {
135 if(mt_rand(0,100)==0 && (1 ~~ @steps)){
136 log_print "Flush all";
137 my $res = $memd->flush_all;
138 log_print "Flush all returned $res";
139 }
140
141 if(mt_rand(0,1)==0 && (2 ~~ @steps)){
142 $key=mt_rand(0,100);
143 }
144
145 if(mt_rand(0,100)==0&& (3 ~~ @steps)){
146 $key=rand_str(3);
147 }
148
149 my $new_val="";
150
151 if(mt_rand(0,1)==0 && (4 ~~ @steps)){
152 $new_val=rand_str(67000);
153 } else {
154 $new_val=mt_rand(0,67000);
155 }
156
157 if(mt_rand(0,2)==0 && (5 ~~ @steps)){
158 log_print "Set $key to $new_val..";
159 my $res=$memd->set($key,$new_val);
160 log_print "Set $key to $new_val returned $res";
161 }
162
163 if(mt_rand(0,1)==0 && (6 ~~ @steps)){
164 $key=mt_rand(0,100);
165 }
166
167 if(mt_rand(0,2)==0 && (7 ~~ @steps)){
168 log_print "Replace $key with $new_val..";
169 my $res=$memd->replace($key,$new_val);
170 log_print "Replace $key with $new_val returned $res";
171 }
172
173 if(mt_rand(0,1)==0 && (8 ~~ @steps)){
174 $key=mt_rand(0,100);
175 }
176
177 if(mt_rand(0,2)==0 && (9 ~~ @steps)){
178 log_print "Get $key ...";
179 my $val=$memd->get($key);
180 log_print "Get $key returned $val";
181 }
182
183 if(mt_rand(0,1)==0 && (10 ~~ @steps)){
184 $key=mt_rand(0,100);
185 }
186
187 if(mt_rand(0,2)==0 && (11 ~~ @steps)){
188 log_print "Increment $key ...";
189 my $val=$memd->incr($key);
190 log_print "Increment $key returned $val";
191 }
192
193 if(mt_rand(0,1)==0 && (12 ~~ @steps)){
194 $key=mt_rand(0,1000);
195 }
196
197 if(mt_rand(0,2)==0 && (13 ~~ @steps)){
198 log_print "Decrement $key ...";
199 my $val=$memd->decr($key);
200 log_print "Decrement $key returned $val";
201 }
202
203 if(mt_rand(0,1)==0 && (14 ~~ @steps)){
204 $key=mt_rand(0,10000000);
205 }
206
207 if(mt_rand(0,50)==0 && (15 ~~ @steps)){
208 log_print "Delete $key...";
209 my $res=$memd->delete($key);
210 log_print "Delete $key returned $res";
211 }
212
213 if($i%1000 == 0 && (16 ~~ @steps))
214 {
215 log_print "Get stats()...";
216 my %hash = $memd->stats();
217 log_print %hash;
218 }
219
220 $i++;
221 }
222 $memd->disconnect_all;
223 }
224
225 use threads;
226 for my $worker_id (1..3)
227 {
228 print "Spawning $worker_id\n";
229 threads->create('run_single_client', $worker_id);
230 }
231
232 foreach my $thr ( threads->list() ) {
233 print "joining...\n";
234 $thr->join();
235 }
236
237 EOF
238
239
240
241 # Stop plugin before innodb_memcached configuration
242 UNINSTALL PLUGIN daemon_memcached;
243 DROP TABLE t1;
244 DROP DATABASE innodb_memcache;
245
246 SET @@global.transaction_isolation= @transaction_isolation;