~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/sql-bench/bench-init.pl

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
# Copyright (C) 2000-2003, 2005 MySQL 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; version 2
 
7
# of the License.
 
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
##########################################################
 
20
# this is the base file every test is using ....
 
21
# this is made for not changing every file if we want to
 
22
# add an option or just want to change something in
 
23
# code what is the same in every file ...
 
24
##########################################################
 
25
 
 
26
#
 
27
# The exported values are:
 
28
 
 
29
# $opt_...      Various options
 
30
# $date         Current date in ISO format
 
31
# $server       Object for current server
 
32
# $limits       Hash reference to limits for benchmark
 
33
 
 
34
$benchmark_version="2.15";
 
35
use Getopt::Long;
 
36
use POSIX;
 
37
 
 
38
require "$pwd/server-cfg" || die "Can't read Configuration file: $!\n";
 
39
 
 
40
$|=1;                           # Output data immediately
 
41
 
 
42
our $opt_skip_test=$opt_skip_create=$opt_skip_delete=$opt_verbose=$opt_fast_insert=$opt_lock_tables=$opt_debug=$opt_skip_delete=$opt_fast=$opt_force=$opt_log=$opt_use_old_results=$opt_help=$opt_odbc=$opt_small_test=$opt_small_tables=$opt_samll_key_tables=$opt_stage=$opt_old_headers=$opt_die_on_errors=$opt_tcpip=$opt_random=$opt_only_missing_tests=0;
 
43
our $opt_cmp=$opt_user=$opt_password=$opt_connect_options="";
 
44
our $opt_create_options=undef;
 
45
our $opt_bzr_repo='';
 
46
our $opt_database="test";
 
47
our $opt_dir="output";
 
48
our $opt_host="localhost";
 
49
our $opt_hw="";
 
50
our $opt_server="mysql"; 
 
51
our $opt_machine=""; 
 
52
our $opt_optimization="None";
 
53
our $opt_suffix="";
 
54
our $opt_threads=5;
 
55
our $repo_version='';
 
56
 
 
57
if (!defined($opt_time_limit))
 
58
{
 
59
  $opt_time_limit=10*60;        # Don't wait more than 10 min for some tests
 
60
}
 
61
 
 
62
$log_prog_args=join(" ", skip_arguments(\@ARGV,"comments","cmp","server",
 
63
                                        "user", "host", "database", "password",
 
64
                                        "use-old-results","skip-test",
 
65
                                        "optimization","hw",
 
66
                                        "machine", "dir", "suffix", "log"));
 
67
GetOptions(
 
68
    "skip-test=s",
 
69
    "comments=s",
 
70
    "cmp=s",
 
71
    "server=s",
 
72
    "user=s",
 
73
    "host=s",
 
74
    "database=s",
 
75
    "password=s",
 
76
    "loop-count=i",
 
77
    "row-count=i",
 
78
    "skip-create",
 
79
    "skip-delete",
 
80
    "verbose",
 
81
    "fast-insert",
 
82
    "lock-tables",
 
83
    "debug",
 
84
    "fast",
 
85
    "force",
 
86
    "field-count=i",
 
87
    "regions=i",
 
88
    "groups=i",
 
89
    "time-limit=i",
 
90
    "log",
 
91
    "use-old-results",
 
92
    "machine=s",
 
93
    "dir=s",
 
94
    "suffix=s",
 
95
    "help",
 
96
    "odbc",
 
97
    "small-test",
 
98
    "small-tables",
 
99
    "small-key-tables",
 
100
    "stage=i",
 
101
    "threads=i",
 
102
    "random",
 
103
    "old-headers",
 
104
    "die-on-errors",
 
105
    "create-options=s",
 
106
    "hires",
 
107
    "tcpip",
 
108
    "silent",
 
109
    "optimization=s",
 
110
    "hw=s",
 
111
    "socket=s",
 
112
    "connect-options=s",
 
113
    "only-missing-tests",
 
114
    "bzr-repo=s") || usage();
 
115
 
 
116
usage() if ($opt_help);
 
117
$server=get_server($opt_server,$opt_host,$opt_database,$opt_odbc,
 
118
                   machine_part(), $opt_socket, $opt_connect_options);
 
119
$limits=merge_limits($server,$opt_cmp);
 
120
$date=date();
 
121
@estimated=(0.0,0.0,0.0);               # For estimated time support
 
122
 
 
123
if ($opt_hires)
 
124
{
 
125
  eval "use Time::HiRes;";
 
126
}
 
127
 
 
128
{
 
129
  my $tmp= $opt_server;
 
130
  $tmp =~ s/_odbc$//;
 
131
  if (length($opt_cmp) && index($opt_cmp,$tmp) < 0)
 
132
  {
 
133
    $opt_cmp.=",$tmp";
 
134
  }
 
135
}
 
136
$opt_cmp=lc(join(",",sort(split(',',$opt_cmp))));
 
137
 
 
138
#
 
139
# set opt_lock_tables if one uses --fast and drivers supports it
 
140
#
 
141
 
 
142
if (($opt_lock_tables || $opt_fast) && $server->{'limits'}->{'lock_tables'})
 
143
{
 
144
  $opt_lock_tables=1;
 
145
}
 
146
else
 
147
{
 
148
  $opt_lock_tables=0;
 
149
}
 
150
if ($opt_fast)
 
151
{
 
152
  $opt_fast_insert=1;
 
153
  $opt_suffix="_fast" if (!length($opt_suffix));
 
154
}
 
155
 
 
156
if ($opt_odbc)
 
157
{
 
158
   $opt_suffix="_odbc" if (!length($opt_suffix));
 
159
}
 
160
 
 
161
if (!$opt_silent)
 
162
{
 
163
  print "Testing server '" . $server->version() . "' at $date\n\n";
 
164
}
 
165
 
 
166
if ($opt_debug)
 
167
{
 
168
  print "\nCurrent limits: \n";
 
169
  foreach $key (sort keys %$limits)
 
170
  {
 
171
    print $key . " " x (30-length($key)) . $limits->{$key} . "\n";
 
172
  }
 
173
  print "\n";
 
174
}
 
175
if ($opt_bzr_repo) {
 
176
  if (-d $opt_bzr_repo) {
 
177
    $repo_version= `bzr revno $opt_bzr_repo`;
 
178
    # get rid of newline
 
179
    chomp($repo_version);
 
180
    if (index($repo_version,'ERROR') > -1) {
 
181
      usage("The bzr repository $opt_bzr_repo has a problem: $repo_version");
 
182
    }
 
183
  }
 
184
}
 
185
 
 
186
#
 
187
# Some help functions
 
188
#
 
189
 
 
190
sub skip_arguments
 
191
{
 
192
  my($argv,@skip_args)=@_;
 
193
  my($skip,$arg,$name,@res);
 
194
 
 
195
  foreach $arg (@$argv)
 
196
  {
 
197
    if ($arg =~ /^\-+([^=]*)/)
 
198
    {
 
199
      $name=$1;
 
200
      foreach $skip (@skip_args)
 
201
      {
 
202
        if (index($skip,$name) == 0)
 
203
        {
 
204
          $name="";             # Don't use this parameters
 
205
          last;
 
206
        }
 
207
      }
 
208
      push (@res,$arg) if (length($name));
 
209
    }
 
210
  }
 
211
  return @res;
 
212
}
 
213
 
 
214
 
 
215
sub merge_limits
 
216
{
 
217
  my ($server,$cmp)= @_;
 
218
  my ($name,$tmp_server,$limits,$res_limits,$limit,$tmp_limits);
 
219
 
 
220
  $res_limits=$server->{'limits'};
 
221
  if ($cmp)
 
222
  {
 
223
    foreach $name (split(",",$cmp))
 
224
    {
 
225
      $tmp_server= (get_server($name,$opt_host, $opt_database,
 
226
                               $opt_odbc,machine_part())
 
227
                    || die "Unknown SQL server: $name\n");
 
228
      $limits=$tmp_server->{'limits'};
 
229
      %new_limits=();
 
230
      foreach $limit (keys(%$limits))
 
231
      {
 
232
        if (defined($res_limits->{$limit}) && defined($limits->{$limit}))
 
233
        {
 
234
          $new_limits{$limit}=min($res_limits->{$limit},$limits->{$limit});
 
235
        }
 
236
      }
 
237
      %tmp_limits=%new_limits;
 
238
      $res_limits=\%tmp_limits;
 
239
    }
 
240
  }
 
241
  return $res_limits;
 
242
}
 
243
 
 
244
sub date
 
245
{
 
246
  my ($sec, $min, $hour, $mday, $mon, $year) = localtime(time());
 
247
  sprintf("%04d-%02d-%02d %2d:%02d:%02d",
 
248
          1900+$year,$mon+1,$mday,$hour,$min,$sec);
 
249
}
 
250
 
 
251
sub min
 
252
{
 
253
  my($min)=$_[0];
 
254
  my($i);
 
255
  for ($i=1 ; $i <= $#_; $i++)
 
256
  {
 
257
    $min=$_[$i] if ($min > $_[$i]);
 
258
  }
 
259
  return $min;
 
260
}
 
261
 
 
262
sub max
 
263
{
 
264
  my($max)=$_[0];
 
265
  my($i);
 
266
  for ($i=1 ; $i <= $#_; $i++)
 
267
  {
 
268
    $max=$_[$i] if ($max < $_[$i]);
 
269
  }
 
270
  return $max;
 
271
}
 
272
 
 
273
 
 
274
#
 
275
# Execute many statements in a row
 
276
#
 
277
 
 
278
sub do_many
 
279
{
 
280
  my ($dbh,@statements)=@_;
 
281
  my ($statement,$sth);
 
282
 
 
283
  foreach $statement (@statements)
 
284
  {
 
285
    if (!($sth=$dbh->do($statement)))
 
286
    {
 
287
      die "Can't execute command '$statement'\nError: $DBI::errstr\n";
 
288
    }
 
289
  }
 
290
}
 
291
 
 
292
sub safe_do_many
 
293
{
 
294
  my ($dbh,@statements)=@_;
 
295
  my ($statement,$sth);
 
296
 
 
297
  foreach $statement (@statements)
 
298
  {
 
299
    if (!($sth=$dbh->do($statement)))
 
300
    {
 
301
      print STDERR "Can't execute command '$statement'\nError: $DBI::errstr\n";
 
302
      return 1;
 
303
    }
 
304
  }
 
305
  return 0;
 
306
}
 
307
 
 
308
 
 
309
 
 
310
#
 
311
# Do a query and fetch all rows from a statement and return the number of rows
 
312
#
 
313
 
 
314
sub fetch_all_rows
 
315
{
 
316
  my ($dbh,$query,$must_get_result)=@_;
 
317
  my ($count,$sth);
 
318
  $count=0;
 
319
 
 
320
  print "$query: " if ($opt_debug);
 
321
  if (!($sth= $dbh->prepare($query)))
 
322
  {
 
323
    print "\n" if ($opt_debug);
 
324
    die "Error occured with prepare($query)\n -> $DBI::errstr\n";
 
325
    return undef;
 
326
  }
 
327
  if (!$sth->execute)
 
328
  {
 
329
    print "\n" if ($opt_debug);
 
330
    if (defined($server->{'error_on_execute_means_zero_rows'}) &&
 
331
       !$server->abort_if_fatal_error())
 
332
    {
 
333
      if (defined($must_get_result) && $must_get_result)
 
334
      {
 
335
        die "Error: Query $query didn't return any rows\n";
 
336
      }
 
337
      $sth->finish;
 
338
      print "0\n" if ($opt_debug);
 
339
      return 0;
 
340
    }
 
341
    die "Error occured with execute($query)\n -> $DBI::errstr\n";
 
342
    $sth->finish;
 
343
    return undef;
 
344
  }
 
345
  while ($sth->fetchrow_arrayref)
 
346
  {
 
347
    $count++;
 
348
  }
 
349
  print "$count\n" if ($opt_debug);
 
350
  if (defined($must_get_result) && $must_get_result && !$count)
 
351
  {
 
352
    die "Error: Query $query didn't return any rows\n";
 
353
  }
 
354
  $sth->finish;
 
355
  undef($sth);
 
356
  return $count;
 
357
}
 
358
 
 
359
sub do_query
 
360
{
 
361
  my($dbh,$query)=@_;
 
362
  print "$query\n" if ($opt_debug);
 
363
  $dbh->do($query) or
 
364
    die "\nError executing '$query':\n$DBI::errstr\n";
 
365
}
 
366
 
 
367
#
 
368
# Run a query X times
 
369
#
 
370
 
 
371
sub time_fetch_all_rows
 
372
{
 
373
  my($test_text,$result_text,$query,$dbh,$test_count)=@_;
 
374
  my($i,$loop_time,$end_time,$count,$rows,$estimated);
 
375
 
 
376
  print $test_text . "\n"   if (defined($test_text));
 
377
  $count=$rows=0;
 
378
  $loop_time=new Benchmark;
 
379
  for ($i=1 ; $i <= $test_count ; $i++)
 
380
  {
 
381
    $count++;
 
382
    $rows+=fetch_all_rows($dbh,$query) or die $DBI::errstr;
 
383
    $end_time=new Benchmark;
 
384
    last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$i,
 
385
                                           $test_count));
 
386
  }
 
387
  $end_time=new Benchmark;
 
388
  if ($estimated)
 
389
  { print "Estimated time"; }
 
390
  else
 
391
  { print "Time"; }
 
392
  print " for $result_text ($count:$rows) " .
 
393
    timestr(timediff($end_time, $loop_time),"all") . "\n\n";
 
394
}
 
395
 
 
396
 
 
397
#
 
398
# Handle estimated time of the server is too slow
 
399
# Returns 0 if one should continue as normal
 
400
#
 
401
 
 
402
sub predict_query_time
 
403
{
 
404
  my ($loop_time,$end_time,$count_ref,$loop,$loop_count)= @_;
 
405
  my ($k,$tmp);
 
406
 
 
407
  if (($end_time->[0] - $loop_time->[0]) > $opt_time_limit)
 
408
  {
 
409
    # We can't wait until the SUN dies.  Try to predict the end time
 
410
    if ($loop != $loop_count)
 
411
    {
 
412
      $tmp=($end_time->[0] - $loop_time->[0]);
 
413
      print "Note: Query took longer then time-limit: $opt_time_limit\nEstimating end time based on:\n";
 
414
      print "$$count_ref queries in $loop loops of $loop_count loops took $tmp seconds\n";
 
415
      for ($k=0; $k < 3; $k++)
 
416
      {
 
417
        $tmp=$loop_time->[$k]+($end_time->[$k]-$loop_time->[$k])/$loop*
 
418
          $loop_count;
 
419
        $estimated[$k]+=($tmp-$end_time->[$k]);
 
420
        $end_time->[$k]=$tmp;
 
421
      }
 
422
      $$count_ref= int($$count_ref/$loop*$loop_count);
 
423
      return 1;
 
424
    }
 
425
  }
 
426
  return 0;
 
427
}
 
428
 
 
429
#
 
430
# standard end of benchmark
 
431
#
 
432
 
 
433
sub end_benchmark
 
434
{
 
435
  my ($start_time)=@_;
 
436
 
 
437
  $end_time=new Benchmark;
 
438
  if ($estimated[0])
 
439
  {
 
440
    print "Estimated total time: ";
 
441
    $end_time->[0]+=$estimated[0];
 
442
    $end_time->[1]+=$estimated[1];
 
443
    $end_time->[2]+=$estimated[2];
 
444
  }
 
445
  else
 
446
  {
 
447
    print "Total time: "
 
448
    }
 
449
  print timestr(timediff($end_time, $start_time),"all") . "\n";
 
450
  exit 0;
 
451
}
 
452
 
 
453
sub print_time
 
454
{
 
455
  my ($estimated)=@_;
 
456
  if ($estimated)
 
457
  { print "Estimated time"; }
 
458
  else
 
459
  { print "Time"; }
 
460
}
 
461
 
 
462
#
 
463
# Usage
 
464
#
 
465
 
 
466
sub usage
 
467
{
 
468
  my $error_msg= $_[0];
 
469
  print "ERROR: $error_msg\n\n";
 
470
  print <<EOF;
 
471
The MySQL benchmarks Ver $benchmark_version
 
472
 
 
473
All benchmarks takes the following options:
 
474
 
 
475
--bzr-repo=<DIR>
 
476
  Specifies a bazaar repository directory for the test suite to obtain the 
 
477
  repo version which it then uses as part of the results output filenames 
 
478
 
 
479
--comments
 
480
  Add a comment to the benchmark output.  Comments should contain
 
481
  extra information that 'uname -a' doesn\'t give and if the database was
 
482
  stared with some specific, non default, options.
 
483
 
 
484
--cmp=server[,server...]
 
485
  Run the test with limits from the given servers.  If you run all servers
 
486
  with the same --cmp, you will get a test that is comparable between
 
487
  the different sql servers.
 
488
 
 
489
--create-options=#
 
490
  Extra argument to all create statements.  If you for example want to
 
491
  create all MySQL tables as InnoDB tables use:
 
492
  --create-options=ENGINE=InnoDB
 
493
 
 
494
--database (Default $opt_database)
 
495
  In which database the test tables are created.
 
496
 
 
497
--debug
 
498
  This is a test specific option that is only used when debugging a test.
 
499
  Print out debugging information.
 
500
 
 
501
--dir (Default $opt_dir)
 
502
  Option to 'run-all-tests' to where the test results should be stored.
 
503
 
 
504
--fast
 
505
  Allow the database to use non standard ANSI SQL commands to make the
 
506
  test go faster.
 
507
 
 
508
--fast-insert
 
509
  Use "insert into table_name values(...)" instead of
 
510
  "insert into table_name (....) values(...)"
 
511
  If the database supports it, some tests uses multiple value lists.
 
512
 
 
513
--field-count
 
514
  This is a test specific option that is only used when debugging a test.
 
515
  This usually means how many fields there should be in the test table.
 
516
 
 
517
--force
 
518
  This is a test specific option that is only used when debugging a test.
 
519
  Continue the test even if there is some error.
 
520
  Delete tables before creating new ones.
 
521
 
 
522
--groups (Default $opt_groups)
 
523
  This is a test specific option that is only used when debugging a test.
 
524
  This usually means how many different groups there should be in the test.
 
525
 
 
526
--lock-tables
 
527
  Allow the database to use table locking to get more speed.
 
528
 
 
529
--log
 
530
  Option to 'run-all-tests' to save the result to the '--dir' directory.
 
531
 
 
532
--loop-count (Default $opt_loop_count)
 
533
  This is a test specific option that is only used when debugging a test.
 
534
  This usually means how many times times each test loop is executed.
 
535
 
 
536
--help
 
537
  Shows this help
 
538
 
 
539
--host='host name' (Default $opt_host)
 
540
  Host name where the database server is located.
 
541
 
 
542
--machine="machine or os_name"
 
543
  The machine/os name that is added to the benchmark output filename.
 
544
  The default is the OS name + version.
 
545
 
 
546
--odbc
 
547
  Use the ODBC DBI driver to connect to the database.
 
548
 
 
549
--only-missing-tests
 
550
  Only run test that don\'t have an old test result.
 
551
  This is useful when you want to do a re-run of tests that failed in last run.
 
552
 
 
553
--optimization='some comments'
 
554
 Add coments about optimization of DBMS, which was done before the test.
 
555
 
 
556
--password='password'
 
557
  Password for the current user.
 
558
 
 
559
--socket='socket'
 
560
  If the database supports connecting through a Unix socket,
 
561
  then use this socket to connect
 
562
 
 
563
--regions
 
564
  This is a test specific option that is only used when debugging a test.
 
565
  This usually means how AND levels should be tested.
 
566
 
 
567
--old-headers
 
568
  Get the old benchmark headers from the old RUN- file.
 
569
 
 
570
--server='server name'  (Default $opt_server)
 
571
  Run the test on the given SQL server.
 
572
  Known servers names are: Access, Adabas, AdabasD, Empress, Oracle,
 
573
  Informix, DB2, mSQL, MS-SQL, MySQL, Pg, Solid and Sybase
 
574
 
 
575
--silent
 
576
  Don't print info about the server when starting test.
 
577
 
 
578
--skip-delete
 
579
  This is a test specific option that is only used when debugging a test.
 
580
  This will keep the test tables after the test is run.
 
581
 
 
582
--skip-test=test1[,test2,...]
 
583
  For run-all-programs;  Don\'t execute the named tests.
 
584
 
 
585
--small-test
 
586
  This runs some tests with smaller limits to get a faster test.
 
587
  Can be used if you just want to verify that the database works, but
 
588
  don't have time to run a full test.
 
589
 
 
590
--small-tables
 
591
  This runs some tests that generate big tables with fewer rows.
 
592
  This can be used with databases that can\'t handle that many rows
 
593
  because of pre-sized partitions.
 
594
 
 
595
--suffix (Default $opt_suffix)
 
596
  The suffix that is added to the database name in the benchmark output
 
597
  filename.  This can be used to run the benchmark multiple times with
 
598
  different server options without overwritten old files.
 
599
  When using --fast the suffix is automaticly set to '_fast'.
 
600
 
 
601
--random
 
602
  Inform test suite that we are generate random inital values for sequence of
 
603
  test executions. It should be used for imitation of real conditions.
 
604
 
 
605
--threads=# (Default 5)
 
606
  Number of threads for multi-user benchmarks.
 
607
 
 
608
--tcpip
 
609
  Inform test suite that we are using TCP/IP to connect to the server. In
 
610
  this case we can\t do many new connections in a row as we in this case may
 
611
  fill the TCP/IP stack
 
612
 
 
613
--time-limit (Default $opt_time_limit)
 
614
  How long a test loop is allowed to take, in seconds, before the end result
 
615
  is 'estimated'.
 
616
 
 
617
--use-old-results
 
618
  Option to 'run-all-tests' to use the old results from the  '--dir' directory
 
619
  instead of running the tests.
 
620
 
 
621
--user='user_name'
 
622
  User name to log into the SQL server.
 
623
 
 
624
--verbose
 
625
  This is a test specific option that is only used when debugging a test.
 
626
  Print more information about what is going on.
 
627
 
 
628
--hw='some comments'
 
629
 Add coments about hardware used for this test.
 
630
 
 
631
--connect-options='some connect options'
 
632
  Add options, which uses at DBI connect.
 
633
  For example --connect-options=mysql_read_default_file=/etc/my.cnf.
 
634
 
 
635
EOF
 
636
  exit(0);
 
637
}
 
638
 
 
639
 
 
640
 
 
641
####
 
642
#### The end of the base file ...
 
643
####
 
644
1;