home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 January / Chip_2001-01_cd1.bin / tema / mysql / mysql-3.23.28g-win.exe / DATA1.CAB / Benchmark_Files / bench / test-connect < prev    next >
Text File  |  2000-11-22  |  8KB  |  288 lines

  1. #!/my/gnu/bin/perl5
  2. # Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  3. #
  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; either
  7. # version 2 of the License, or (at your option) any later version.
  8. #
  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.
  13. #
  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,
  17. # MA 02111-1307, USA
  18. #
  19. # This test is for testing the speed of connections and sending
  20. # data to the client.
  21. #
  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 ##############################
  26.  
  27. use DBI;
  28. use Benchmark;
  29.  
  30. $opt_loop_count=10000;    # Change this to make test harder/easier
  31. $str_length=65000;    # This is the length of blob strings in PART:5
  32. $max_test=20;        # How many times to test if the server is busy
  33.  
  34. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  35. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  36.  
  37. # This is the length of blob strings in PART:5
  38. $str_length=min($limits->{'max_text_size'},$limits->{'query_size'}-30,$str_length);
  39.  
  40. if ($opt_small_test)
  41. {
  42.   $opt_loop_count/=100;
  43. }
  44.  
  45. print "Testing the speed of connecting to the server and sending of data\n";
  46. print "All tests are done $opt_loop_count times\n\n";
  47.  
  48. ################################# PART:1 ###################################
  49. ####
  50. ####  Start timeing and start connect test..
  51. ####
  52.  
  53. $start_time=new Benchmark;
  54.  
  55. print "Testing connection/disconnect\n";
  56.  
  57. $loop_time=new Benchmark;
  58. $errors=0;
  59.  
  60. for ($i=0 ; $i < $opt_loop_count ; $i++)
  61. {
  62.   print "$i " if (($opt_debug));
  63.   for ($j=0; $j < $max_test ; $j++)
  64.   {
  65.     if ($dbh = DBI->connect($server->{'data_source'}, $opt_user,
  66.                 $opt_password))
  67.     {
  68.       $dbh->disconnect;
  69.       last;
  70.     }
  71.     select(undef, undef, undef, 0.001);
  72.     print "$errors " if (($opt_debug));
  73.     $errors++;
  74.   }
  75.   die $DBI::errstr if ($j == $max_test);
  76.   $dbh->disconnect;
  77.   undef($dbh);
  78. }
  79. $end_time=new Benchmark;
  80. print "Warning: $errors connections didn't work without a time delay\n" if ($errors);
  81. print "Time to connect ($opt_loop_count): " .
  82.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  83.  
  84. ################################# PART:2 ###################################
  85. #### Now we shall do first one connect, then simple select
  86. #### (select 1..) and then close connection. This will be
  87. #### done $opt_loop_count times.
  88.  
  89. if ($limits->{'select_without_from'})
  90. {
  91.   print "Test connect/simple select/disconnect\n";
  92.   $loop_time=new Benchmark;
  93.  
  94.   for ($i=0; $i<$opt_loop_count; $i++)
  95.   {
  96.     $dbh = DBI->connect($server->{'data_source'}, $opt_user, $opt_password) || die $DBI::errstr;
  97.     $sth = $dbh->do("select 1") or die $DBI::errstr;
  98.     $dbh->disconnect;
  99.   }
  100.   $end_time=new Benchmark;
  101.   print "Time for connect+select_simple ($opt_loop_count): " .
  102.     timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  103. }
  104.  
  105. ################################# PART:3 ###################################
  106. ####
  107. #### Okay..Next thing we'll do is a simple select $opt_loop_count times.
  108. ####
  109.  
  110. $dbh = DBI->connect($server->{'data_source'}, $opt_user, $opt_password,
  111.             { PrintError => 0}) || die $DBI::errstr;
  112.  
  113. if ($limits->{'select_without_from'})
  114. {
  115.   print "Test simple select\n";
  116.   $loop_time=new Benchmark;
  117.   for ($i=0 ; $i<$opt_loop_count ; $i++)
  118.   {
  119.     $sth = $dbh->do("select 1") or die $DBI::errstr;
  120.   }
  121.   $end_time=new Benchmark;
  122.   print "Time for select_simple ($opt_loop_count): " .
  123.     timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  124. }
  125.  
  126. ################################# PART:4 ###################################
  127. #### First, we'll create a simple table 'bench1'
  128. #### Then we shall do $opt_loop_count selects from this table.
  129. #### Table will contain very simple data.
  130.  
  131. $sth = $dbh->do("drop table bench1");
  132. do_many($dbh,$server->create("bench1",
  133.                  ["a int NOT NULL",
  134.                   "i int",
  135.                   "s char(10)"],
  136.                  ["primary key (a)"]));
  137. $sth = $dbh->do("insert into bench1 values(1,100,'AAA')") or die $DBI::errstr;
  138.  
  139. if ($opt_fast && defined($server->{vacuum}))
  140. {
  141.   $server->vacuum(0,\$dbh);
  142. }
  143. $dbh->disconnect;
  144.  
  145. #
  146. # First test connect/select/disconnect
  147. #
  148. print "Testing connect/select 1 row from table/disconnect\n";
  149.  
  150. $loop_time=new Benchmark;
  151. $errors=0;
  152.  
  153. for ($i=0 ; $i<$opt_loop_count ; $i++)
  154. {
  155.   for ($j=0; $j < $max_test ; $j++)
  156.   {
  157.     last if ($dbh = DBI->connect($server->{'data_source'}, $opt_user, $opt_password));
  158.     $errors++;
  159.   }
  160.   die $DBI::errstr if ($j == $max_test);
  161.  
  162.   $sth = $dbh->do("select * from bench1") #Select * from table with 1 record
  163.     or die $DBI::errstr;
  164.   $dbh->disconnect;
  165. }
  166.  
  167. $end_time=new Benchmark;
  168. print "Warning: $errors connections didn't work without a time delay\n" if ($errors);
  169. print "Time to connect+select_1_row ($opt_loop_count): " .
  170.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  171.  
  172. #
  173. # The same test, but without connect/disconnect
  174. #
  175. print "Testing select 1 row from table\n";
  176.  
  177. $dbh = $server->connect();
  178. $loop_time=new Benchmark;
  179.  
  180. for ($i=0 ; $i<$opt_loop_count ; $i++)
  181. {
  182.   $sth = $dbh->do("select * from bench1") # Select * from table with 1 record
  183.     or die $DBI::errstr;
  184. }
  185.  
  186. $end_time=new Benchmark;
  187. print "Time to select_1_row ($opt_loop_count): " .
  188.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  189.  
  190. #
  191. # The same test, but with 2 rows.
  192. #
  193. print "Testing select 2 rows from table\n";
  194.  
  195. $sth = $dbh->do("insert into bench1 values(2,200,'BBB')")
  196.   or die $DBI::errstr;
  197.  
  198. $loop_time=new Benchmark;
  199.  
  200. for ($i=0 ; $i<$opt_loop_count ; $i++)
  201. {
  202.   $sth = $dbh->do("select * from bench1") # Select * from table with 2 record
  203.     or die $DBI::errstr;
  204. }
  205.  
  206. $end_time=new Benchmark;
  207. print "Time to select_2_rows ($opt_loop_count): " .
  208.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  209.  
  210. if ($limits->{'functions'})
  211. {
  212.   print "Test select with aritmetic (+)\n";
  213.   $loop_time=new Benchmark;
  214.  
  215.   for ($i=0; $i<$opt_loop_count; $i++)
  216.   {
  217.     $sth = $dbh->do("select a+a+a+a+a+a+a+a+a+a from bench1") or die $DBI::errstr;
  218.   }
  219.   $end_time=new Benchmark;
  220.   print "Time for select_column+column ($opt_loop_count): " .
  221.     timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  222. }
  223.  
  224. $sth = $dbh->do("drop table bench1")
  225.   or die $DBI::errstr;
  226.  
  227. if ($opt_fast && defined($server->{vacuum}))
  228. {
  229.   $server->vacuum(0,\$dbh);
  230. }
  231.  
  232. ################################# PART:5 ###################################
  233. #### We'll create one table with a single blob field,but with a
  234. #### huge record in it and then we'll do $opt_loop_count selects
  235. #### from it.
  236.  
  237. print "Testing retrieval of big records ($str_length bytes)\n";
  238.  
  239. do_many($dbh,$server->create("bench1", ["b blob"], []));
  240. $dbh->{LongReadLen}= $str_length; # Set retrieval buffer
  241.  
  242. my $string=(A) x ($str_length); # This will make a string $str_length long.
  243. $sth = $dbh->prepare("insert into bench1 values(?)") or die $dbh->errstr;
  244. $sth->execute($string) or die $sth->errstr;
  245. undef($string);
  246. if ($opt_fast && defined($server->{vacuum}))
  247. {
  248.   $server->vacuum(0,\$dbh);
  249. }
  250.  
  251. $loop_time=new Benchmark;
  252.  
  253. for ($i=0 ; $i < $opt_loop_count ; $i++)
  254. {
  255.   $sth = $dbh->prepare("select * from bench1");
  256.   if (!$sth->execute || !(@row = $sth->fetchrow_array) ||
  257.       length($row[0]) != $str_length)
  258.   {
  259.     warn "$DBI::errstr - ".length($row[0])." - $str_length **\n";
  260.   }
  261.   $sth->finish;
  262. }
  263.  
  264. $end_time=new Benchmark;
  265. print "Time to select_big ($opt_loop_count): " .
  266.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  267.  
  268. $sth = $dbh->do("drop table bench1")
  269.   or do
  270. {
  271.     # Fix for Access 2000
  272.     die $dbh->errstr if (!$dbh->abort_if_fatal_error());
  273. };
  274.  
  275. if ($opt_fast && defined($server->{vacuum}))
  276. {
  277.   $server->vacuum(0,\$dbh);
  278. }
  279.  
  280.  
  281. ################################ END ###################################
  282. ####
  283. #### End of the test...Finally print time used to execute the
  284. #### whole test.
  285.  
  286. $dbh->disconnect;
  287. end_benchmark($start_time);
  288.