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_delete=$opt_skip_flush=0;
17
$opt_host=""; $opt_db="test";
19
GetOptions("host=s","db=s","loop-count=i","skip-create","skip-delete",
20
"skip-flush") || die "Aborted";
22
print "Testing 5 multiple connections to a server with 1 insert, 1 rename\n";
23
print "1 select and 1 flush thread\n";
25
$firsttable = "bench_f1";
28
#### Start timing and start test
31
$start_time=new Benchmark;
32
if (!$opt_skip_create)
34
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
35
$opt_user, $opt_password,
36
{ PrintError => 0}) || die $DBI::errstr;
37
$dbh->do("drop table if exists $firsttable, ${firsttable}_1, ${firsttable}_2");
39
print "Creating table $firsttable in database $opt_db\n";
40
$dbh->do("create table $firsttable (id int(6) not null, info varchar(32), marker char(1), primary key(id))") || die $DBI::errstr;
41
$dbh->disconnect; $dbh=0; # Close handler
49
test_insert() if (($pid=fork()) == 0); $work{$pid}="insert";
50
test_rename(1) if (($pid=fork()) == 0); $work{$pid}="rename 1";
51
test_rename(2) if (($pid=fork()) == 0); $work{$pid}="rename 2";
52
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. Delete table when test is finished
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','')"))
97
$dbh->do("drop table ${firsttable}"); # End other threads
98
die "Warning; Got error on insert: " . $error . "\n";
102
$dbh->do("drop table ${firsttable}") || die "Got error on drop table: " . $dbh->errstr . "\n";
103
$dbh->disconnect; $dbh=0;
104
print "Test_insert: Inserted $i rows\n";
112
my ($dbh,$i,$error_counter,$sleep_time);
114
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
115
$opt_user, $opt_password,
116
{ PrintError => 0}) || die $DBI::errstr;
119
for ($i=0 ; $i < $opt_loop_count ; $i++)
122
$dbh->do("create table ${firsttable}_$id (id int(6) not null, info varchar(32), marker char(1), primary key(id))") || die $DBI::errstr;
123
if (!$dbh->do("rename table $firsttable to ${firsttable}_${id}_1, ${firsttable}_$id to ${firsttable}"))
125
last if ($dbh->errstr =~ /^Can\'t find/);
126
die "Got error on rename: " . $dbh->errstr . "\n";
128
$dbh->do("drop table ${firsttable}_${id}_1") || die "Got error on drop table: " . $dbh->errstr . "\n";
130
$dbh->disconnect; $dbh=0;
131
print "Test_drop: Did a drop $i times\n";
142
my ($dbh,$i,$sth,@row,$sleep_time);
144
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
145
$opt_user, $opt_password,
146
{ PrintError => 0}) || die $DBI::errstr;
149
for ($i=0 ; $i < $opt_loop_count ; $i++)
152
$sth=$dbh->prepare("select sum(t.id) from $firsttable as t,$firsttable as t2") || die "Got error on select: $dbh->errstr;\n";
155
@row = $sth->fetchrow_array();
161
last if (! ($dbh->errstr =~ /doesn\'t exist/));
162
die "Got error on select: " . $dbh->errstr . "\n";
165
$dbh->disconnect; $dbh=0;
166
print "Test_select: ok\n";
176
my ($dbh,$i,$sth,@row,$error_counter,$sleep_time);
178
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
179
$opt_user, $opt_password,
180
{ PrintError => 0}) || die $DBI::errstr;
184
for ($i=0 ; $i < $opt_loop_count ; $i++)
187
$sth=$dbh->prepare("select count(*) from $firsttable") || die "Got error on prepar: $dbh->errstr;\n";
190
@row = $sth->fetchrow_array();
193
$dbh->do("flush tables $firsttable") || die "Got error on flush table: " . $dbh->errstr . "\n";
197
last if (! ($dbh->errstr =~ /doesn\'t exist/));
198
die "Got error on flush: " . $dbh->errstr . "\n";
201
$dbh->disconnect; $dbh=0;
202
print "Test_select: ok\n";