1#!/usr/bin/perl
2############################################################################
3#     Stress test for MySQL/InnoDB combined database
4#     (c) 2002 Innobase Oy & MySQL AB
5#
6############################################################################
7
8use Cwd;
9use DBI;
10use Benchmark;
11
12$opt_loop_count = 200000;
13
14$pwd = cwd(); $pwd = "." if ($pwd eq '');
15require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
16
17print "Innotest1b: MySQL/InnoDB stress test in Perl\n";
18print "-------------------------------------------\n";
19print "This is a randomized stress test for concurrent inserts,\n";
20print "updates, deletes, commits and rollbacks. The test will generate\n";
21print "also a lot of deadlocks, duplicate key errors, and other SQL errors.\n";
22print "\n";
23print "You should run innotest1, innotest1a, and innotest1b concurrently.\n";
24print "The thing to watch is that the server does not crash or does not\n";
25print "print to the .err log anything. Currently, due to a buglet in MySQL,\n";
26print "warnings about MySQL lock reservations can appear in the .err log.\n";
27print "The test will run very long, even several hours. You can kill\n";
28print "the perl processes running this test at any time and do CHECK\n";
29print "TABLE on table innotest1 in the 'test' database.\n";
30print "\n";
31print "Some of these stress tests will print a lot of SQL errors\n";
32print "to the standard output. That is not to be worried about.\n";
33print "You can direct the output to a file like this:\n";
34print "perl innotest1 > out1\n\n";
35
36print "Generating random keys\n";
37$random[$opt_loop_count] = 0;
38$rnd_str[$opt_loop_count] = "a";
39
40for ($i = 0; $i < $opt_loop_count; $i++) {
41
42	$random[$i] = ($i * 63857) % $opt_loop_count;
43
44  	if (0 == ($random[$i] % 3)) {
45  		$rnd_str[$i] = "kjgclgrtfuylfluyfyufyulfulfyyulofuyolfyufyufuyfyufyufyufyufyyufujhfghd";
46	} else { if (1 == ($random[$i] % 3)) {
47		$rnd_str[$i] = "khd";
48	} else { if (2 == ($random[$i] % 3)) {
49		$rnd_str[$i] = "kh";
50	}}}
51
52	for ($j = 0; $j < (($i * 764877) % 20); $j++) {
53		$rnd_str[$i] = $rnd_str[$i]."k";
54	}
55}
56
57####
58####  Connect
59####
60
61$dbh = $server->connect()
62|| die $dbh->errstr;
63
64$dbh->do("set autocommit = 0");
65
66for ($i = 0; $i < 5; $i++) {
67	print "loop $i\n";
68
69	for ($j = 1; $j < $opt_loop_count - 10; $j = $j + 2) {
70
71		fetch_all_rows($dbh, "select b, c from innotest1 where a > ".$random[$j]." and a < ".($random[$j] + 7));
72
73		if (0 == ($j % 37)) {
74			$dbh->do("commit");
75		}
76
77		if (0 == ($j % 533)) {
78			$dbh->do("rollback");
79		}
80
81		if (0 == ($j % 537)) {
82		print fetch_all_rows($dbh, "select c from innotest1 where c = '".$rnd_str[$j - 67]."'");
83		print fetch_all_rows($dbh, "select b from innotest1 where b = '".$rnd_str[$j - 688]."'");
84		print fetch_all_rows($dbh, "select b, c from innotest1 where c = '".$rnd_str[$j - 67]."'");
85		print fetch_all_rows($dbh, "select b, c from innotest1 where b = '".$rnd_str[$j - 622]."'");
86		print fetch_all_rows($dbh, "select a, b, c from innotest1 where c = '".$rnd_str[$j - 68]."'");
87		print fetch_all_rows($dbh, "select a, b, c from innotest1 where b = '".$rnd_str[$j - 644]."'");
88		print fetch_all_rows($dbh, "select d, b, c from innotest1 where c = '".$rnd_str[$j - 68]."'");
89		print fetch_all_rows($dbh, "select d, b, c from innotest1 where b = '".$rnd_str[$j - 677]."'");
90		print "\n";
91		}
92
93		if (0 == (($j - 1) % 1000)) {
94			print "round $j\n";
95		}
96	}
97
98	$dbh->do("commit");
99}
100
101$dbh->disconnect;				# close connection
102