Changeset 6
- Timestamp:
- 06/01/07 03:26:26 (2 years ago)
- Files:
-
- mysqltuner.pl (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mysqltuner.pl
r5 r6 3 3 use warnings; 4 4 use diagnostics; 5 use Getopt::Long; 6 7 # Set defaults 8 my %opt = ( 9 "nobad" => 0, 10 "nogood" => 0, 11 "noinfo" => 0, 12 "notitle" => 0, 13 ); 14 15 # Gather the options from the command line 16 GetOptions(\%opt, 17 'nobad', 18 'nogood', 19 'noinfo', 20 'notitle', 21 'help', 22 ); 23 24 if (defined $opt{'help'} && $opt{'help'} == 1) { usage(); } 25 26 sub usage { 27 print "\n". 28 " MySQL High Performance Tuning Script\n". 29 " Bug reports, feature requests, and downloads at http://mysqltuner.com/\n". 30 " Maintained by Major Hayden (major.hayden\@rackspace.com)\n\n". 31 " Important Usage Guidelines:\n". 32 " To run the script with the default options, run the script without arguments\n". 33 " Allow MySQL server to run for at least 24-48 hours before trusting suggestions\n". 34 " Some routines may require root level privileges (script will provide warnings)\n\n". 35 " Output Options:\n". 36 " --nogood Remove OK responses\n". 37 " --nobad Remove negative/suggestion responses\n". 38 " --noinfo Remove informational responses\n". 39 " --notitle Remove section title headers\n". 40 "\n"; 41 exit; 42 } 5 43 6 44 # CONFIGURATION ITEMS … … 11 49 12 50 sub goodprint { 51 if ($opt{nogood} == 1) { return 0; } 13 52 my $text = shift; 14 53 print $good." ".$text; … … 16 55 17 56 sub infoprint { 57 if ($opt{noinfo} == 1) { return 0; } 18 58 my $text = shift; 19 59 print $info." ".$text; … … 21 61 22 62 sub badprint { 63 if ($opt{nobad} == 1) { return 0; } 23 64 my $text = shift; 24 65 print $bad." ".$text; 66 } 67 68 sub titleprint { 69 if ($opt{notitle} == 1) { return 0; } 70 my $text = shift; 71 print $text; 25 72 } 26 73 … … 201 248 202 249 sub check_memory { 203 print "------ MEMORY USAGE ------\n";250 titleprint "------ MEMORY USAGE ------\n"; 204 251 # The purpose of this section is to make sure you're not going to end up in swap or crashing the box 205 252 # by having buffers that are set too large … … 235 282 # query_cache_size - holds query results (default 0) [still allocated when query_cache_type = 0] 236 283 my $query_cache_size = (defined $myvar{'query_cache_size'}) ? $myvar{'query_cache_size'} : 0 ; 284 # max_heap_table_size / tmp_table_size - hold temporary table data from queries 285 # ** The effective temporary table size is the smaller number between these two 286 my $eff_tmp_table_size; 287 if ($myvar{'tmp_table_size'} > $myvar{'max_heap_table_size'}) { 288 $eff_tmp_table_size = $myvar{'max_heap_table_size'}; 289 } else { 290 $eff_tmp_table_size = $myvar{'tmp_table_size'}; 291 } 237 292 # 238 293 # GLOBAL BUFFER CALCULATIONS: 239 my $global_buffers = $innodb_buffer_pool_size + $innodb_additional_mem_pool_size + $innodb_log_buffer_size + $key_buffer_size + $query_cache_size ;294 my $global_buffers = $innodb_buffer_pool_size + $innodb_additional_mem_pool_size + $innodb_log_buffer_size + $key_buffer_size + $query_cache_size + $eff_tmp_table_size; 240 295 # 241 296 # FINAL BUFFER/MEMORY CALCULATIONS: … … 255 310 ") of physical memory (".hr_bytes($physical_memory).")\n"; 256 311 } 312 infoprint "This memory total above is when MySQL is at absolute full load\n"; 257 313 } 258 314 259 315 sub check_slow_queries { 260 print "------ SLOW QUERIES ------\n";316 titleprint "------ SLOW QUERIES ------\n"; 261 317 # If the server hasn't received any queries, then we can't calculate a slow query percentage 262 318 if ($mystat{'Questions'} > 0) { … … 287 343 288 344 sub check_connections { 289 print "------ CONNECTION LIMITS ------\n";345 titleprint "------ CONNECTION LIMITS ------\n"; 290 346 # We're looking at two things here: 291 347 # How many connections have been used so far and how close is the connection limit? … … 316 372 317 373 sub check_key_buffer { 318 print "------ KEY BUFFER ------\n";374 titleprint "------ KEY BUFFER ------\n"; 319 375 my $myisamindexes; 320 376 if ($mysqlvermajor < 5) { … … 376 432 377 433 sub check_query_cache { 378 print "------ QUERY CACHE ------\n";434 titleprint "------ QUERY CACHE ------\n"; 379 435 # If query cache support isn't compiled into MySQL, we fail here 380 436 if (!defined $myvar{'have_query_cache'}) { … … 428 484 429 485 sub check_sort { 430 print "------ SORTING ------\n";486 titleprint "------ SORTING ------\n"; 431 487 # SORTING VARIABLES/STATUS: 432 488 # read_rnd_buffer_size - sorts are read from this buffer after the sort is complete, helps ORDER BY … … 454 510 455 511 sub check_join { 456 print "------ JOINS ------\n";512 titleprint "------ JOINS ------\n"; 457 513 # JOIN VARIABLES/STATUS: 458 514 # join_buffer_size - buffer used to join tables when indexes can't be utilized … … 473 529 474 530 sub check_temporary_tables { 475 print "------ TEMPORARY TABLES ------\n";531 titleprint "------ TEMPORARY TABLES ------\n"; 476 532 # TEMPORARY TABLE VARIABLES/STATUS: 477 533 # Created_tmp_disk_tables - number of temporary tables created on disk … … 496 552 497 553 sub check_other_buffers { 498 print "------ OTHER BUFFERS ------\n";554 titleprint "------ OTHER BUFFERS ------\n"; 499 555 # bulk_insert_buffer_size = buffer for large inserts (default: 8M) 500 556 infoprint "Your bulk_insert_buffer_size is ".hr_bytes_rnd($myvar{'bulk_insert_buffer_size'}). … … 503 559 504 560 sub performance_options { 505 print "------ PERFORMANCE OPTIONS ------\n";561 titleprint "------ PERFORMANCE OPTIONS ------\n"; 506 562 # concurrent_insert = enables simultaneous insert/select on MyISAM tables w/o holes 507 563 # It's ON/OFF in MySQL 4.1 and 0/1 in MySQL 5.x … … 516 572 # BEGIN 'MAIN' 517 573 # --------------------------------------------------------------------------- 518 infoprint "MySQL High-Performance Tuner - Major Hayden <major.hayden\@rackspace.com>\n"; 574 print " MySQL High-Performance Tuner - Major Hayden <major.hayden\@rackspace.com>\n". 575 " Bug reports, feature requests, downloads at mysqltuner.com\n"; 519 576 mysql_install_ok; # Check to see if MySQL is installed 520 577 os_setup; # Set up some OS variables