You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

602 lines
15 KiB

Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
  1. #!@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. # The exported values are:
  27. # $opt_... Various options
  28. # $date Current date in ISO format
  29. # $server Object for current server
  30. # $limits Hash reference to limits for benchmark
  31. $benchmark_version="2.15";
  32. use Getopt::Long;
  33. use POSIX;
  34. require "$pwd/server-cfg" || die "Can't read Configuration file: $!\n";
  35. $|=1; # Output data immediately
  36. $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;
  37. $opt_cmp=$opt_user=$opt_password=$opt_connect_options="";
  38. $opt_server="mysql"; $opt_dir="output";
  39. $opt_host="localhost";$opt_database="test";
  40. $opt_machine=""; $opt_suffix="";
  41. $opt_create_options=undef;
  42. $opt_optimization="None";
  43. $opt_hw="";
  44. $opt_threads=5;
  45. if (!defined($opt_time_limit))
  46. {
  47. $opt_time_limit=10*60; # Don't wait more than 10 min for some tests
  48. }
  49. $log_prog_args=join(" ", skip_arguments(\@ARGV,"comments","cmp","server",
  50. "user", "host", "database", "password",
  51. "use-old-results","skip-test",
  52. "optimization","hw",
  53. "machine", "dir", "suffix", "log"));
  54. GetOptions("skip-test=s","comments=s","cmp=s","server=s","user=s","host=s","database=s","password=s","loop-count=i","row-count=i","skip-create","skip-delete","verbose","fast-insert","lock-tables","debug","fast","force","field-count=i","regions=i","groups=i","time-limit=i","log","use-old-results","machine=s","dir=s","suffix=s","help","odbc","small-test","small-tables","small-key-tables","stage=i","threads=i","random","old-headers","die-on-errors","create-options=s","hires","tcpip","silent","optimization=s","hw=s","socket=s","connect-options=s","only-missing-tests") || usage();
  55. usage() if ($opt_help);
  56. $server=get_server($opt_server,$opt_host,$opt_database,$opt_odbc,
  57. machine_part(), $opt_socket, $opt_connect_options);
  58. $limits=merge_limits($server,$opt_cmp);
  59. $date=date();
  60. @estimated=(0.0,0.0,0.0); # For estimated time support
  61. if ($opt_hires)
  62. {
  63. eval "use Time::HiRes;";
  64. }
  65. {
  66. my $tmp= $opt_server;
  67. $tmp =~ s/_odbc$//;
  68. if (length($opt_cmp) && index($opt_cmp,$tmp) < 0)
  69. {
  70. $opt_cmp.=",$tmp";
  71. }
  72. }
  73. $opt_cmp=lc(join(",",sort(split(',',$opt_cmp))));
  74. #
  75. # set opt_lock_tables if one uses --fast and drivers supports it
  76. #
  77. if (($opt_lock_tables || $opt_fast) && $server->{'limits'}->{'lock_tables'})
  78. {
  79. $opt_lock_tables=1;
  80. }
  81. else
  82. {
  83. $opt_lock_tables=0;
  84. }
  85. if ($opt_fast)
  86. {
  87. $opt_fast_insert=1;
  88. $opt_suffix="_fast" if (!length($opt_suffix));
  89. }
  90. if ($opt_odbc)
  91. {
  92. $opt_suffix="_odbc" if (!length($opt_suffix));
  93. }
  94. if (!$opt_silent)
  95. {
  96. print "Testing server '" . $server->version() . "' at $date\n\n";
  97. }
  98. if ($opt_debug)
  99. {
  100. print "\nCurrent limits: \n";
  101. foreach $key (sort keys %$limits)
  102. {
  103. print $key . " " x (30-length($key)) . $limits->{$key} . "\n";
  104. }
  105. print "\n";
  106. }
  107. #
  108. # Some help functions
  109. #
  110. sub skip_arguments
  111. {
  112. my($argv,@skip_args)=@_;
  113. my($skip,$arg,$name,@res);
  114. foreach $arg (@$argv)
  115. {
  116. if ($arg =~ /^\-+([^=]*)/)
  117. {
  118. $name=$1;
  119. foreach $skip (@skip_args)
  120. {
  121. if (index($skip,$name) == 0)
  122. {
  123. $name=""; # Don't use this parameters
  124. last;
  125. }
  126. }
  127. push (@res,$arg) if (length($name));
  128. }
  129. }
  130. return @res;
  131. }
  132. sub merge_limits
  133. {
  134. my ($server,$cmp)= @_;
  135. my ($name,$tmp_server,$limits,$res_limits,$limit,$tmp_limits);
  136. $res_limits=$server->{'limits'};
  137. if ($cmp)
  138. {
  139. foreach $name (split(",",$cmp))
  140. {
  141. $tmp_server= (get_server($name,$opt_host, $opt_database,
  142. $opt_odbc,machine_part())
  143. || die "Unknown SQL server: $name\n");
  144. $limits=$tmp_server->{'limits'};
  145. %new_limits=();
  146. foreach $limit (keys(%$limits))
  147. {
  148. if (defined($res_limits->{$limit}) && defined($limits->{$limit}))
  149. {
  150. $new_limits{$limit}=min($res_limits->{$limit},$limits->{$limit});
  151. }
  152. }
  153. %tmp_limits=%new_limits;
  154. $res_limits=\%tmp_limits;
  155. }
  156. }
  157. return $res_limits;
  158. }
  159. sub date
  160. {
  161. my ($sec, $min, $hour, $mday, $mon, $year) = localtime(time());
  162. sprintf("%04d-%02d-%02d %2d:%02d:%02d",
  163. 1900+$year,$mon+1,$mday,$hour,$min,$sec);
  164. }
  165. sub min
  166. {
  167. my($min)=$_[0];
  168. my($i);
  169. for ($i=1 ; $i <= $#_; $i++)
  170. {
  171. $min=$_[$i] if ($min > $_[$i]);
  172. }
  173. return $min;
  174. }
  175. sub max
  176. {
  177. my($max)=$_[0];
  178. my($i);
  179. for ($i=1 ; $i <= $#_; $i++)
  180. {
  181. $max=$_[$i] if ($max < $_[$i]);
  182. }
  183. return $max;
  184. }
  185. #
  186. # Execute many statements in a row
  187. #
  188. sub do_many
  189. {
  190. my ($dbh,@statements)=@_;
  191. my ($statement,$sth);
  192. foreach $statement (@statements)
  193. {
  194. if (!($sth=$dbh->do($statement)))
  195. {
  196. die "Can't execute command '$statement'\nError: $DBI::errstr\n";
  197. }
  198. }
  199. }
  200. sub safe_do_many
  201. {
  202. my ($dbh,@statements)=@_;
  203. my ($statement,$sth);
  204. foreach $statement (@statements)
  205. {
  206. if (!($sth=$dbh->do($statement)))
  207. {
  208. print STDERR "Can't execute command '$statement'\nError: $DBI::errstr\n";
  209. return 1;
  210. }
  211. }
  212. return 0;
  213. }
  214. #
  215. # Do a query and fetch all rows from a statement and return the number of rows
  216. #
  217. sub fetch_all_rows
  218. {
  219. my ($dbh,$query,$must_get_result)=@_;
  220. my ($count,$sth);
  221. $count=0;
  222. print "$query: " if ($opt_debug);
  223. if (!($sth= $dbh->prepare($query)))
  224. {
  225. print "\n" if ($opt_debug);
  226. die "Error occured with prepare($query)\n -> $DBI::errstr\n";
  227. return undef;
  228. }
  229. if (!$sth->execute)
  230. {
  231. print "\n" if ($opt_debug);
  232. if (defined($server->{'error_on_execute_means_zero_rows'}) &&
  233. !$server->abort_if_fatal_error())
  234. {
  235. if (defined($must_get_result) && $must_get_result)
  236. {
  237. die "Error: Query $query didn't return any rows\n";
  238. }
  239. $sth->finish;
  240. print "0\n" if ($opt_debug);
  241. return 0;
  242. }
  243. die "Error occured with execute($query)\n -> $DBI::errstr\n";
  244. $sth->finish;
  245. return undef;
  246. }
  247. while ($sth->fetchrow_arrayref)
  248. {
  249. $count++;
  250. }
  251. print "$count\n" if ($opt_debug);
  252. if (defined($must_get_result) && $must_get_result && !$count)
  253. {
  254. die "Error: Query $query didn't return any rows\n";
  255. }
  256. $sth->finish;
  257. undef($sth);
  258. return $count;
  259. }
  260. sub do_query
  261. {
  262. my($dbh,$query)=@_;
  263. print "$query\n" if ($opt_debug);
  264. $dbh->do($query) or
  265. die "\nError executing '$query':\n$DBI::errstr\n";
  266. }
  267. #
  268. # Run a query X times
  269. #
  270. sub time_fetch_all_rows
  271. {
  272. my($test_text,$result_text,$query,$dbh,$test_count)=@_;
  273. my($i,$loop_time,$end_time,$count,$rows,$estimated);
  274. print $test_text . "\n" if (defined($test_text));
  275. $count=$rows=0;
  276. $loop_time=new Benchmark;
  277. for ($i=1 ; $i <= $test_count ; $i++)
  278. {
  279. $count++;
  280. $rows+=fetch_all_rows($dbh,$query) or die $DBI::errstr;
  281. $end_time=new Benchmark;
  282. last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$i,
  283. $test_count));
  284. }
  285. $end_time=new Benchmark;
  286. if ($estimated)
  287. { print "Estimated time"; }
  288. else
  289. { print "Time"; }
  290. print " for $result_text ($count:$rows) " .
  291. timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  292. }
  293. #
  294. # Handle estimated time of the server is too slow
  295. # Returns 0 if one should continue as normal
  296. #
  297. sub predict_query_time
  298. {
  299. my ($loop_time,$end_time,$count_ref,$loop,$loop_count)= @_;
  300. my ($k,$tmp);
  301. if (($end_time->[0] - $loop_time->[0]) > $opt_time_limit)
  302. {
  303. # We can't wait until the SUN dies. Try to predict the end time
  304. if ($loop != $loop_count)
  305. {
  306. $tmp=($end_time->[0] - $loop_time->[0]);
  307. print "Note: Query took longer then time-limit: $opt_time_limit\nEstimating end time based on:\n";
  308. print "$$count_ref queries in $loop loops of $loop_count loops took $tmp seconds\n";
  309. for ($k=0; $k < 3; $k++)
  310. {
  311. $tmp=$loop_time->[$k]+($end_time->[$k]-$loop_time->[$k])/$loop*
  312. $loop_count;
  313. $estimated[$k]+=($tmp-$end_time->[$k]);
  314. $end_time->[$k]=$tmp;
  315. }
  316. $$count_ref= int($$count_ref/$loop*$loop_count);
  317. return 1;
  318. }
  319. }
  320. return 0;
  321. }
  322. #
  323. # standard end of benchmark
  324. #
  325. sub end_benchmark
  326. {
  327. my ($start_time)=@_;
  328. $end_time=new Benchmark;
  329. if ($estimated[0])
  330. {
  331. print "Estimated total time: ";
  332. $end_time->[0]+=$estimated[0];
  333. $end_time->[1]+=$estimated[1];
  334. $end_time->[2]+=$estimated[2];
  335. }
  336. else
  337. {
  338. print "Total time: "
  339. }
  340. print timestr(timediff($end_time, $start_time),"all") . "\n";
  341. exit 0;
  342. }
  343. sub print_time
  344. {
  345. my ($estimated)=@_;
  346. if ($estimated)
  347. { print "Estimated time"; }
  348. else
  349. { print "Time"; }
  350. }
  351. #
  352. # Create a filename part for the machine that can be used for log file.
  353. #
  354. sub machine_part
  355. {
  356. my ($name,$orig);
  357. return $opt_machine if (length($opt_machine)); # Specified by user
  358. # Specified by user
  359. $orig=$name=machine();
  360. $name="win9$1" if ($orig =~ /win.*9(\d)/i);
  361. $name="NT_$1" if ($orig =~ /Windows NT.*(\d+\.\d+)/i);
  362. $name="win2k" if ($orig =~ /Windows 2000/i);
  363. $name =~ s/\s+/_/g; # Make the filenames easier to parse
  364. $name =~ s/-/_/g;
  365. $name =~ s/\//_/g;
  366. return $name;
  367. }
  368. sub machine
  369. {
  370. my @name = POSIX::uname();
  371. my $name= $name[0] . " " . $name[2] . " " . $name[4];
  372. return $name;
  373. }
  374. #
  375. # Usage
  376. #
  377. sub usage
  378. {
  379. print <<EOF;
  380. The MySQL benchmarks Ver $benchmark_version
  381. All benchmarks takes the following options:
  382. --comments
  383. Add a comment to the benchmark output. Comments should contain
  384. extra information that 'uname -a' doesn\'t give and if the database was
  385. stared with some specific, non default, options.
  386. --cmp=server[,server...]
  387. Run the test with limits from the given servers. If you run all servers
  388. with the same --cmp, you will get a test that is comparable between
  389. the different sql servers.
  390. --create-options=#
  391. Extra argument to all create statements. If you for example want to
  392. create all MySQL tables as InnoDB tables use:
  393. --create-options=ENGINE=InnoDB
  394. --database (Default $opt_database)
  395. In which database the test tables are created.
  396. --debug
  397. This is a test specific option that is only used when debugging a test.
  398. Print out debugging information.
  399. --dir (Default $opt_dir)
  400. Option to 'run-all-tests' to where the test results should be stored.
  401. --fast
  402. Allow the database to use non standard ANSI SQL commands to make the
  403. test go faster.
  404. --fast-insert
  405. Use "insert into table_name values(...)" instead of
  406. "insert into table_name (....) values(...)"
  407. If the database supports it, some tests uses multiple value lists.
  408. --field-count
  409. This is a test specific option that is only used when debugging a test.
  410. This usually means how many fields there should be in the test table.
  411. --force
  412. This is a test specific option that is only used when debugging a test.
  413. Continue the test even if there is some error.
  414. Delete tables before creating new ones.
  415. --groups (Default $opt_groups)
  416. This is a test specific option that is only used when debugging a test.
  417. This usually means how many different groups there should be in the test.
  418. --lock-tables
  419. Allow the database to use table locking to get more speed.
  420. --log
  421. Option to 'run-all-tests' to save the result to the '--dir' directory.
  422. --loop-count (Default $opt_loop_count)
  423. This is a test specific option that is only used when debugging a test.
  424. This usually means how many times times each test loop is executed.
  425. --help
  426. Shows this help
  427. --host='host name' (Default $opt_host)
  428. Host name where the database server is located.
  429. --machine="machine or os_name"
  430. The machine/os name that is added to the benchmark output filename.
  431. The default is the OS name + version.
  432. --odbc
  433. Use the ODBC DBI driver to connect to the database.
  434. --only-missing-tests
  435. Only run test that don\'t have an old test result.
  436. This is useful when you want to do a re-run of tests that failed in last run.
  437. --optimization='some comments'
  438. Add coments about optimization of DBMS, which was done before the test.
  439. --password='password'
  440. Password for the current user.
  441. --socket='socket'
  442. If the database supports connecting through a Unix socket,
  443. then use this socket to connect
  444. --regions
  445. This is a test specific option that is only used when debugging a test.
  446. This usually means how AND levels should be tested.
  447. --old-headers
  448. Get the old benchmark headers from the old RUN- file.
  449. --server='server name' (Default $opt_server)
  450. Run the test on the given SQL server.
  451. Known servers names are: Access, Adabas, AdabasD, Empress, Oracle,
  452. Informix, DB2, mSQL, MS-SQL, MySQL, Pg, Solid and Sybase
  453. --silent
  454. Don't print info about the server when starting test.
  455. --skip-delete
  456. This is a test specific option that is only used when debugging a test.
  457. This will keep the test tables after the test is run.
  458. --skip-test=test1[,test2,...]
  459. For run-all-programs; Don\'t execute the named tests.
  460. --small-test
  461. This runs some tests with smaller limits to get a faster test.
  462. Can be used if you just want to verify that the database works, but
  463. don't have time to run a full test.
  464. --small-tables
  465. This runs some tests that generate big tables with fewer rows.
  466. This can be used with databases that can\'t handle that many rows
  467. because of pre-sized partitions.
  468. --suffix (Default $opt_suffix)
  469. The suffix that is added to the database name in the benchmark output
  470. filename. This can be used to run the benchmark multiple times with
  471. different server options without overwritten old files.
  472. When using --fast the suffix is automaticly set to '_fast'.
  473. --random
  474. Inform test suite that we are generate random inital values for sequence of
  475. test executions. It should be used for imitation of real conditions.
  476. --threads=# (Default 5)
  477. Number of threads for multi-user benchmarks.
  478. --tcpip
  479. Inform test suite that we are using TCP/IP to connect to the server. In
  480. this case we can\t do many new connections in a row as we in this case may
  481. fill the TCP/IP stack
  482. --time-limit (Default $opt_time_limit)
  483. How long a test loop is allowed to take, in seconds, before the end result
  484. is 'estimated'.
  485. --use-old-results
  486. Option to 'run-all-tests' to use the old results from the '--dir' directory
  487. instead of running the tests.
  488. --user='user_name'
  489. User name to log into the SQL server.
  490. --verbose
  491. This is a test specific option that is only used when debugging a test.
  492. Print more information about what is going on.
  493. --hw='some comments'
  494. Add coments about hardware used for this test.
  495. --connect-options='some connect options'
  496. Add options, which uses at DBI connect.
  497. For example --connect-options=mysql_read_default_file=/etc/my.cnf.
  498. EOF
  499. exit(0);
  500. }
  501. ####
  502. #### The end of the base file ...
  503. ####
  504. 1;