1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
#!/usr/bin/perl
# Copyright (c) 2000, 2001, 2003, 2006 MySQL AB, 2009 Sun Microsystems, Inc.
# Use is subject to license terms.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; version 2
# of the License.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA
#
# This test is for testing the speed of connections and sending
# data to the client.
#
# By changing the variable '$opt_loop_count' value you can make this test
# easier/harderto your computer to execute. You can also change this value
# by using option --loop_value='what_ever_you_like'.
##################### Standard benchmark inits ##############################
use Cwd;
use DBI;
use Benchmark;
$opt_loop_count=500000; # Change this to make test harder/easier
$str_length=65000; # This is the length of blob strings in PART:5
$max_test=20; # How many times to test if the server is busy
$pwd = cwd(); $pwd = "." if ($pwd eq '');
require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
# This is the length of blob strings in PART:5
$str_length=min($limits->{'max_text_size'},$limits->{'query_size'}-30,$str_length);
if ($opt_small_test)
{
$opt_loop_count/=100;
}
$opt_loop_count=min(1000, $opt_loop_count) if ($opt_tcpip);
$small_loop_count=$opt_loop_count/10; # For connect tests
print "Testing the speed of connecting to the server and sending of data\n";
print "Connect tests are done $small_loop_count times and other tests $opt_loop_count times\n\n";
################################# PART:1 ###################################
####
#### Start timeing and start connect test..
####
$start_time=new Benchmark;
print "Testing connection/disconnect\n";
$loop_time=new Benchmark;
$errors=0;
for ($i=0 ; $i < $small_loop_count ; $i++)
{
print "$i " if (($opt_debug));
for ($j=0; $j < $max_test ; $j++)
{
if ($dbh = DBI->connect($server->{'data_source'}, $opt_user,
$opt_password))
{
$dbh->disconnect;
last;
}
select(undef, undef, undef, 0.01*$j);
print "$errors " if (($opt_debug));
$errors++;
}
die "Got error '$DBI::errstr' after $i connects" if ($j == $max_test);
$dbh->disconnect;
undef($dbh);
}
$end_time=new Benchmark;
print "Warning: $errors connections didn't work without a time delay\n" if ($errors);
print "Time to connect ($small_loop_count): " .
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
################################# PART:2 ###################################
#### Now we shall do first one connect, then simple select
#### (select 1..) and then close connection. This will be
#### done $small_loop_count times.
if ($limits->{'select_without_from'})
{
print "Test connect/simple select/disconnect\n";
$loop_time=new Benchmark;
for ($i=0; $i < $small_loop_count; $i++)
{
$dbh = DBI->connect($server->{'data_source'}, $opt_user, $opt_password) || die $DBI::errstr;
$sth = $dbh->do("select $i") or die $DBI::errstr;
$dbh->disconnect;
}
$end_time=new Benchmark;
print "Time for connect+select_simple ($small_loop_count): " .
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
}
################################# PART:3 ###################################
####
#### Okay..Next thing we'll do is a simple select $opt_loop_count times.
####
$dbh = DBI->connect($server->{'data_source'}, $opt_user, $opt_password,
{ PrintError => 0}) || die $DBI::errstr;
if ($limits->{'select_without_from'})
{
print "Test simple select\n";
$loop_time=new Benchmark;
for ($i=0 ; $i < $opt_loop_count ; $i++)
{
$sth = $dbh->do("select $i") or die $DBI::errstr;
}
$end_time=new Benchmark;
print "Time for select_simple ($opt_loop_count): " .
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
}
###########################################################################
#### The same as the previous test, but always execute the same select
#### This is done to test the query cache for real simple selects.
if ($limits->{'select_without_from'})
{
print "Test simple select\n";
$loop_time=new Benchmark;
for ($i=0 ; $i < $opt_loop_count ; $i++)
{
$sth = $dbh->do("select 10000") or die $DBI::errstr;
}
$end_time=new Benchmark;
print "Time for select_simple_cache ($opt_loop_count): " .
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
}
##########################################################################
#### First, we'll create a simple table 'bench1'
#### Then we shall do $opt_loop_count selects from this table.
#### Table will contain very simple data.
$sth = $dbh->do("drop table bench1" . $server->{'drop_attr'});
do_many($dbh,$server->create("bench1",
["a int NOT NULL",
"i int",
"s char(10)"],
["primary key (a)"]));
$sth = $dbh->do("insert into bench1 values(1,100,'AAA')") or die $DBI::errstr;
if ($opt_fast && defined($server->{vacuum}))
{
$server->vacuum(0,\$dbh);
}
if (!$main::opt_temporary_tables)
{
$dbh->disconnect;
}
#
# First test connect/select/disconnect
#
if (!$main::opt_temporary_tables)
{
print "Testing connect/select 1 row from table/disconnect\n";
$loop_time=new Benchmark;
$errors=0;
for ($i=0 ; $i < $small_loop_count ; $i++)
{
for ($j=0; $j < $max_test ; $j++)
{
last if ($dbh = DBI->connect($server->{'data_source'}, $opt_user, $opt_password));
$errors++;
}
die $DBI::errstr if ($j == $max_test);
$sth = $dbh->do("select a,i,s,$i from bench1") # Select * from table with 1 record
or die $DBI::errstr;
$dbh->disconnect;
}
$end_time=new Benchmark;
print "Warning: $errors connections didn't work without a time delay\n" if ($errors);
print "Time to connect+select_1_row ($small_loop_count): " .
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
$dbh = $server->connect();
}
#
# The same test, but without connect/disconnect
#
print "Testing select 1 row from table\n";
$loop_time=new Benchmark;
for ($i=0 ; $i < $opt_loop_count ; $i++)
{
$sth = $dbh->do("select a,i,s,$i from bench1") # Select * from table with 1 record
or die $DBI::errstr;
}
$end_time=new Benchmark;
print "Time to select_1_row ($opt_loop_count): " .
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
#
# Same test (as with one row) but now with a cacheable query
#
$loop_time=new Benchmark;
for ($i=0 ; $i < $opt_loop_count ; $i++)
{
$sth = $dbh->do("select a,i,s from bench1") # Select * from table with 1 record
or die $DBI::errstr;
}
$end_time=new Benchmark;
print "Time to select_1_row_cache ($opt_loop_count): " .
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
#
# The same test, but with 2 rows (not cacheable).
#
print "Testing select 2 rows from table\n";
$sth = $dbh->do("insert into bench1 values(2,200,'BBB')")
or die $DBI::errstr;
$loop_time=new Benchmark;
for ($i=0 ; $i < $opt_loop_count ; $i++)
{
$sth = $dbh->do("select a,i,s,$i from bench1") # Select * from table with 2 record
or die $DBI::errstr;
}
$end_time=new Benchmark;
print "Time to select_2_rows ($opt_loop_count): " .
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
#
# Simple test to test speed of functions.
#
if ($limits->{'functions'})
{
print "Test select with aritmetic (+)\n";
$loop_time=new Benchmark;
for ($i=0; $i < $opt_loop_count; $i++)
{
$sth = $dbh->do("select a+a+a+a+a+a+a+a+a+$i from bench1") or die $DBI::errstr;
}
$end_time=new Benchmark;
print "Time for select_column+column ($opt_loop_count): " .
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
}
$sth = $dbh->do("drop table bench1" . $server->{'drop_attr'})
or die $DBI::errstr;
if ($opt_fast && defined($server->{vacuum}))
{
$server->vacuum(0,\$dbh);
}
################################# PART:5 ###################################
#### We'll create one table with a single blob field,but with a
#### huge record in it and then we'll do $opt_loop_count selects
#### from it.
goto skip_blob_test if (!$limits->{'working_blobs'});
print "Testing retrieval of big records ($str_length bytes)\n";
do_many($dbh,$server->create("bench1", ["b blob"], []));
$dbh->{LongReadLen}= $str_length; # Set retrieval buffer
my $string=(A) x ($str_length); # This will make a string $str_length long.
$sth = $dbh->prepare("insert into bench1 values(?)") or die $dbh->errstr;
$sth->execute($string) or die $sth->errstr;
undef($string);
if ($opt_fast && defined($server->{vacuum}))
{
$server->vacuum(0,\$dbh);
}
$loop_time=new Benchmark;
for ($i=0 ; $i < $small_loop_count ; $i++)
{
$sth = $dbh->prepare("select b,$i from bench1");
if (!$sth->execute || !(@row = $sth->fetchrow_array) ||
length($row[0]) != $str_length)
{
warn "$DBI::errstr - ".length($row[0])." - $str_length **\n";
}
$sth->finish;
}
$end_time=new Benchmark;
print "Time to select_big_str ($small_loop_count): " .
timestr(timediff($end_time, $loop_time),"all") . "\n\n";
$sth = $dbh->do("drop table bench1" . $server->{'drop_attr'})
or do
{
# Fix for Access 2000
die $dbh->errstr if (!$server->abort_if_fatal_error());
};
if ($opt_fast && defined($server->{vacuum}))
{
$server->vacuum(0,\$dbh);
}
skip_blob_test:
################################ END ###################################
####
#### End of the test...Finally print time used to execute the
#### whole test.
$dbh->disconnect;
end_benchmark($start_time);
|