DBD-PrimeBase
view release on metacpan or search on metacpan
benchmarks/test-connect view on Meta::CPAN
#!/usr/bin/perl
# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
#
# 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; either
# version 2 of the License, or (at your option) any later version.
#
# 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., 59 Temple Place - Suite 330, Boston,
# MA 02111-1307, 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 DBI;
use Benchmark;
$opt_loop_count=1000; # 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
chomp($pwd = `pwd`); $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);
print "Testing the speed of connecting to the server and sending of data\n";
print "All tests are done $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 < $opt_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 ($opt_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 $opt_loop_count times.
if ($limits->{'select_without_from'})
{
print "Test connect/simple select/disconnect\n";
( run in 2.858 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )