3
# This is a test with uses processes to insert, select and drop tables.
6
$opt_loop_count=100000; # Change this to make test harder/easier
8
##################### Standard benchmark inits ##############################
16
$opt_skip_create=$opt_skip_in=$opt_verbose=$opt_fast_insert=
17
$opt_lock_tables=$opt_debug=$opt_skip_delete=$opt_fast=$opt_force=0;
18
$opt_host=""; $opt_db="test";
20
GetOptions("host=s","db=s","loop-count=i","skip-create","skip-in","skip-delete",
21
"verbose","fast-insert","lock-tables","debug","fast","force") || die "Aborted";
22
$opt_verbose=$opt_debug=$opt_lock_tables=$opt_fast_insert=$opt_fast=$opt_skip_in=$opt_force=undef; # Ignore warnings from these
24
print "Testing 5 multiple connections to a server with 1 insert, 2 drop/rename\n";
25
print "1 select and 1 flush thread\n";
27
$firsttable = "bench_f1";
30
#### Start timeing and start test
33
$start_time=new Benchmark;
34
if (!$opt_skip_create)
36
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
37
$opt_user, $opt_password,
38
{ PrintError => 0}) || die $DBI::errstr;
39
$dbh->do("drop table if exists $firsttable, ${firsttable}_1, ${firsttable}_2");
41
print "Creating table $firsttable in database $opt_db\n";
42
$dbh->do("create table $firsttable (id int(6) not null, info varchar(32), marker char(1), primary key(id))") || die $DBI::errstr;
43
$dbh->disconnect; $dbh=0; # Close handler
51
test_insert() if (($pid=fork()) == 0); $work{$pid}="insert";
52
test_drop(1) if (($pid=fork()) == 0); $work{$pid}="drop 1";
53
test_drop(2) if (($pid=fork()) == 0); $work{$pid}="drop 2";
54
test_select() if (($pid=fork()) == 0); $work{$pid}="select";
55
test_flush() if (($pid=fork()) == 0); $work{$pid}="flush";
58
while (($pid=wait()) != -1)
61
print "thread '" . $work{$pid} . "' finished with exit code $ret\n";
62
$errors++ if ($ret != 0);
65
if (!$opt_skip_delete && !$errors)
67
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
68
$opt_user, $opt_password,
69
{ PrintError => 0}) || die $DBI::errstr;
70
$dbh->do("drop table $firsttable");
71
$dbh->disconnect; $dbh=0; # Close handler
73
print ($errors ? "Test failed\n" :"Test ok\n");
75
$end_time=new Benchmark;
76
print "Total time: " .
77
timestr(timediff($end_time, $start_time),"noc") . "\n";
82
# Insert records in the table
89
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
90
$opt_user, $opt_password,
91
{ PrintError => 0}) || die $DBI::errstr;
92
for ($i=0 ; $i < $opt_loop_count; $i++)
94
if (!$dbh->do("insert into $firsttable values ($i,'This is entry $i','')"))
96
print "Warning; Got error on insert: " . $dbh->errstr . "\n" if (! ($dbh->errstr =~ /doesn't exist/));
99
$dbh->disconnect; $dbh=0;
100
print "Test_insert: Inserted $i rows\n";
108
my ($dbh,$i,$sth,$error_counter,$sleep_time);
110
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
111
$opt_user, $opt_password,
112
{ PrintError => 0}) || die $DBI::errstr;
115
for ($i=0 ; $i < $opt_loop_count ; $i++)
118
# Check if insert thread is ready
119
$sth=$dbh->prepare("select count(*) from $firsttable") || die "Got error on select from $firsttable: $dbh->errstr\n";
120
if (!$sth->execute || !(@row = $sth->fetchrow_array()) ||
125
last if ($error_counter++ == 5);
131
# Change to use a new table
132
$dbh->do("create table ${firsttable}_$id (id int(6) not null, info varchar(32), marker char(1), primary key(id))") || die $DBI::errstr;
133
$dbh->do("drop table if exists $firsttable") || die "Got error on drop table: $dbh->errstr\n";
134
if (!$dbh->do("alter table ${firsttable}_$id rename to $firsttable"))
136
print "Warning; Got error from alter table: " . $dbh->errstr . "\n" if (! ($dbh->errstr =~ /already exist/));
137
$dbh->do("drop table if exists ${firsttable}_$id") || die "Got error on drop table: $dbh->errstr\n";
140
$dbh->do("drop table if exists $firsttable,${firsttable}_$id") || die "Got error on drop table: $dbh->errstr\n";
141
$dbh->disconnect; $dbh=0;
142
print "Test_drop: Did a drop $i times\n";
153
my ($dbh,$i,$sth,@row,$error_counter,$sleep_time);
155
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
156
$opt_user, $opt_password,
157
{ PrintError => 0}) || die $DBI::errstr;
161
for ($i=0 ; $i < $opt_loop_count ; $i++)
164
$sth=$dbh->prepare("select sum(t.id) from $firsttable as t,$firsttable as t2") || die "Got error on select: $dbh->errstr;\n";
167
@row = $sth->fetchrow_array();
173
print "Warning; Got error from select: " . $dbh->errstr . "\n" if (! ($dbh->errstr =~ /doesn't exist/));
175
last if ($error_counter++ == 5);
179
$dbh->disconnect; $dbh=0;
180
print "Test_select: ok\n";
190
my ($dbh,$i,$sth,@row,$error_counter,$sleep_time);
192
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
193
$opt_user, $opt_password,
194
{ PrintError => 0}) || die $DBI::errstr;
198
for ($i=0 ; $i < $opt_loop_count ; $i++)
201
$sth=$dbh->prepare("select count(*) from $firsttable") || die "Got error on prepar: $dbh->errstr;\n";
204
@row = $sth->fetchrow_array();
207
$dbh->do("flush tables $firsttable") || die "Got error on flush table: " . $dbh->errstr . "\n";
211
print "Warning; Got error from select: " . $dbh->errstr . "\n" if (! ($dbh->errstr =~ /doesn't exist/));
213
last if ($error_counter++ == 5);
217
$dbh->disconnect; $dbh=0;
218
print "Test_select: ok\n";