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 ##############################
31
$opt_loop_count=100000; # Change this to make test harder/easier
32
$str_length=65000; # This is the length of blob strings in PART:5
33
$max_test=20; # How many times to test if the server is busy
35
$pwd = cwd(); $pwd = "." if ($pwd eq '');
36
require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
38
# This is the length of blob strings in PART:5
39
$str_length=min($limits->{'max_text_size'},$limits->{'query_size'}-30,$str_length);
46
$opt_loop_count=min(1000, $opt_loop_count) if ($opt_tcpip);
47
$small_loop_count=$opt_loop_count/10; # For connect tests
49
print "Testing the speed of connecting to the server and sending of data\n";
50
print "Connect tests are done $small_loop_count times and other tests $opt_loop_count times\n\n";
52
################################# PART:1 ###################################
54
#### Start timeing and start connect test..
57
$start_time=new Benchmark;
59
print "Testing connection/disconnect\n";
61
$loop_time=new Benchmark;
64
for ($i=0 ; $i < $small_loop_count ; $i++)
66
print "$i " if (($opt_debug));
67
for ($j=0; $j < $max_test ; $j++)
69
if ($dbh = DBI->connect($server->{'data_source'}, $opt_user,
75
select(undef, undef, undef, 0.01*$j);
76
print "$errors " if (($opt_debug));
79
die "Got error '$DBI::errstr' after $i connects" if ($j == $max_test);
83
$end_time=new Benchmark;
84
print "Warning: $errors connections didn't work without a time delay\n" if ($errors);
85
print "Time to connect ($small_loop_count): " .
86
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
88
################################# PART:2 ###################################
89
#### Now we shall do first one connect, then simple select
90
#### (select 1..) and then close connection. This will be
91
#### done $small_loop_count times.
93
if ($limits->{'select_without_from'})
95
print "Test connect/simple select/disconnect\n";
96
$loop_time=new Benchmark;
98
for ($i=0; $i < $small_loop_count; $i++)
100
$dbh = DBI->connect($server->{'data_source'}, $opt_user, $opt_password) || die $DBI::errstr;
101
$sth = $dbh->do("select $i") or die $DBI::errstr;
104
$end_time=new Benchmark;
105
print "Time for connect+select_simple ($small_loop_count): " .
106
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
109
################################# PART:3 ###################################
111
#### Okay..Next thing we'll do is a simple select $opt_loop_count times.
114
$dbh = DBI->connect($server->{'data_source'}, $opt_user, $opt_password,
115
{ PrintError => 0}) || die $DBI::errstr;
117
if ($limits->{'select_without_from'})
119
print "Test simple select\n";
120
$loop_time=new Benchmark;
121
for ($i=0 ; $i < $opt_loop_count ; $i++)
123
$sth = $dbh->do("select $i") or die $DBI::errstr;
125
$end_time=new Benchmark;
126
print "Time for select_simple ($opt_loop_count): " .
127
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
130
###########################################################################
131
#### The same as the previous test, but always execute the same select
132
#### This is done to test the query cache for real simple selects.
134
if ($limits->{'select_without_from'})
136
print "Test simple select\n";
137
$loop_time=new Benchmark;
138
for ($i=0 ; $i < $opt_loop_count ; $i++)
140
$sth = $dbh->do("select 10000") or die $DBI::errstr;
142
$end_time=new Benchmark;
143
print "Time for select_simple_cache ($opt_loop_count): " .
144
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
147
##########################################################################
148
#### First, we'll create a simple table 'bench1'
149
#### Then we shall do $opt_loop_count selects from this table.
150
#### Table will contain very simple data.
152
$sth = $dbh->do("drop table bench1" . $server->{'drop_attr'});
153
do_many($dbh,$server->create("bench1",
157
["primary key (a)"]));
158
$sth = $dbh->do("insert into bench1 values(1,100,'AAA')") or die $DBI::errstr;
160
if ($opt_fast && defined($server->{vacuum}))
162
$server->vacuum(0,\$dbh);
167
# First test connect/select/disconnect
169
print "Testing connect/select 1 row from table/disconnect\n";
171
$loop_time=new Benchmark;
174
for ($i=0 ; $i < $small_loop_count ; $i++)
176
for ($j=0; $j < $max_test ; $j++)
178
last if ($dbh = DBI->connect($server->{'data_source'}, $opt_user, $opt_password));
181
die $DBI::errstr if ($j == $max_test);
183
$sth = $dbh->do("select a,i,s,$i from bench1") # Select * from table with 1 record
188
$end_time=new Benchmark;
189
print "Warning: $errors connections didn't work without a time delay\n" if ($errors);
190
print "Time to connect+select_1_row ($small_loop_count): " .
191
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
194
# The same test, but without connect/disconnect
196
print "Testing select 1 row from table\n";
198
$dbh = $server->connect();
199
$loop_time=new Benchmark;
201
for ($i=0 ; $i < $opt_loop_count ; $i++)
203
$sth = $dbh->do("select a,i,s,$i from bench1") # Select * from table with 1 record
207
$end_time=new Benchmark;
208
print "Time to select_1_row ($opt_loop_count): " .
209
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
212
# Same test (as with one row) but now with a cacheable query
215
$loop_time=new Benchmark;
217
for ($i=0 ; $i < $opt_loop_count ; $i++)
219
$sth = $dbh->do("select a,i,s from bench1") # Select * from table with 1 record
222
$end_time=new Benchmark;
223
print "Time to select_1_row_cache ($opt_loop_count): " .
224
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
227
# The same test, but with 2 rows (not cacheable).
230
print "Testing select 2 rows from table\n";
232
$sth = $dbh->do("insert into bench1 values(2,200,'BBB')")
235
$loop_time=new Benchmark;
237
for ($i=0 ; $i < $opt_loop_count ; $i++)
239
$sth = $dbh->do("select a,i,s,$i from bench1") # Select * from table with 2 record
243
$end_time=new Benchmark;
244
print "Time to select_2_rows ($opt_loop_count): " .
245
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
248
# Simple test to test speed of functions.
251
if ($limits->{'functions'})
253
print "Test select with aritmetic (+)\n";
254
$loop_time=new Benchmark;
256
for ($i=0; $i < $opt_loop_count; $i++)
258
$sth = $dbh->do("select a+a+a+a+a+a+a+a+a+$i from bench1") or die $DBI::errstr;
260
$end_time=new Benchmark;
261
print "Time for select_column+column ($opt_loop_count): " .
262
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
265
$sth = $dbh->do("drop table bench1" . $server->{'drop_attr'})
268
if ($opt_fast && defined($server->{vacuum}))
270
$server->vacuum(0,\$dbh);
273
################################# PART:5 ###################################
274
#### We'll create one table with a single blob field,but with a
275
#### huge record in it and then we'll do $opt_loop_count selects
278
goto skip_blob_test if (!$limits->{'working_blobs'});
280
print "Testing retrieval of big records ($str_length bytes)\n";
282
do_many($dbh,$server->create("bench1", ["b blob"], []));
283
$dbh->{LongReadLen}= $str_length; # Set retrieval buffer
285
my $string=(A) x ($str_length); # This will make a string $str_length long.
286
$sth = $dbh->prepare("insert into bench1 values(?)") or die $dbh->errstr;
287
$sth->execute($string) or die $sth->errstr;
289
if ($opt_fast && defined($server->{vacuum}))
291
$server->vacuum(0,\$dbh);
294
$loop_time=new Benchmark;
296
for ($i=0 ; $i < $small_loop_count ; $i++)
298
$sth = $dbh->prepare("select b,$i from bench1");
299
if (!$sth->execute || !(@row = $sth->fetchrow_array) ||
300
length($row[0]) != $str_length)
302
warn "$DBI::errstr - ".length($row[0])." - $str_length **\n";
307
$end_time=new Benchmark;
308
print "Time to select_big_str ($small_loop_count): " .
309
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
311
$sth = $dbh->do("drop table bench1" . $server->{'drop_attr'})
314
# Fix for Access 2000
315
die $dbh->errstr if (!$server->abort_if_fatal_error());
318
if ($opt_fast && defined($server->{vacuum}))
320
$server->vacuum(0,\$dbh);
325
################################ END ###################################
327
#### End of the test...Finally print time used to execute the
331
end_benchmark($start_time);