3
# This is a test with uses many processes to test a MySQL server.
6
$opt_loop_count=10000; # 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;
19
$opt_host=$opt_user=$opt_password=""; $opt_db="test";
21
GetOptions("host=s","db=s","user=s","password=s","loop-count=i","skip-create","skip-in","skip-delete","verbose","fast-insert","lock-tables","debug","fast","force","threads=i") || 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 truncate from $opt_threads multiple connections $opt_loop_count times\n";
26
@testtables = ( ["bench_f31", "type=heap"]);
29
#### Start timeing and start test
32
$start_time=new Benchmark;
33
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
34
$opt_user, $opt_password,
35
{ PrintError => 0}) || die $DBI::errstr;
36
if (!$opt_skip_create)
39
foreach $table_def (@testtables)
41
my ($table,$extra)= ($table_def->[0], $table_def->[1]);
42
print "Creating table $table in database $opt_db\n";
43
$dbh->do("drop table if exists $table");
44
$dbh->do("create table $table".
45
" (id int(6) not null,".
46
" info varchar(32)," .
47
" marker timestamp," .
48
" flag int not null," .
49
" primary key(id)) $extra")
55
$dbh->disconnect; $dbh=0; # Close handler
62
for ($i=0 ; $i < $opt_threads ; $i ++)
64
test_truncate() if (($pid=fork()) == 0); $work{$pid}="truncate";
67
print "Started $opt_threads threads\n";
70
$running_insert_threads=$opt_threads;
71
while (($pid=wait()) != -1)
74
print "thread '" . $work{$pid} . "' finished with exit code $ret\n";
75
--$running_insert_threads;
76
$errors++ if ($ret != 0);
83
if (!$opt_skip_delete && !$errors)
86
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
87
$opt_user, $opt_password,
88
{ PrintError => 0}) || die $DBI::errstr;
90
foreach $table_def (@testtables)
92
$dbh->do("drop table " . $table_def->[0]);
94
$dbh->disconnect; $dbh=0; # Close handler
97
print ($errors ? "Test failed\n" :"Test ok\n");
98
$end_time=new Benchmark;
99
print "Total time: " .
100
timestr(timediff($end_time, $start_time),"noc") . "\n";
106
# Insert records in the table
111
my ($dbh,$i,$j,$count,$table_def,$table);
113
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
114
$opt_user, $opt_password,
115
{ PrintError => 0}) || die $DBI::errstr;
117
for ($count=0; $count < $opt_loop_count ; $count++)
119
my ($table)= ($testtables[0]->[0]);
120
$dbh->do("truncate table $table") || die "Got error on truncate: $DBI::errstr\n";
122
$dbh->disconnect; $dbh=0;
123
print "Test_truncate: Run $count times\n";