3
# Copyright (C) 2000, 2001 MySQL AB
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; version 2 of the License.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
# This is a test with uses processes to insert, select and drop tables.
22
$opt_loop_count=100000; # Change this to make test harder/easier
24
##################### Standard benchmark inits ##############################
32
$opt_skip_create=$opt_skip_delete=$opt_skip_flush=0;
33
$opt_host=""; $opt_db="test";
35
GetOptions("host=s","db=s","loop-count=i","skip-create","skip-delete",
36
"skip-flush") || die "Aborted";
38
print "Testing 5 multiple connections to a server with 1 insert, 1 rename\n";
39
print "1 select and 1 flush thread\n";
41
$firsttable = "bench_f1";
44
#### Start timing and start test
47
$start_time=new Benchmark;
48
if (!$opt_skip_create)
50
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
51
$opt_user, $opt_password,
52
{ PrintError => 0}) || die $DBI::errstr;
53
$dbh->do("drop table if exists $firsttable, ${firsttable}_1, ${firsttable}_2");
55
print "Creating table $firsttable in database $opt_db\n";
56
$dbh->do("create table $firsttable (id int(6) not null, info varchar(32), marker char(1), primary key(id))") || die $DBI::errstr;
57
$dbh->disconnect; $dbh=0; # Close handler
65
test_insert() if (($pid=fork()) == 0); $work{$pid}="insert";
66
test_rename(1) if (($pid=fork()) == 0); $work{$pid}="rename 1";
67
test_rename(2) if (($pid=fork()) == 0); $work{$pid}="rename 2";
68
test_select() if (($pid=fork()) == 0); $work{$pid}="select";
71
test_flush() if (($pid=fork()) == 0); $work{$pid}="flush";
74
while (($pid=wait()) != -1)
77
print "thread '" . $work{$pid} . "' finished with exit code $ret\n";
78
$errors++ if ($ret != 0);
81
if (!$opt_skip_delete && !$errors)
83
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
84
$opt_user, $opt_password,
85
{ PrintError => 0}) || die $DBI::errstr;
86
$dbh->do("drop table $firsttable");
87
$dbh->disconnect; $dbh=0; # Close handler
89
print ($errors ? "Test failed\n" :"Test ok\n");
91
$end_time=new Benchmark;
92
print "Total time: " .
93
timestr(timediff($end_time, $start_time),"noc") . "\n";
98
# Insert records in the table. Delete table when test is finished
105
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
106
$opt_user, $opt_password,
107
{ PrintError => 0}) || die $DBI::errstr;
108
for ($i=0 ; $i < $opt_loop_count; $i++)
110
if (!$dbh->do("insert into $firsttable values ($i,'This is entry $i','')"))
113
$dbh->do("drop table ${firsttable}"); # End other threads
114
die "Warning; Got error on insert: " . $error . "\n";
118
$dbh->do("drop table ${firsttable}") || die "Got error on drop table: " . $dbh->errstr . "\n";
119
$dbh->disconnect; $dbh=0;
120
print "Test_insert: Inserted $i rows\n";
128
my ($dbh,$i,$error_counter,$sleep_time);
130
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
131
$opt_user, $opt_password,
132
{ PrintError => 0}) || die $DBI::errstr;
135
for ($i=0 ; $i < $opt_loop_count ; $i++)
138
$dbh->do("create table ${firsttable}_$id (id int(6) not null, info varchar(32), marker char(1), primary key(id))") || die $DBI::errstr;
139
if (!$dbh->do("rename table $firsttable to ${firsttable}_${id}_1, ${firsttable}_$id to ${firsttable}"))
141
last if ($dbh->errstr =~ /^Can\'t find/);
142
die "Got error on rename: " . $dbh->errstr . "\n";
144
$dbh->do("drop table ${firsttable}_${id}_1") || die "Got error on drop table: " . $dbh->errstr . "\n";
146
$dbh->disconnect; $dbh=0;
147
print "Test_drop: Did a drop $i times\n";
158
my ($dbh,$i,$sth,@row,$sleep_time);
160
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
161
$opt_user, $opt_password,
162
{ PrintError => 0}) || die $DBI::errstr;
165
for ($i=0 ; $i < $opt_loop_count ; $i++)
168
$sth=$dbh->prepare("select sum(t.id) from $firsttable as t,$firsttable as t2") || die "Got error on select: $dbh->errstr;\n";
171
@row = $sth->fetchrow_array();
177
last if (! ($dbh->errstr =~ /doesn\'t exist/));
178
die "Got error on select: " . $dbh->errstr . "\n";
181
$dbh->disconnect; $dbh=0;
182
print "Test_select: ok\n";
192
my ($dbh,$i,$sth,@row,$error_counter,$sleep_time);
194
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
195
$opt_user, $opt_password,
196
{ PrintError => 0}) || die $DBI::errstr;
200
for ($i=0 ; $i < $opt_loop_count ; $i++)
203
$sth=$dbh->prepare("select count(*) from $firsttable") || die "Got error on prepar: $dbh->errstr;\n";
206
@row = $sth->fetchrow_array();
209
$dbh->do("flush tables $firsttable") || die "Got error on flush table: " . $dbh->errstr . "\n";
213
last if (! ($dbh->errstr =~ /doesn\'t exist/));
214
die "Got error on flush: " . $dbh->errstr . "\n";
217
$dbh->disconnect; $dbh=0;
218
print "Test_select: ok\n";