2
# Copyright (C) 2000-2001, 2003 MySQL AB
4
# This library is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU Library General Public
6
# License as published by the Free Software Foundation; version 2
9
# This library is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# Library General Public License for more details.
14
# You should have received a copy of the GNU Library General Public
15
# License along with this library; if not, write to the Free
16
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19
# This test is for testing the speed of connections and sending
22
# By changing the variable '$opt_loop_count' value you can make this test
23
# easier/harderto your computer to execute. You can also change this value
24
# by using option --loop_value='what_ever_you_like'.
25
##################### Standard benchmark inits ##############################
32
# changed to 20k to get past issue with connect in drizzle for now
33
$opt_loop_count=20000; # Change this to make test harder/easier
34
$str_length=65000; # This is the length of blob strings in PART:5
35
$max_test=20; # How many times to test if the server is busy
37
$pwd = cwd(); $pwd = "." if ($pwd eq '');
38
require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
40
# This is the length of blob strings in PART:5
41
$str_length=min($limits->{'max_text_size'},$limits->{'query_size'}-30,$str_length);
48
$opt_loop_count=min(1000, $opt_loop_count) if ($opt_tcpip);
49
$small_loop_count=$opt_loop_count/10; # For connect tests
51
print "Testing the speed of connecting to the server and sending of data\n";
52
print "Connect tests are done $small_loop_count times and other tests $opt_loop_count times\n\n";
54
################################# PART:1 ###################################
56
#### Start timeing and start connect test..
59
$start_time=new Benchmark;
61
print "Testing connection/disconnect\n";
63
$loop_time=new Benchmark;
66
for ($i=0 ; $i < $small_loop_count ; $i++)
68
print "$i " if (($opt_debug));
69
for ($j=0; $j < $max_test ; $j++)
71
if ($dbh = DBI->connect($server->{'data_source'}, $opt_user,
77
select(undef, undef, undef, 0.01*$j);
78
print "$errors " if (($opt_debug));
81
die "Got error '$DBI::errstr' after $i connects" if ($j == $max_test);
85
$end_time=new Benchmark;
86
print "Warning: $errors connections didn't work without a time delay\n" if ($errors);
87
print "Time to connect ($small_loop_count): " .
88
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
90
################################# PART:2 ###################################
91
#### Now we shall do first one connect, then simple select
92
#### (select 1..) and then close connection. This will be
93
#### done $small_loop_count times.
95
if ($limits->{'select_without_from'})
97
print "Test connect/simple select/disconnect\n";
98
$loop_time=new Benchmark;
100
for ($i=0; $i < $small_loop_count; $i++)
102
$dbh = DBI->connect($server->{'data_source'}, $opt_user, $opt_password) || die $DBI::errstr;
103
$sth = $dbh->do("select $i") or die $DBI::errstr;
106
$end_time=new Benchmark;
107
print "Time for connect+select_simple ($small_loop_count): " .
108
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
111
################################# PART:3 ###################################
113
#### Okay..Next thing we'll do is a simple select $opt_loop_count times.
116
$dbh = DBI->connect($server->{'data_source'}, $opt_user, $opt_password,
117
{ PrintError => 0}) || die $DBI::errstr;
119
if ($limits->{'select_without_from'})
121
print "Test simple select\n";
122
$loop_time=new Benchmark;
123
for ($i=0 ; $i < $opt_loop_count ; $i++)
125
$sth = $dbh->do("select $i") or die $DBI::errstr;
127
$end_time=new Benchmark;
128
print "Time for select_simple ($opt_loop_count): " .
129
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
132
###########################################################################
133
#### The same as the previous test, but always execute the same select
134
#### This is done to test the query cache for real simple selects.
136
if ($limits->{'select_without_from'})
138
print "Test simple select\n";
139
$loop_time=new Benchmark;
140
for ($i=0 ; $i < $opt_loop_count ; $i++)
142
$sth = $dbh->do("select 10000") or die $DBI::errstr;
144
$end_time=new Benchmark;
145
print "Time for select_simple_cache ($opt_loop_count): " .
146
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
149
##########################################################################
150
#### First, we'll create a simple table 'bench1'
151
#### Then we shall do $opt_loop_count selects from this table.
152
#### Table will contain very simple data.
154
$sth = $dbh->do("drop table bench1" . $server->{'drop_attr'});
155
do_many($dbh,$server->create("bench1",
159
["primary key (a)"]));
160
$sth = $dbh->do("insert into bench1 values(1,100,'AAA')") or die $DBI::errstr;
162
if ($opt_fast && defined($server->{vacuum}))
164
$server->vacuum(0,\$dbh);
169
# First test connect/select/disconnect
171
print "Testing connect/select 1 row from table/disconnect\n";
173
$loop_time=new Benchmark;
176
for ($i=0 ; $i < $small_loop_count ; $i++)
178
for ($j=0; $j < $max_test ; $j++)
180
last if ($dbh = DBI->connect($server->{'data_source'}, $opt_user, $opt_password));
183
die $DBI::errstr if ($j == $max_test);
185
$sth = $dbh->do("select a,i,s,$i from bench1") # Select * from table with 1 record
190
$end_time=new Benchmark;
191
print "Warning: $errors connections didn't work without a time delay\n" if ($errors);
192
print "Time to connect+select_1_row ($small_loop_count): " .
193
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
196
# The same test, but without connect/disconnect
198
print "Testing select 1 row from table\n";
200
$dbh = $server->connect();
201
$loop_time=new Benchmark;
203
for ($i=0 ; $i < $opt_loop_count ; $i++)
205
$sth = $dbh->do("select a,i,s,$i from bench1") # Select * from table with 1 record
209
$end_time=new Benchmark;
210
print "Time to select_1_row ($opt_loop_count): " .
211
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
214
# Same test (as with one row) but now with a cacheable query
217
$loop_time=new Benchmark;
219
for ($i=0 ; $i < $opt_loop_count ; $i++)
221
$sth = $dbh->do("select a,i,s from bench1") # Select * from table with 1 record
224
$end_time=new Benchmark;
225
print "Time to select_1_row_cache ($opt_loop_count): " .
226
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
229
# The same test, but with 2 rows (not cacheable).
232
print "Testing select 2 rows from table\n";
234
$sth = $dbh->do("insert into bench1 values(2,200,'BBB')")
237
$loop_time=new Benchmark;
239
for ($i=0 ; $i < $opt_loop_count ; $i++)
241
$sth = $dbh->do("select a,i,s,$i from bench1") # Select * from table with 2 record
245
$end_time=new Benchmark;
246
print "Time to select_2_rows ($opt_loop_count): " .
247
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
250
# Simple test to test speed of functions.
253
if ($limits->{'functions'})
255
print "Test select with aritmetic (+)\n";
256
$loop_time=new Benchmark;
258
for ($i=0; $i < $opt_loop_count; $i++)
260
$sth = $dbh->do("select a+a+a+a+a+a+a+a+a+$i from bench1") or die $DBI::errstr;
262
$end_time=new Benchmark;
263
print "Time for select_column+column ($opt_loop_count): " .
264
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
267
$sth = $dbh->do("drop table bench1" . $server->{'drop_attr'})
270
if ($opt_fast && defined($server->{vacuum}))
272
$server->vacuum(0,\$dbh);
275
################################# PART:5 ###################################
276
#### We'll create one table with a single blob field,but with a
277
#### huge record in it and then we'll do $opt_loop_count selects
280
goto skip_blob_test if (!$limits->{'working_blobs'});
282
print "Testing retrieval of big records ($str_length bytes)\n";
284
do_many($dbh,$server->create("bench1", ["b blob"], []));
285
$dbh->{LongReadLen}= $str_length; # Set retrieval buffer
287
my $string=(A) x ($str_length); # This will make a string $str_length long.
288
$sth = $dbh->prepare("insert into bench1 values(?)") or die $dbh->errstr;
289
$sth->execute($string) or die $sth->errstr;
291
if ($opt_fast && defined($server->{vacuum}))
293
$server->vacuum(0,\$dbh);
296
$loop_time=new Benchmark;
298
for ($i=0 ; $i < $small_loop_count ; $i++)
300
$sth = $dbh->prepare("select b,$i from bench1");
301
if (!$sth->execute || !(@row = $sth->fetchrow_array) ||
302
length($row[0]) != $str_length)
304
warn "$DBI::errstr - ".length($row[0])." - $str_length **\n";
309
$end_time=new Benchmark;
310
print "Time to select_big_str ($small_loop_count): " .
311
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
313
$sth = $dbh->do("drop table bench1" . $server->{'drop_attr'})
316
# Fix for Access 2000
317
die $dbh->errstr if (!$server->abort_if_fatal_error());
320
if ($opt_fast && defined($server->{vacuum}))
322
$server->vacuum(0,\$dbh);
327
################################ END ###################################
329
#### End of the test...Finally print time used to execute the
333
end_benchmark($start_time);