Assembla home | Assembla project page
 

Changeset 22

Show
Ignore:
Timestamp:
12/01/07 22:04:00 (1 year ago)
Author:
major
Message:

* Added innodb_log_file_size checks
* Added 32-bit/64-bit checks and warnings (maximum memory > 2GB = bad)
* Fixed temporary table recommendation bug (would never recommend increase)
* Fixed thread cache recommendations/warnings
* Merged increase/decrease variable recommendations into one category

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mysqltuner.pl

    r21 r22  
    183183my (%mystat,%myvar,$dummyselect); 
    184184sub get_all_vars { 
     185    # We need to initiate at least one query so that our data is useable 
    185186    $dummyselect = `mysql $mysqllogin -Bse "SELECT VERSION();"`; 
    186187    my @mysqlvarlist = `mysql $mysqllogin -Bse "SHOW /*!50000 GLOBAL */ VARIABLES;"`; 
     
    205206    } else { 
    206207        goodprint "Currently running supported MySQL version ".$myvar{'version'}."\n"; 
     208    } 
     209} 
     210 
     211my ($arch); 
     212sub 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        } 
    207223    } 
    208224} 
     
    383399                } 
    384400        } 
    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 
     409my (@adjvars, @generalrec); 
    388410sub mysql_stats { 
    389411    print "-------- General Statistics --------------------------------------------------\n"; 
     
    401423    infoprint "Total buffers per thread: ".hr_bytes($mycalc{'per_thread_buffers'})."\n"; 
    402424    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) { 
    404429        badprint "Maximum possible memory usage: ".hr_bytes($mycalc{'total_possible_used_memory'})." ($mycalc{'pct_physical_memory'}% of installed RAM)\n"; 
    405430        push(@generalrec,"Reduce your overall MySQL memory footprint for system stability"); 
     
    414439        goodprint "Slow queries: $mycalc{'pct_slow_queries'}%\n"; 
    415440    } 
    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)"); } 
    417442    if (defined($myvar{'log_slow_queries'})) { 
    418443            if ($myvar{'log_slow_queries'} eq "OFF") { push(@generalrec,"Enable the slow query log to troubleshoot bad queries"); } 
     
    422447    if ($mycalc{'pct_connections_used'} > 85) { 
    423448        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'}.")"); 
    426451        push(@generalrec,"Reduce or eliminate persistent connections to reduce connection usage") 
    427452    } else { 
     
    437462        if ($myvar{'key_buffer_size'} < $mycalc{'total_myisam_indexes'} && $mycalc{'pct_keys_from_mem'} < 95) { 
    438463            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'}).")"); 
    440465        } else { 
    441466            goodprint "Key buffer size / total MyISAM indexes: ".hr_bytes($myvar{'key_buffer_size'})."/".hr_bytes($mycalc{'total_myisam_indexes'})."\n"; 
     
    460485    } elsif ($myvar{'query_cache_size'} < 1) { 
    461486        badprint "Query cache is disabled\n"; 
    462         push(@incvars,"query_cache_size (>= 8M)"); 
     487        push(@adjvars,"query_cache_size (>= 8M)"); 
    463488    } elsif ($mystat{'Com_select'} == 0) { 
    464489        badprint "Query cache cannot be analyzed - no SELECT statements executed\n"; 
     
    466491        if ($mycalc{'query_cache_efficiency'} < 20) { 
    467492            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)"); 
    469494        } else { 
    470495            goodprint "Query cache efficiency: $mycalc{'query_cache_efficiency'}%\n"; 
     
    472497        if ($mycalc{'query_cache_prunes_per_day'} > 98) { 
    473498            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'}).")") 
    475500        } else { 
    476501            goodprint "Query cache prunes per day: $mycalc{'query_cache_prunes_per_day'}\n"; 
     
    484509    } elsif ($mycalc{'pct_temp_sort_table'} > 10) { 
    485510        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'}).")"); 
    488513    } else { 
    489514        goodprint "Sorts requiring temporary tables: $mycalc{'pct_temp_sort_table'}%\n"; 
     
    493518    if ($mycalc{'joins_without_indexes_per_day'} > 250) { 
    494519        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)"); 
    496521        push(@generalrec,"Adjust your join queries to always utilize indexes"); 
    497522    } else { 
     
    502527    # Temporary tables 
    503528    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) { 
    505530            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'}).")"); 
    508533            push(@generalrec,"Be sure that tmp_table_size/max_heap_table_size are equal"); 
    509534            push(@generalrec,"Reduce your SELECT DISTINCT queries without LIMIT clauses"); 
     
    521546 
    522547    # 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 
    528561 
    529562    # Table cache 
     
    531564        if ($mycalc{'table_cache_hit_rate'} < 20) { 
    532565            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'}.")"); 
    534567            push(@generalrec,"Increase table_cache gradually to avoid file descriptor limits"); 
    535568        } else { 
     
    542575        if ($mycalc{'pct_files_open'} > 85) { 
    543576            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'}.")"); 
    545578        } else { 
    546579            goodprint "Open file limit used: $mycalc{'pct_files_open'}%\n"; 
     
    570603                push(@generalrec,"Your applications are not closing MySQL connections properly"); 
    571604        } 
     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 
    572617} 
    573618 
     
    578623        foreach (@generalrec) { print "     ".$_."\n"; } 
    579624    } 
    580     if (@incvars > 0) { 
    581         print "Variables to increase:\n"; 
     625    if (@adjvars > 0) { 
     626        print "Variables to adjust:\n"; 
    582627        if ($mycalc{'pct_physical_memory'} > 85) { 
    583628            print "     *** MySQL's maximum memory usage exceeds your installed memory ***\n". 
    584629                  "     *** Add more RAM before increasing any MySQL buffer variables  ***\n"; 
    585630        } 
    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"; } 
    591632    } 
    592633} 
     
    602643get_all_vars;                       # Toss variables/status into hashes 
    603644validate_mysql_version;             # Check current MySQL version 
     645check_architecture;                 # Suggest 64-bit upgrade 
    604646calculations;                       # Calculate everything we need 
    605647mysql_stats;                        # Print the server stats