2
############################################################################
3
# Stress test for MySQL/InnoDB combined database
4
# (c) 2002 Innobase Oy & MySQL AB
6
############################################################################
2
############################################################################
3
# Stress test for MySQL/InnoDB combined database
4
# (c) 2002 Innobase Oy & MySQL AB
6
############################################################################
12
$opt_loop_count = 100000;
12
$opt_loop_count = 100000;
14
14
$pwd = cwd(); $pwd = "." if ($pwd eq '');
15
require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
17
print "Innotest1: 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";
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";
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";
36
print "Generating random keys\n";
37
$random[$opt_loop_count] = 0;
38
$rnd_str[$opt_loop_count] = "a";
40
for ($i = 0; $i < $opt_loop_count; $i++) {
42
$random[$i] = ($i * 63857) % $opt_loop_count;
44
if (0 == ($random[$i] % 3)) {
45
$rnd_str[$i] = "kjgclgrtfuylfluyfyufyulfulfyyulofuyolfyufyufuyfyufyufyufyufyyufujhfghd";
46
} else { if (1 == ($random[$i] % 3)) {
48
} else { if (2 == ($random[$i] % 3)) {
52
for ($j = 0; $j < (($i * 764877) % 20); $j++) {
53
$rnd_str[$i] = $rnd_str[$i]."k";
61
$dbh = $server->connect()
64
$dbh->do("set autocommit = 0");
68
for ($i = 0; $i < 1; $i++) {
70
print "Dropping table innotest1\n";
72
$dbh->do("drop table innotest1");
74
print "Creating table innotest1\n";
77
"create table innotest1 (A INT NOT NULL AUTO_INCREMENT, D INT NOT NULL, B VARCHAR(200) NOT NULL, C VARCHAR(175), E TIMESTAMP, F TIMESTAMP, G DATETIME, PRIMARY KEY (A, D), INDEX
78
(B, C), INDEX (C), INDEX (D), INDEX(E), INDEX(G)) TYPE = INNODB")
81
for ($j = 2; $j < $opt_loop_count - 10; $j = $j + 2) {
85
"insert into innotest1 (D, B, C, F, G) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."', NULL, NULL)");
88
"insert into innotest1 (D, B, C, F, G) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."', NOW(), NOW())");
91
$dbh->do("update innotest1 set B = '".$rnd_str[$j + 7]."' where A = ".$random[$j + 5]);
93
$dbh->do("update innotest1 SET D = D + 1 where A =".($j / 2 - 500));
95
$dbh->do("update innotest1 set B = '".$rnd_str[$j + 1]."' where A =".($j / 2 - 505));
97
$dbh->do("delete from innotest1 where A = ".$random[$random[$j]]);
99
fetch_all_rows($dbh, "select b, c from innotest1 where a > ".$random[$j]." and a < ".($random[$j] + 7));
101
if (0 == ($j % 10)) {
105
if (0 == ($j % 97)) {
106
fetch_all_rows($dbh, "select c, e, f, g from innotest1 where c = '".$rnd_str[$j - 68]."'");
107
fetch_all_rows($dbh, "select b, e, f, g from innotest1 where b = '".$rnd_str[$j - 677]."'");
108
fetch_all_rows($dbh, "select b, c, e, f, g from innotest1 where c = '".$rnd_str[$j - 68]."'");
109
fetch_all_rows($dbh, "select b, c, g from innotest1 where b = '".$rnd_str[$j - 677]."'");
110
fetch_all_rows($dbh, "select a, b, c, e, f, g from innotest1 where c = '".$rnd_str[$j - 68]."'");
111
fetch_all_rows($dbh, "select a, b, c, e, f, g from innotest1 where b = '".$rnd_str[$j - 677]."'");
112
fetch_all_rows($dbh, "select d, b, c from innotest1 where c = '".$rnd_str[$j - 68]."'");
113
fetch_all_rows($dbh, "select d, b, c, g from innotest1 where b = '".$rnd_str[$j - 677]."'");
115
$dbh->do("rollback");
118
for ($k = 1; $k < 10; $k++) {
120
$n += fetch_all_rows($dbh,
121
"SELECT a, d from innotest1 where a = ".(($k * 1764767) % $j));
123
$n += fetch_all_rows($dbh,
124
"SELECT * from innotest1 where a = ".(($k * 187567) % $j));
128
if (0 == ($j % 1000)) {
129
print "round $j, $n rows fetched\n";
132
if (0 == ($j % 20000)) {
133
print "Checking table innotest1...\n";
134
$dbh->do("check table innotest1");
135
print "Table checked.\n";
142
$dbh->disconnect; # close connection
15
require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
17
print "Innotest1: 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";
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";
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";
36
print "Generating random keys\n";
37
$random[$opt_loop_count] = 0;
38
$rnd_str[$opt_loop_count] = "a";
40
for ($i = 0; $i < $opt_loop_count; $i++) {
42
$random[$i] = ($i * 63857) % $opt_loop_count;
44
if (0 == ($random[$i] % 3)) {
45
$rnd_str[$i] = "kjgclgrtfuylfluyfyufyulfulfyyulofuyolfyufyufuyfyufyufyufyufyyufujhfghd";
46
} else { if (1 == ($random[$i] % 3)) {
48
} else { if (2 == ($random[$i] % 3)) {
52
for ($j = 0; $j < (($i * 764877) % 20); $j++) {
53
$rnd_str[$i] = $rnd_str[$i]."k";
61
$dbh = $server->connect()
64
$dbh->do("set autocommit = 0");
68
for ($i = 0; $i < 1; $i++) {
70
print "Dropping table innotest1\n";
72
$dbh->do("drop table innotest1");
74
print "Creating table innotest1\n";
77
"create table innotest1 (A INT NOT NULL AUTO_INCREMENT, D INT NOT NULL, B VARCHAR(200) NOT NULL, C VARCHAR(175), E TIMESTAMP, F TIMESTAMP, G DATETIME, PRIMARY KEY (A, D), INDEX
78
(B, C), INDEX (C), INDEX (D), INDEX(E), INDEX(G)) TYPE = INNODB")
81
for ($j = 2; $j < $opt_loop_count - 10; $j = $j + 2) {
85
"insert into innotest1 (D, B, C, F, G) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."', NULL, NULL)");
88
"insert into innotest1 (D, B, C, F, G) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."', NOW(), NOW())");
91
$dbh->do("update innotest1 set B = '".$rnd_str[$j + 7]."' where A = ".$random[$j + 5]);
93
$dbh->do("update innotest1 SET D = D + 1 where A =".($j / 2 - 500));
95
$dbh->do("update innotest1 set B = '".$rnd_str[$j + 1]."' where A =".($j / 2 - 505));
97
$dbh->do("delete from innotest1 where A = ".$random[$random[$j]]);
99
fetch_all_rows($dbh, "select b, c from innotest1 where a > ".$random[$j]." and a < ".($random[$j] + 7));
101
if (0 == ($j % 10)) {
105
if (0 == ($j % 97)) {
106
fetch_all_rows($dbh, "select c, e, f, g from innotest1 where c = '".$rnd_str[$j - 68]."'");
107
fetch_all_rows($dbh, "select b, e, f, g from innotest1 where b = '".$rnd_str[$j - 677]."'");
108
fetch_all_rows($dbh, "select b, c, e, f, g from innotest1 where c = '".$rnd_str[$j - 68]."'");
109
fetch_all_rows($dbh, "select b, c, g from innotest1 where b = '".$rnd_str[$j - 677]."'");
110
fetch_all_rows($dbh, "select a, b, c, e, f, g from innotest1 where c = '".$rnd_str[$j - 68]."'");
111
fetch_all_rows($dbh, "select a, b, c, e, f, g from innotest1 where b = '".$rnd_str[$j - 677]."'");
112
fetch_all_rows($dbh, "select d, b, c from innotest1 where c = '".$rnd_str[$j - 68]."'");
113
fetch_all_rows($dbh, "select d, b, c, g from innotest1 where b = '".$rnd_str[$j - 677]."'");
115
$dbh->do("rollback");
118
for ($k = 1; $k < 10; $k++) {
120
$n += fetch_all_rows($dbh,
121
"SELECT a, d from innotest1 where a = ".(($k * 1764767) % $j));
123
$n += fetch_all_rows($dbh,
124
"SELECT * from innotest1 where a = ".(($k * 187567) % $j));
128
if (0 == ($j % 1000)) {
129
print "round $j, $n rows fetched\n";
132
if (0 == ($j % 20000)) {
133
print "Checking table innotest1...\n";
134
$dbh->do("check table innotest1");
135
print "Table checked.\n";
142
$dbh->disconnect; # close connection