~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to tests/truncate.pl

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
#
 
3
# This is a test with uses many processes to test a MySQL server.
 
4
#
 
5
 
 
6
$opt_loop_count=10000; # Change this to make test harder/easier
 
7
 
 
8
##################### Standard benchmark inits ##############################
 
9
 
 
10
use DBI;
 
11
use Getopt::Long;
 
12
use Benchmark;
 
13
 
 
14
package main;
 
15
 
 
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_threads=2;
 
19
$opt_host=$opt_user=$opt_password=""; $opt_db="test";
 
20
 
 
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
 
23
 
 
24
print "Testing truncate from $opt_threads multiple connections $opt_loop_count times\n";
 
25
 
 
26
@testtables = ( ["bench_f31", "type=heap"]);
 
27
 
 
28
####
 
29
####  Start timeing and start test
 
30
####
 
31
 
 
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)
 
37
{
 
38
  my $table_def;
 
39
  foreach $table_def (@testtables)
 
40
  {
 
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")
 
50
 
 
51
      or die $DBI::errstr;
 
52
  }
 
53
}
 
54
 
 
55
$dbh->disconnect; $dbh=0;       # Close handler
 
56
$|= 1;                          # Autoflush
 
57
 
 
58
####
 
59
#### Start the tests
 
60
####
 
61
 
 
62
for ($i=0 ; $i < $opt_threads ; $i ++)
 
63
{
 
64
  test_truncate() if (($pid=fork()) == 0); $work{$pid}="truncate";
 
65
}
 
66
 
 
67
print "Started $opt_threads threads\n";
 
68
 
 
69
$errors=0;
 
70
$running_insert_threads=$opt_threads;
 
71
while (($pid=wait()) != -1)
 
72
{
 
73
  $ret=$?/256;
 
74
  print "thread '" . $work{$pid} . "' finished with exit code $ret\n";
 
75
  --$running_insert_threads;
 
76
  $errors++ if ($ret != 0);
 
77
}
 
78
 
 
79
#
 
80
# Cleanup
 
81
#
 
82
 
 
83
if (!$opt_skip_delete && !$errors)
 
84
{
 
85
  my $table_def;
 
86
  $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
 
87
                      $opt_user, $opt_password,
 
88
                    { PrintError => 0}) || die $DBI::errstr;
 
89
 
 
90
  foreach $table_def (@testtables)
 
91
  {
 
92
    $dbh->do("drop table " . $table_def->[0]);
 
93
  }
 
94
  $dbh->disconnect; $dbh=0;     # Close handler
 
95
}
 
96
 
 
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";
 
101
 
 
102
exit(0);
 
103
 
 
104
 
 
105
#
 
106
# Insert records in the table
 
107
#
 
108
 
 
109
sub test_truncate
 
110
{
 
111
  my ($dbh,$i,$j,$count,$table_def,$table);
 
112
 
 
113
  $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
 
114
                      $opt_user, $opt_password,
 
115
                    { PrintError => 0}) || die $DBI::errstr;
 
116
 
 
117
  for ($count=0; $count < $opt_loop_count ; $count++)
 
118
  {
 
119
    my ($table)= ($testtables[0]->[0]);
 
120
    $dbh->do("truncate table $table") || die "Got error on truncate: $DBI::errstr\n";
 
121
  }
 
122
  $dbh->disconnect; $dbh=0;
 
123
  print "Test_truncate: Run $count times\n";
 
124
  exit(0);
 
125
}