Changeset 22
- Timestamp:
- 12/01/07 22:04:00 (1 year ago)
- Files:
-
- mysqltuner.pl (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mysqltuner.pl
r21 r22 183 183 my (%mystat,%myvar,$dummyselect); 184 184 sub get_all_vars { 185 # We need to initiate at least one query so that our data is useable 185 186 $dummyselect = `mysql $mysqllogin -Bse "SELECT VERSION();"`; 186 187 my @mysqlvarlist = `mysql $mysqllogin -Bse "SHOW /*!50000 GLOBAL */ VARIABLES;"`; … … 205 206 } else { 206 207 goodprint "Currently running supported MySQL version ".$myvar{'version'}."\n"; 208 } 209 } 210 211 my ($arch); 212 sub check_architecture { 213 if (`uname -m` =~ /64/) { 214 $arch = 64; 215 goodprint "Operating on 64-bit architecture\n"; 216 } else { 217 $arch = 32; 218 if ($physical_memory > 2*1024*1024*1024) { 219 badprint "Switch to 64-bit OS - MySQL cannot currenty use all of your RAM\n"; 220 } else { 221 goodprint "Operating on 32-bit architecture with less than 2GB RAM\n"; 222 } 207 223 } 208 224 } … … 383 399 } 384 400 } 385 } 386 387 my (@decvars, @incvars, @generalrec); 401 402 # InnoDB 403 if ($myvar{'have_innodb'} eq "YES") { 404 $mycalc{'innodb_log_size_pct'} = ($myvar{'innodb_log_file_size'} * 100 / $myvar{'innodb_buffer_pool_size'}); 405 } 406 407 } 408 409 my (@adjvars, @generalrec); 388 410 sub mysql_stats { 389 411 print "-------- General Statistics --------------------------------------------------\n"; … … 401 423 infoprint "Total buffers per thread: ".hr_bytes($mycalc{'per_thread_buffers'})."\n"; 402 424 infoprint "Total global buffers: ".hr_bytes($mycalc{'server_buffers'})."\n"; 403 if ($mycalc{'pct_physical_memory'} > 85) { 425 if ($mycalc{'total_possible_used_memory'} > 2*1024*1024*1024 && $arch eq 32) { 426 badprint "Allocating > 2GB RAM on 32-bit systems can cause system instability\n"; 427 badprint "Maximum possible memory usage: ".hr_bytes($mycalc{'total_possible_used_memory'})." ($mycalc{'pct_physical_memory'}% of installed RAM)\n"; 428 } elsif ($mycalc{'pct_physical_memory'} > 85) { 404 429 badprint "Maximum possible memory usage: ".hr_bytes($mycalc{'total_possible_used_memory'})." ($mycalc{'pct_physical_memory'}% of installed RAM)\n"; 405 430 push(@generalrec,"Reduce your overall MySQL memory footprint for system stability"); … … 414 439 goodprint "Slow queries: $mycalc{'pct_slow_queries'}%\n"; 415 440 } 416 if ($myvar{'long_query_time'} > 10) { push(@ decvars,"long_query_time (<= 10)"); }441 if ($myvar{'long_query_time'} > 10) { push(@adjvars,"long_query_time (<= 10)"); } 417 442 if (defined($myvar{'log_slow_queries'})) { 418 443 if ($myvar{'log_slow_queries'} eq "OFF") { push(@generalrec,"Enable the slow query log to troubleshoot bad queries"); } … … 422 447 if ($mycalc{'pct_connections_used'} > 85) { 423 448 badprint "Highest connection usage: $mycalc{'pct_connections_used'}%\n"; 424 push(@ incvars,"max_connections (> ".$myvar{'max_connections'}.")");425 push(@ decvars,"wait_timeout (< ".$myvar{'wait_timeout'}.")","interactive_timeout (< ".$myvar{'interactive_timeout'}.")");449 push(@adjvars,"max_connections (> ".$myvar{'max_connections'}.")"); 450 push(@adjvars,"wait_timeout (< ".$myvar{'wait_timeout'}.")","interactive_timeout (< ".$myvar{'interactive_timeout'}.")"); 426 451 push(@generalrec,"Reduce or eliminate persistent connections to reduce connection usage") 427 452 } else { … … 437 462 if ($myvar{'key_buffer_size'} < $mycalc{'total_myisam_indexes'} && $mycalc{'pct_keys_from_mem'} < 95) { 438 463 badprint "Key buffer size / total MyISAM indexes: ".hr_bytes($myvar{'key_buffer_size'})."/".hr_bytes($mycalc{'total_myisam_indexes'})."\n"; 439 push(@ incvars,"key_buffer_size (> ".hr_bytes($mycalc{'total_myisam_indexes'}).")");464 push(@adjvars,"key_buffer_size (> ".hr_bytes($mycalc{'total_myisam_indexes'}).")"); 440 465 } else { 441 466 goodprint "Key buffer size / total MyISAM indexes: ".hr_bytes($myvar{'key_buffer_size'})."/".hr_bytes($mycalc{'total_myisam_indexes'})."\n"; … … 460 485 } elsif ($myvar{'query_cache_size'} < 1) { 461 486 badprint "Query cache is disabled\n"; 462 push(@ incvars,"query_cache_size (>= 8M)");487 push(@adjvars,"query_cache_size (>= 8M)"); 463 488 } elsif ($mystat{'Com_select'} == 0) { 464 489 badprint "Query cache cannot be analyzed - no SELECT statements executed\n"; … … 466 491 if ($mycalc{'query_cache_efficiency'} < 20) { 467 492 badprint "Query cache efficiency: $mycalc{'query_cache_efficiency'}%\n"; 468 push(@ incvars,"query_cache_limit (> 1M, or use smaller result sets)");493 push(@adjvars,"query_cache_limit (> 1M, or use smaller result sets)"); 469 494 } else { 470 495 goodprint "Query cache efficiency: $mycalc{'query_cache_efficiency'}%\n"; … … 472 497 if ($mycalc{'query_cache_prunes_per_day'} > 98) { 473 498 badprint "Query cache prunes per day: $mycalc{'query_cache_prunes_per_day'}\n"; 474 push(@ incvars,"query_cache_size (> ".hr_bytes_rnd($myvar{'query_cache_size'}).")")499 push(@adjvars,"query_cache_size (> ".hr_bytes_rnd($myvar{'query_cache_size'}).")") 475 500 } else { 476 501 goodprint "Query cache prunes per day: $mycalc{'query_cache_prunes_per_day'}\n"; … … 484 509 } elsif ($mycalc{'pct_temp_sort_table'} > 10) { 485 510 badprint "Sorts requiring temporary tables: $mycalc{'pct_temp_sort_table'}%\n"; 486 push(@ incvars,"sort_buffer_size (> ".hr_bytes_rnd($myvar{'sort_buffer_size'}).")");487 push(@ incvars,"read_rnd_buffer_size (> ".hr_bytes_rnd($myvar{'read_rnd_buffer_size'}).")");511 push(@adjvars,"sort_buffer_size (> ".hr_bytes_rnd($myvar{'sort_buffer_size'}).")"); 512 push(@adjvars,"read_rnd_buffer_size (> ".hr_bytes_rnd($myvar{'read_rnd_buffer_size'}).")"); 488 513 } else { 489 514 goodprint "Sorts requiring temporary tables: $mycalc{'pct_temp_sort_table'}%\n"; … … 493 518 if ($mycalc{'joins_without_indexes_per_day'} > 250) { 494 519 badprint "Joins performed without indexes: $mycalc{'joins_without_indexes'}\n"; 495 push(@ incvars,"join_buffer_size (> ".hr_bytes($myvar{'join_buffer_size'}).", or always use indexes with joins)");520 push(@adjvars,"join_buffer_size (> ".hr_bytes($myvar{'join_buffer_size'}).", or always use indexes with joins)"); 496 521 push(@generalrec,"Adjust your join queries to always utilize indexes"); 497 522 } else { … … 502 527 # Temporary tables 503 528 if ($mystat{'Created_tmp_tables'} > 0) { 504 if ($mycalc{'pct_temp_disk'} > 25 && $mycalc{'max_tmp_table_size'} < 256 ) {529 if ($mycalc{'pct_temp_disk'} > 25 && $mycalc{'max_tmp_table_size'} < 256*1024*1024) { 505 530 badprint "Temporary tables created on disk: $mycalc{'pct_temp_disk'}%\n"; 506 push(@ incvars,"tmp_table_size (> ".hr_bytes_rnd($myvar{'tmp_table_size'}).")");507 push(@ incvars,"max_heap_table_size (> ".hr_bytes_rnd($myvar{'max_heap_table_size'}).")");531 push(@adjvars,"tmp_table_size (> ".hr_bytes_rnd($myvar{'tmp_table_size'}).")"); 532 push(@adjvars,"max_heap_table_size (> ".hr_bytes_rnd($myvar{'max_heap_table_size'}).")"); 508 533 push(@generalrec,"Be sure that tmp_table_size/max_heap_table_size are equal"); 509 534 push(@generalrec,"Reduce your SELECT DISTINCT queries without LIMIT clauses"); … … 521 546 522 547 # Thread cache 523 if ($mycalc{'thread_cache_hit_rate'} <= 50) { 524 badprint "Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}%\n"; 525 } else { 526 goodprint "Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}%\n"; 527 } 548 if ($myvar{'thread_cache_size'} eq 0) { 549 badprint "Thread cache is disabled\n"; 550 push(@generalrec,"Set thread_cache_size to 4 as a starting value"); 551 push(@adjvars,"thread_cache_size (start at 4)"); 552 } else { 553 if ($mycalc{'thread_cache_hit_rate'} <= 50) { 554 badprint "Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}%\n"; 555 push(@adjvars,"thread_cache_size (> $myvar{'thread_cache_size'})"); 556 } else { 557 goodprint "Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}%\n"; 558 } 559 } 560 528 561 529 562 # Table cache … … 531 564 if ($mycalc{'table_cache_hit_rate'} < 20) { 532 565 badprint "Table cache hit rate: $mycalc{'table_cache_hit_rate'}%\n"; 533 push(@ incvars,"table_cache (> ".$myvar{'table_cache'}.")");566 push(@adjvars,"table_cache (> ".$myvar{'table_cache'}.")"); 534 567 push(@generalrec,"Increase table_cache gradually to avoid file descriptor limits"); 535 568 } else { … … 542 575 if ($mycalc{'pct_files_open'} > 85) { 543 576 badprint "Open file limit used: $mycalc{'pct_files_open'}%\n"; 544 push(@ incvars,"open_files_limit (> ".$myvar{'open_files_limit'}.")");577 push(@adjvars,"open_files_limit (> ".$myvar{'open_files_limit'}.")"); 545 578 } else { 546 579 goodprint "Open file limit used: $mycalc{'pct_files_open'}%\n"; … … 570 603 push(@generalrec,"Your applications are not closing MySQL connections properly"); 571 604 } 605 606 # InnoDB 607 if ($myvar{'have_innodb'} eq "YES") { 608 if ($mycalc{'innodb_log_size_pct'} > 20 && $mycalc{'innodb_log_size_pct'} < 30) { 609 goodprint "InnoDB log size is ".hr_bytes($myvar{'innodb_log_file_size'})." ($mycalc{'innodb_log_size_pct'}% of InnoDB buffer pool)\n"; 610 } else { 611 badprint "InnoDB log size is ".hr_bytes($myvar{'innodb_log_file_size'})." ($mycalc{'innodb_log_size_pct'}% of InnoDB buffer pool)\n"; 612 push(@generalrec,"Set innodb_log_file_size to 25% of InnoDB buffer pool"); 613 push(@adjvars,"innodb_log_file_size (".hr_bytes($myvar{'innodb_buffer_pool_size'}*.25).", which is 25% of InnoDB buffer pool)"); 614 } 615 } 616 572 617 } 573 618 … … 578 623 foreach (@generalrec) { print " ".$_."\n"; } 579 624 } 580 if (@ incvars > 0) {581 print "Variables to increase:\n";625 if (@adjvars > 0) { 626 print "Variables to adjust:\n"; 582 627 if ($mycalc{'pct_physical_memory'} > 85) { 583 628 print " *** MySQL's maximum memory usage exceeds your installed memory ***\n". 584 629 " *** Add more RAM before increasing any MySQL buffer variables ***\n"; 585 630 } 586 foreach (@incvars) { print " ".$_."\n"; } 587 } 588 if (@decvars > 0) { 589 print "Variables to decrease:\n"; 590 foreach (@decvars) { print " ".$_."\n"; } 631 foreach (@adjvars) { print " ".$_."\n"; } 591 632 } 592 633 } … … 602 643 get_all_vars; # Toss variables/status into hashes 603 644 validate_mysql_version; # Check current MySQL version 645 check_architecture; # Suggest 64-bit upgrade 604 646 calculations; # Calculate everything we need 605 647 mysql_stats; # Print the server stats