~drizzle-trunk/drizzle/development

2324.2.1 by patrick crews
Initial work for sql-bench mode. Added sql-bench to the tree. Test script for running entire suite added
1
#!/usr/bin/perl
2318.2.38 by Olaf van der Spek
Merge trunk
2
############################################################################
3
#     Stress test for MySQL/Innobase combined database
4
#     (c) 2000 Innobase Oy & MySQL AB
5
#
6
############################################################################
7
2324.2.1 by patrick crews
Initial work for sql-bench mode. Added sql-bench to the tree. Test script for running entire suite added
8
use Cwd;
2318.2.38 by Olaf van der Spek
Merge trunk
9
use DBI;
10
use Benchmark;
11
12
$opt_loop_count = 100000;
13
2324.2.1 by patrick crews
Initial work for sql-bench mode. Added sql-bench to the tree. Test script for running entire suite added
14
$pwd = cwd(); $pwd = "." if ($pwd eq '');
2318.2.38 by Olaf van der Spek
Merge trunk
15
require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
16
17
print "Innotest2b: MySQL/InnoDB stress test in Perl for FOREIGN keys\n";
18
print "------------------------------------------------------------\n";
19
print "This is a randomized stress test for concurrent inserts,\n";
20
print "updates, deletes, commits and rollbacks with foreign keys with\n";
21
print "the ON DELETE ... clause. The test will generate\n";
22
print "also a lot of deadlocks, duplicate key errors, and other SQL errors.\n";
23
print "\n";
24
print "You should run innotest2, innotest2a, and innotest2b concurrently.\n";
25
print "The thing to watch is that the server does not crash or does not\n";
26
print "print to the .err log anything. Currently, due to a buglet in MySQL,\n";
27
print "warnings about MySQL lock reservations can appear in the .err log.\n";
28
print "The test will run very long, even several hours. You can kill\n";
29
print "the perl processes running this test at any time and do CHECK\n";
30
print "TABLE on tables innotest2a, b, c, d in the 'test' database.\n";
31
print "\n";
32
print "Some of these stress tests will print a lot of SQL errors\n";
33
print "to the standard output. That is not to be worried about.\n";
34
print "You can direct the output to a file like this:\n";
35
print "perl innotest2 > out2\n\n";
36
37
print "Generating random keys\n";
38
$random[$opt_loop_count] = 0;
39
$rnd_str[$opt_loop_count] = "a";
40
41
for ($i = 0; $i < $opt_loop_count; $i++) {
42
43
	$random[$i] = ($i * 98641) % $opt_loop_count;
44
45
  	if (0 == ($random[$i] % 3)) {
46
  		$rnd_str[$i] = "khD";
47
	} else { if (1 == ($random[$i] % 3)) {
48
		$rnd_str[$i] = "khd";
49
	} else { if (2 == ($random[$i] % 3)) {
50
		$rnd_str[$i] = "kHd";
51
	}}}
52
53
	for ($j = 0; $j < (($i * 764877) % 10); $j++) {
54
		$rnd_str[$i] = $rnd_str[$i]."k";
55
	}	
56
}
57
58
####
59
####  Connect
60
####
61
62
$dbh = $server->connect();
63
64
$dbh->do("set autocommit = 0");
65
66
for ($i = 0; $i < 1; $i++) {
67
	print "loop $i\n";
68
69
	for ($j = 0; $j < $opt_loop_count - 10; $j = $j + 2) {
70
		$dbh->do(
71
		"insert into innotest2b (D, B, C) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."')")
72
		|| print $dbh->errstr;
73
74
		$dbh->do(
75
		"insert into innotest2a (D, B, C) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."')")
76
		|| print $dbh->errstr;
77
		
78
		$dbh->do(
79
		"insert into innotest2c (D, B, C) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."')")
80
		|| print $dbh->errstr;
81
82
		$dbh->do("delete from innotest2b where A = ".$random[$random[$j]])
83
		|| print $dbh->errstr;
84
85
		$dbh->do("update innotest2b set A = A + 1 where A = ".$random[$j])
86
		|| print $dbh->errstr;
87
88
		if (0 == ($j % 10)) {
89
			$dbh->do("commit");
90
		}
91
92
		if (0 == ($j % 39)) {
93
			$dbh->do("rollback");
94
		}		
95
96
		if (0 == ($j % 1000)) {
97
			print "round $j\n";
98
		}
99
	}	
100
	
101
	$dbh->do("commit");
102
}				
103
104
$dbh->disconnect;				# close connection