~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/InnoDB combined database
4
#     (c) 2002 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 = 200000;
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 "Innotest1a: MySQL/InnoDB stress test in Perl\n";
18
print "-------------------------------------------\n";
19
print "This is a randomized stress test for concurrent inserts,\n";
20
print "updates, deletes, commits and rollbacks. The test will generate\n";
21
print "also a lot of deadlocks, duplicate key errors, and other SQL errors.\n";
22
print "\n";
23
print "You should run innotest1, innotest1a, and innotest1b concurrently.\n";
24
print "The thing to watch is that the server does not crash or does not\n";
25
print "print to the .err log anything. Currently, due to a buglet in MySQL,\n";
26
print "warnings about MySQL lock reservations can appear in the .err log.\n";
27
print "The test will run very long, even several hours. You can kill\n";
28
print "the perl processes running this test at any time and do CHECK\n";
29
print "TABLE on table innotest1 in the 'test' database.\n";
30
print "\n";
31
print "Some of these stress tests will print a lot of SQL errors\n";
32
print "to the standard output. That is not to be worried about.\n";
33
print "You can direct the output to a file like this:\n";
34
print "perl innotest1 > out1\n\n";
35
36
print "Generating random keys\n";
37
$random[$opt_loop_count] = 0;
38
$rnd_str[$opt_loop_count] = "a";
39
40
for ($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
65
$dbh->do("set autocommit = 0");
66
67
for ($i = 0; $i < 1; $i++) {
68
	print "loop $i\n";
69
70
	for ($j = 1; $j < $opt_loop_count - 10; $j = $j + 2) {
71
		$dbh->do(
72
		"insert into innotest1 (D, B, C) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."')");
73
		$dbh->do("update innotest1 set B = '".$rnd_str[$j + 2]."' where A = ".$random[$j + 5]);
74
		$dbh->do("update innotest1 SET D = D + 1 where A =".(($j - 1) / 2 - 777));
75
		$dbh->do("update innotest1 set B = '".$rnd_str[$j + 8]."' where A =".(($j - 1) / 2 - 770));
76
		$dbh->do("delete from innotest1 where A = ".$random[$random[$j]]);
77
78
		fetch_all_rows($dbh, "select b, c from innotest1 where a > ".$random[$j]." and a < ".($random[$j] + 7));
79
		
80
		if (0 == ($j % 37)) {
81
			$dbh->do("commit");
82
		}
83
84
		if (0 == ($j % 533)) {
85
			$dbh->do("rollback");
86
		}		
87
88
		if (0 == ($j % 537)) {
89
		print fetch_all_rows($dbh, "select c from innotest1 where c = '".$rnd_str[$j - 67]."'");
90
		print fetch_all_rows($dbh, "select b from innotest1 where b = '".$rnd_str[$j - 688]."'");
91
		print fetch_all_rows($dbh, "select b, c from innotest1 where c = '".$rnd_str[$j - 67]."'");
92
		print fetch_all_rows($dbh, "select b, c from innotest1 where b = '".$rnd_str[$j - 622]."'");
93
		print fetch_all_rows($dbh, "select a, b, c from innotest1 where c = '".$rnd_str[$j - 68]."'");
94
		print fetch_all_rows($dbh, "select a, b, c from innotest1 where b = '".$rnd_str[$j - 644]."'");
95
		print fetch_all_rows($dbh, "select d, b, c from innotest1 where c = '".$rnd_str[$j - 68]."'");
96
		print fetch_all_rows($dbh, "select d, b, c from innotest1 where b = '".$rnd_str[$j - 677]."'");
97
		print "\n";
98
		}
99
100
		if (0 == (($j - 1) % 1000)) {
101
			print "round $j\n";
102
		}
103
	}	
104
	
105
	$dbh->do("commit");
106
}				
107
108
$dbh->disconnect;				# close connection