Assembla home | Assembla project page
 

Changeset 6

Show
Ignore:
Timestamp:
06/01/07 03:26:26 (2 years ago)
Author:
major
Message:

Massive changes... output filtering, usage information, and temporary table corrections with regards to max memory calculations

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mysqltuner.pl

    r5 r6  
    33use warnings; 
    44use diagnostics; 
     5use Getopt::Long; 
     6 
     7# Set defaults 
     8my %opt = ( 
     9        "nobad" => 0, 
     10        "nogood" => 0, 
     11        "noinfo" => 0, 
     12        "notitle" => 0, 
     13    ); 
     14 
     15# Gather the options from the command line 
     16GetOptions(\%opt, 
     17        'nobad', 
     18        'nogood', 
     19        'noinfo', 
     20        'notitle', 
     21        'help', 
     22    ); 
     23 
     24if (defined $opt{'help'} && $opt{'help'} == 1) { usage(); } 
     25 
     26sub 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} 
    543 
    644# CONFIGURATION ITEMS 
     
    1149 
    1250sub goodprint { 
     51    if ($opt{nogood} == 1) { return 0; } 
    1352    my $text = shift; 
    1453    print $good." ".$text; 
     
    1655 
    1756sub infoprint { 
     57    if ($opt{noinfo} == 1) { return 0; } 
    1858    my $text = shift; 
    1959    print $info." ".$text; 
     
    2161 
    2262sub badprint { 
     63    if ($opt{nobad} == 1) { return 0; } 
    2364    my $text = shift; 
    2465    print $bad." ".$text; 
     66} 
     67 
     68sub titleprint { 
     69    if ($opt{notitle} == 1) { return 0; } 
     70    my $text = shift; 
     71    print $text; 
    2572} 
    2673 
     
    201248 
    202249sub check_memory { 
    203     print "------ MEMORY USAGE ------\n"; 
     250    titleprint "------ MEMORY USAGE ------\n"; 
    204251    # The purpose of this section is to make sure you're not going to end up in swap or crashing the box 
    205252    # by having buffers that are set too large 
     
    235282    #   query_cache_size - holds query results (default 0) [still allocated when query_cache_type = 0] 
    236283    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    } 
    237292    # 
    238293    # 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
    240295    # 
    241296    # FINAL BUFFER/MEMORY CALCULATIONS: 
     
    255310            ") of physical memory (".hr_bytes($physical_memory).")\n"; 
    256311    } 
     312    infoprint "This memory total above is when MySQL is at absolute full load\n"; 
    257313} 
    258314 
    259315sub check_slow_queries { 
    260     print "------ SLOW QUERIES ------\n"; 
     316    titleprint "------ SLOW QUERIES ------\n"; 
    261317    # If the server hasn't received any queries, then we can't calculate a slow query percentage 
    262318    if ($mystat{'Questions'} > 0) { 
     
    287343 
    288344sub check_connections { 
    289     print "------ CONNECTION LIMITS ------\n"; 
     345    titleprint "------ CONNECTION LIMITS ------\n"; 
    290346    # We're looking at two things here: 
    291347    #   How many connections have been used so far and how close is the connection limit? 
     
    316372 
    317373sub check_key_buffer { 
    318     print "------ KEY BUFFER ------\n"; 
     374    titleprint "------ KEY BUFFER ------\n"; 
    319375    my $myisamindexes; 
    320376    if ($mysqlvermajor < 5) { 
     
    376432 
    377433sub check_query_cache { 
    378     print "------ QUERY CACHE ------\n"; 
     434    titleprint "------ QUERY CACHE ------\n"; 
    379435    # If query cache support isn't compiled into MySQL, we fail here 
    380436    if (!defined $myvar{'have_query_cache'}) { 
     
    428484 
    429485sub check_sort { 
    430     print "------ SORTING ------\n"; 
     486    titleprint "------ SORTING ------\n"; 
    431487    # SORTING VARIABLES/STATUS: 
    432488    #   read_rnd_buffer_size - sorts are read from this buffer after the sort is complete, helps ORDER BY 
     
    454510 
    455511sub check_join { 
    456     print "------ JOINS ------\n"; 
     512    titleprint "------ JOINS ------\n"; 
    457513    # JOIN VARIABLES/STATUS: 
    458514    #   join_buffer_size - buffer used to join tables when indexes can't be utilized 
     
    473529 
    474530sub check_temporary_tables { 
    475     print "------ TEMPORARY TABLES ------\n"; 
     531    titleprint "------ TEMPORARY TABLES ------\n"; 
    476532    # TEMPORARY TABLE VARIABLES/STATUS: 
    477533    #   Created_tmp_disk_tables - number of temporary tables created on disk 
     
    496552 
    497553sub check_other_buffers { 
    498     print "------ OTHER BUFFERS ------\n"; 
     554    titleprint "------ OTHER BUFFERS ------\n"; 
    499555    #  bulk_insert_buffer_size = buffer for large inserts (default: 8M) 
    500556    infoprint "Your bulk_insert_buffer_size is ".hr_bytes_rnd($myvar{'bulk_insert_buffer_size'}). 
     
    503559 
    504560sub performance_options { 
    505     print "------ PERFORMANCE OPTIONS ------\n"; 
     561    titleprint "------ PERFORMANCE OPTIONS ------\n"; 
    506562    # concurrent_insert = enables simultaneous insert/select on MyISAM tables w/o holes 
    507563    # It's ON/OFF in MySQL 4.1 and 0/1 in MySQL 5.x 
     
    516572# BEGIN 'MAIN' 
    517573# --------------------------------------------------------------------------- 
    518 infoprint "MySQL High-Performance Tuner - Major Hayden <major.hayden\@rackspace.com>\n"; 
     574print   "     MySQL High-Performance Tuner - Major Hayden <major.hayden\@rackspace.com>\n". 
     575        "     Bug reports, feature requests, downloads at mysqltuner.com\n"; 
    519576mysql_install_ok;               # Check to see if MySQL is installed 
    520577os_setup;                       # Set up some OS variables