~mysql/mysql-server/mysql-6.0

« back to all changes in this revision

Viewing changes to tests/fork2_test.pl

  • Committer: bk at mysql
  • Date: 2000-07-31 19:29:14 UTC
  • Revision ID: sp1r-bk@work.mysql.com-20000731192914-08846
Import changeset

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 5 processes to insert, update and select from
 
4
# two tables.
 
5
# One inserts records in the tables, one updates some record in it and
 
6
# the last 3 does different selects on the tables.
 
7
# Er, hmmm..., something like that :^)
 
8
# Modified to do crazy-join, � la Nasdaq.
 
9
 
 
10
$opt_loop_count=10000; # Change this to make test harder/easier
 
11
 
 
12
##################### Standard benchmark inits ##############################
 
13
 
 
14
use Mysql;
 
15
use Getopt::Long;
 
16
use Benchmark;
 
17
 
 
18
package main;
 
19
 
 
20
$opt_skip_create=$opt_skip_in=$opt_verbose=$opt_fast_insert=
 
21
  $opt_lock_tables=$opt_debug=$opt_skip_delete=$opt_fast=$opt_force=0;
 
22
$opt_host=""; $opt_db="test";
 
23
 
 
24
GetOptions("host=s","db=s","loop-count=i","skip-create","skip-in",
 
25
           "skip-delete", "verbose","fast-insert","lock-tables","debug","fast",
 
26
           "force") || die "Aborted";
 
27
$opt_verbose=$opt_debug=$opt_lock_tables=$opt_fast_insert=$opt_fast=$opt_skip_in=$Mysql::db_errstr=$opt_force=undef;  # Ignore warnings from these
 
28
 
 
29
print "Testing 9 multiple connections to a server with 1 insert/update\n";
 
30
print "and 8 select connections.\n";
 
31
 
 
32
 
 
33
@testtables = qw(bench_f21 bench_f22 bench_f23 bench_f24 bench_f25);
 
34
$numtables = $#testtables;      # make emacs happier
 
35
$dtable = "directory";
 
36
####  
 
37
####  Start timeing and start test
 
38
####
 
39
 
 
40
$start_time=new Benchmark;
 
41
if (!$opt_skip_create)
 
42
{
 
43
  $dbh = Mysql->Connect($opt_host, $opt_db) || die $Mysql::db_errstr;
 
44
  $Mysql::QUIET = 1;
 
45
  foreach $table (@testtables) {
 
46
      $dbh->Query("drop table $table");
 
47
  }
 
48
  $dbh->Query("drop table $dtable");
 
49
  $Mysql::QUIET = 0;
 
50
 
 
51
  foreach $table (@testtables) {
 
52
      print "Creating table $table in database $opt_db\n";
 
53
      $dbh->Query("create table $table".
 
54
                  " (id int(6) not null,".
 
55
                  " info varchar(32),".
 
56
                  " marker timestamp,".
 
57
                  " primary key(id))")
 
58
          or die $Mysql::db_errstr;
 
59
  }
 
60
  print "Creating directory table $dtable in $opt_db\n";
 
61
  $dbh->Query("create table $dtable (id int(6), last int(6))")
 
62
      or die $Mysql::db_errstr;
 
63
  # Populate directory table
 
64
  for $i ( 0 .. $numtables ) {
 
65
      $dbh->Query("insert into $dtable values($i, 0)");
 
66
  }
 
67
  $dbh=0;                       # Close handler
 
68
}
 
69
$|= 1;                          # Autoflush
 
70
 
 
71
####
 
72
#### Start the tests
 
73
####
 
74
 
 
75
#$test_index = 0;
 
76
 
 
77
test_1() if (($pid=fork()) == 0); $work{$pid}="insert";
 
78
test_2() if (($pid=fork()) == 0); $work{$pid}="simple1";
 
79
test_3() if (($pid=fork()) == 0); $work{$pid}="funny1";
 
80
test_2() if (($pid=fork()) == 0); $work{$pid}="simple2";
 
81
test_3() if (($pid=fork()) == 0); $work{$pid}="funny2";
 
82
test_2() if (($pid=fork()) == 0); $work{$pid}="simple3";
 
83
test_3() if (($pid=fork()) == 0); $work{$pid}="funny3";
 
84
test_2() if (($pid=fork()) == 0); $work{$pid}="simple4";
 
85
test_3() if (($pid=fork()) == 0); $work{$pid}="funny4";
 
86
 
 
87
$errors=0;
 
88
while (($pid=wait()) != -1)
 
89
{
 
90
  $ret=$?/256;
 
91
  print "thread '" . $work{$pid} . "' finnished with exit code $ret\n";
 
92
  $errors++ if ($ret != 0);
 
93
}
 
94
 
 
95
if (!$opt_skip_delete && !$errors)
 
96
{
 
97
  $dbh = Mysql->Connect($opt_host, $opt_db) || die $Mysql::db_errstr;
 
98
  foreach $table (@testtables) {
 
99
      $dbh->Query("drop table $table");
 
100
  }
 
101
}
 
102
print ($errors ? "Test failed\n" :"Test ok\n");
 
103
 
 
104
$end_time=new Benchmark;
 
105
print "Total time: " .
 
106
  timestr(timediff($end_time, $start_time),"noc") . "\n";
 
107
 
 
108
exit(0);
 
109
 
 
110
#
 
111
# Insert records in the ?? tables the Nasdaq way
 
112
 
113
 
 
114
sub test_1
 
115
{
 
116
    my ($dbh,$table,$tmpvar,$rows,$found,$i);
 
117
 
 
118
    $dbh = Mysql->Connect($opt_host, $opt_db) || die $Mysql::db_errstr;
 
119
    $tmpvar=1;
 
120
    $rows=$found=0;
 
121
    for ($i=0 ; $i < $opt_loop_count; $i++)
 
122
    {
 
123
        $tmpvar^= ((($tmpvar + 63) + $i)*3 % $numtables);
 
124
        # Nasdaq step 1:
 
125
        $sth=$dbh->Query("select id,last from $dtable where id='$tmpvar'")
 
126
            or die "Select directory row: $Mysql::db_errstr\n";
 
127
        # Nasdaq step 2:
 
128
        my ($did,$dlast) = $sth->FetchRow
 
129
            or die "Fetch directory row: $Mysql::db_errstr\n";
 
130
        $dlast++;
 
131
        $sth=$dbh->Query("INSERT into $testtables[$did]".
 
132
                         " VALUES($dlast,'This is entry $dlast',NULL)")
 
133
            || die "Got error on insert table $testtable[$did]:". 
 
134
                " $Mysql::db_errstr\n";
 
135
        # Nasdaq step 3 - where my application hangs
 
136
        $sth=$dbh->Query("update $dtable set last='$dlast' where id='$tmpvar'")
 
137
            or die "Updating directory for table $testtable[$did]:".
 
138
                " Mysql::db_errstr\n";
 
139
        $rows++;
 
140
    }
 
141
    $dbh=0;
 
142
    print "Test_1: Inserted $rows rows\n";
 
143
    exit(0);
 
144
}
 
145
 
 
146
#
 
147
# Nasdaq simple select
 
148
#
 
149
 
 
150
sub test_2
 
151
{
 
152
    my ($dbh,$id,$tmpvar,$rows,$found,$i);
 
153
 
 
154
    $dbh = Mysql->Connect($opt_host, $opt_db) || die $Mysql::db_errstr;
 
155
    $rows=$found=0;
 
156
    $tmpvar=1;
 
157
    for ($i=0 ; $i < $opt_loop_count ; $i++)
 
158
    {
 
159
        $tmpvar^= ((($tmpvar + 63) + $i)*3 % $numtables);
 
160
        $sth=$dbh->Query("select a.id,a.info from $testtables[$tmpvar] as a,".
 
161
                         "$dtable as d".
 
162
                         " where a.id=d.last and $i >= 0")
 
163
            || die "Got error select max: $Mysql::db_errstr\n";
 
164
        if ((@row = $sth->FetchRow()) && defined($row[0]))
 
165
        {
 
166
            $found++;
 
167
        }
 
168
    }
 
169
    $dbh=0;
 
170
    print "Test_2: Found $found rows\n";
 
171
    exit(0);
 
172
}
 
173
 
 
174
 
 
175
#
 
176
# Nasdaq not-so-simple select
 
177
#
 
178
 
 
179
sub test_3
 
180
{
 
181
    my ($dbh,$id,$tmpvar,$rows,$i);
 
182
    $dbh = Mysql->Connect($opt_host, $opt_db) || die $Mysql::db_errstr;
 
183
    $rows=0;
 
184
    $tmpvar ||= $numtables;
 
185
    for ($i=0 ; $i < $opt_loop_count ; $i++)
 
186
    {
 
187
        $tmpvar^= ((($tmpvar + 63) + $i)*3 % $numtables);
 
188
        $id1 = ($tmpvar+1) % $numtables;
 
189
        $id2 = ($id1+1) % $numtables;
 
190
        $id3 = ($id2+1) % $numtables;
 
191
        $sth = $dbh->Query("SELECT greatest(a.id, b.id, c.id), a.info".
 
192
                           " FROM $testtables[$id1] as a,".
 
193
                           " $testtables[$id2] as b,".
 
194
                           " $testtables[$id3] as c,".
 
195
                           " $dtable as d1, $dtable as d2, $dtable as d3".
 
196
                           " WHERE ".
 
197
                           " d1.last=a.id AND d2.last=b.id AND d3.last=c.id".
 
198
                           " AND d1.id='$id1' AND d2.id='$id2'".
 
199
                           " AND d3.id='$id3'")
 
200
            or die "Funny select: $Mysql::db_errstr\n";
 
201
        $rows+=$sth->numrows;
 
202
    }
 
203
    $dbh=0;
 
204
    print "Test_3: Found $rows rows\n";
 
205
    exit(0);
 
206
}
 
207
 
 
208
 
 
209
 
 
210