Permalink
Browse files

* 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
  • Loading branch information...
1 parent 34b5cba commit bc69094412f202cebf12d441967192c110ce0723 @major committed Dec 1, 2007
Showing with 76 additions and 35 deletions.
  1. +76 −35 mysqltuner.pl
View
111 mysqltuner.pl
@@ -180,7 +180,8 @@ sub mysql_setup {
}
}
-my (%mystat,%myvar,$dummyselect);
+my (%mystat,%myvar,$dummyselect);
+sub get_all_vars {
# We need to initiate at least one query so that our data is useable
$dummyselect = `mysql $mysqllogin -Bse "SELECT VERSION();"`;
my @mysqlvarlist = `mysql $mysqllogin -Bse "SHOW /*!50000 GLOBAL */ VARIABLES;"`;
@@ -205,6 +206,21 @@ sub validate_mysql_version {
} else {
goodprint "Currently running supported MySQL version ".$myvar{'version'}."\n";
}
+}
+
+my ($arch);
+sub check_architecture {
+ if (`uname -m` =~ /64/) {
+ $arch = 64;
+ goodprint "Operating on 64-bit architecture\n";
+ } else {
+ $arch = 32;
+ if ($physical_memory > 2*1024*1024*1024) {
+ badprint "Switch to 64-bit OS - MySQL cannot currenty use all of your RAM\n";
+ } else {
+ goodprint "Operating on 32-bit architecture with less than 2GB RAM\n";
+ }
+ }
}
sub pretty_uptime {
@@ -380,10 +396,16 @@ sub calculations {
} else {
$mycalc{'pct_reads'} = int(($mycalc{'total_reads'}/($mycalc{'total_reads'}+$mycalc{'total_writes'})) * 100);
$mycalc{'pct_writes'} = 100-$mycalc{'pct_reads'};
- }
+ }
+ }
+
+ # InnoDB
+ if ($myvar{'have_innodb'} eq "YES") {
+ $mycalc{'innodb_log_size_pct'} = ($myvar{'innodb_log_file_size'} * 100 / $myvar{'innodb_buffer_pool_size'});
+ }
}
-
+
my (@adjvars, @generalrec);
sub mysql_stats {
print "-------- General Statistics --------------------------------------------------\n";
@@ -398,8 +420,11 @@ sub mysql_stats {
infoprint "Reads / Writes: ".$mycalc{'pct_reads'}."% / ".$mycalc{'pct_writes'}."%\n";
# Memory usage
- infoprint "Total buffers per thread: ".hr_bytes($mycalc{'per_thread_buffers'})."\n";
- infoprint "Total global buffers: ".hr_bytes($mycalc{'server_buffers'})."\n";
+ infoprint "Total buffers per thread: ".hr_bytes($mycalc{'per_thread_buffers'})."\n";
+ infoprint "Total global buffers: ".hr_bytes($mycalc{'server_buffers'})."\n";
+ if ($mycalc{'total_possible_used_memory'} > 2*1024*1024*1024 && $arch eq 32) {
+ badprint "Allocating > 2GB RAM on 32-bit systems can cause system instability\n";
+ badprint "Maximum possible memory usage: ".hr_bytes($mycalc{'total_possible_used_memory'})." ($mycalc{'pct_physical_memory'}% of installed RAM)\n";
} elsif ($mycalc{'pct_physical_memory'} > 85) {
badprint "Maximum possible memory usage: ".hr_bytes($mycalc{'total_possible_used_memory'})." ($mycalc{'pct_physical_memory'}% of installed RAM)\n";
push(@generalrec,"Reduce your overall MySQL memory footprint for system stability");
@@ -412,16 +437,16 @@ sub mysql_stats {
badprint "Slow queries: $mycalc{'pct_slow_queries'}%\n";
} else {
goodprint "Slow queries: $mycalc{'pct_slow_queries'}%\n";
- }
+ }
if ($myvar{'long_query_time'} > 10) { push(@adjvars,"long_query_time (<= 10)"); }
if (defined($myvar{'log_slow_queries'})) {
if ($myvar{'log_slow_queries'} eq "OFF") { push(@generalrec,"Enable the slow query log to troubleshoot bad queries"); }
}
# Connections
if ($mycalc{'pct_connections_used'} > 85) {
- badprint "Highest connection usage: $mycalc{'pct_connections_used'}%\n";
- push(@incvars,"max_connections (> ".$myvar{'max_connections'}.")");
+ badprint "Highest connection usage: $mycalc{'pct_connections_used'}%\n";
+ push(@adjvars,"max_connections (> ".$myvar{'max_connections'}.")");
push(@adjvars,"wait_timeout (< ".$myvar{'wait_timeout'}.")","interactive_timeout (< ".$myvar{'interactive_timeout'}.")");
push(@generalrec,"Reduce or eliminate persistent connections to reduce connection usage")
} else {
@@ -435,7 +460,7 @@ sub mysql_stats {
badprint "None of your MyISAM tables are indexed - add indexes immediately\n";
} else {
if ($myvar{'key_buffer_size'} < $mycalc{'total_myisam_indexes'} && $mycalc{'pct_keys_from_mem'} < 95) {
- badprint "Key buffer size / total MyISAM indexes: ".hr_bytes($myvar{'key_buffer_size'})."/".hr_bytes($mycalc{'total_myisam_indexes'})."\n";
+ badprint "Key buffer size / total MyISAM indexes: ".hr_bytes($myvar{'key_buffer_size'})."/".hr_bytes($mycalc{'total_myisam_indexes'})."\n";
push(@adjvars,"key_buffer_size (> ".hr_bytes($mycalc{'total_myisam_indexes'}).")");
} else {
goodprint "Key buffer size / total MyISAM indexes: ".hr_bytes($myvar{'key_buffer_size'})."/".hr_bytes($mycalc{'total_myisam_indexes'})."\n";
@@ -458,19 +483,19 @@ sub mysql_stats {
# MySQL versions < 4.01 don't support query caching
push(@generalrec,"Upgrade MySQL to version 4+ to utilize query caching");
} elsif ($myvar{'query_cache_size'} < 1) {
- badprint "Query cache is disabled\n";
+ badprint "Query cache is disabled\n";
push(@adjvars,"query_cache_size (>= 8M)");
} elsif ($mystat{'Com_select'} == 0) {
badprint "Query cache cannot be analyzed - no SELECT statements executed\n";
} else {
if ($mycalc{'query_cache_efficiency'} < 20) {
- badprint "Query cache efficiency: $mycalc{'query_cache_efficiency'}%\n";
+ badprint "Query cache efficiency: $mycalc{'query_cache_efficiency'}%\n";
push(@adjvars,"query_cache_limit (> 1M, or use smaller result sets)");
} else {
goodprint "Query cache efficiency: $mycalc{'query_cache_efficiency'}%\n";
}
if ($mycalc{'query_cache_prunes_per_day'} > 98) {
- badprint "Query cache prunes per day: $mycalc{'query_cache_prunes_per_day'}\n";
+ badprint "Query cache prunes per day: $mycalc{'query_cache_prunes_per_day'}\n";
push(@adjvars,"query_cache_size (> ".hr_bytes_rnd($myvar{'query_cache_size'}).")")
} else {
goodprint "Query cache prunes per day: $mycalc{'query_cache_prunes_per_day'}\n";
@@ -482,16 +507,16 @@ sub mysql_stats {
# For the sake of space, we will be quiet here
# No sorts have run yet
} elsif ($mycalc{'pct_temp_sort_table'} > 10) {
- badprint "Sorts requiring temporary tables: $mycalc{'pct_temp_sort_table'}%\n";
- push(@incvars,"sort_buffer_size (> ".hr_bytes_rnd($myvar{'sort_buffer_size'}).")");
+ badprint "Sorts requiring temporary tables: $mycalc{'pct_temp_sort_table'}%\n";
+ push(@adjvars,"sort_buffer_size (> ".hr_bytes_rnd($myvar{'sort_buffer_size'}).")");
push(@adjvars,"read_rnd_buffer_size (> ".hr_bytes_rnd($myvar{'read_rnd_buffer_size'}).")");
} else {
goodprint "Sorts requiring temporary tables: $mycalc{'pct_temp_sort_table'}%\n";
}
# Joins
if ($mycalc{'joins_without_indexes_per_day'} > 250) {
- badprint "Joins performed without indexes: $mycalc{'joins_without_indexes'}\n";
+ badprint "Joins performed without indexes: $mycalc{'joins_without_indexes'}\n";
push(@adjvars,"join_buffer_size (> ".hr_bytes($myvar{'join_buffer_size'}).", or always use indexes with joins)");
push(@generalrec,"Adjust your join queries to always utilize indexes");
} else {
@@ -500,10 +525,10 @@ sub mysql_stats {
}
# Temporary tables
- if ($mystat{'Created_tmp_tables'} > 0) {
+ if ($mystat{'Created_tmp_tables'} > 0) {
if ($mycalc{'pct_temp_disk'} > 25 && $mycalc{'max_tmp_table_size'} < 256*1024*1024) {
- badprint "Temporary tables created on disk: $mycalc{'pct_temp_disk'}%\n";
- push(@incvars,"tmp_table_size (> ".hr_bytes_rnd($myvar{'tmp_table_size'}).")");
+ badprint "Temporary tables created on disk: $mycalc{'pct_temp_disk'}%\n";
+ push(@adjvars,"tmp_table_size (> ".hr_bytes_rnd($myvar{'tmp_table_size'}).")");
push(@adjvars,"max_heap_table_size (> ".hr_bytes_rnd($myvar{'max_heap_table_size'}).")");
push(@generalrec,"Be sure that tmp_table_size/max_heap_table_size are equal");
push(@generalrec,"Reduce your SELECT DISTINCT queries without LIMIT clauses");
@@ -518,18 +543,25 @@ sub mysql_stats {
# For the sake of space, we will be quiet here
# No temporary tables have been created
}
-
- # Thread cache
- if ($mycalc{'thread_cache_hit_rate'} <= 50) {
- badprint "Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}%\n";
- } else {
- goodprint "Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}%\n";
+
+ # Thread cache
+ if ($myvar{'thread_cache_size'} eq 0) {
+ badprint "Thread cache is disabled\n";
+ push(@generalrec,"Set thread_cache_size to 4 as a starting value");
+ push(@adjvars,"thread_cache_size (start at 4)");
+ } else {
+ if ($mycalc{'thread_cache_hit_rate'} <= 50) {
+ badprint "Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}%\n";
+ push(@adjvars,"thread_cache_size (> $myvar{'thread_cache_size'})");
+ } else {
+ goodprint "Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}%\n";
+ }
}
# Table cache
if ($mystat{'Open_tables'} > 0) {
- badprint "Table cache hit rate: $mycalc{'table_cache_hit_rate'}%\n";
+ if ($mycalc{'table_cache_hit_rate'} < 20) {
badprint "Table cache hit rate: $mycalc{'table_cache_hit_rate'}%\n";
push(@adjvars,"table_cache (> ".$myvar{'table_cache'}.")");
push(@generalrec,"Increase table_cache gradually to avoid file descriptor limits");
@@ -540,7 +572,7 @@ sub mysql_stats {
# Open files
if ($myvar{'open_files_limit'} > 0) {
- badprint "Open file limit used: $mycalc{'pct_files_open'}%\n";
+ if ($mycalc{'pct_files_open'} > 85) {
badprint "Open file limit used: $mycalc{'pct_files_open'}%\n";
push(@adjvars,"open_files_limit (> ".$myvar{'open_files_limit'}.")");
} else {
@@ -567,7 +599,19 @@ sub mysql_stats {
push(@generalrec,"Enable concurrent_insert by setting it to 1");
}
if ($mycalc{'pct_aborted_connections'} > 5) {
- push(@generalrec,"Your applications are not closing MySQL connections properly");
+ badprint "Connections aborted: ".$mycalc{'pct_aborted_connections'}."%\n";
+ push(@generalrec,"Your applications are not closing MySQL connections properly");
+ }
+
+ # InnoDB
+ if ($myvar{'have_innodb'} eq "YES") {
+ if ($mycalc{'innodb_log_size_pct'} > 20 && $mycalc{'innodb_log_size_pct'} < 30) {
+ goodprint "InnoDB log size is ".hr_bytes($myvar{'innodb_log_file_size'})." ($mycalc{'innodb_log_size_pct'}% of InnoDB buffer pool)\n";
+ } else {
+ badprint "InnoDB log size is ".hr_bytes($myvar{'innodb_log_file_size'})." ($mycalc{'innodb_log_size_pct'}% of InnoDB buffer pool)\n";
+ push(@generalrec,"Set innodb_log_file_size to 25% of InnoDB buffer pool");
+ push(@adjvars,"innodb_log_file_size (".hr_bytes($myvar{'innodb_buffer_pool_size'}*.25).", which is 25% of InnoDB buffer pool)");
+ }
}
}
@@ -576,17 +620,13 @@ sub make_recommendations {
print "-------- Recommendations -----------------------------------------------------\n";
if (@generalrec > 0) {
print "General recommendations:\n";
- }
- if (@incvars > 0) {
+ foreach (@generalrec) { print " ".$_."\n"; }
+ }
if (@adjvars > 0) {
print "Variables to adjust:\n";
if ($mycalc{'pct_physical_memory'} > 85) {
print " *** MySQL's maximum memory usage exceeds your installed memory ***\n".
- }
- foreach (@incvars) { print " ".$_."\n"; }
- }
- if (@decvars > 0) {
- print "Variables to decrease:\n";
+ " *** Add more RAM before increasing any MySQL buffer variables ***\n";
}
foreach (@adjvars) { print " ".$_."\n"; }
}
@@ -599,7 +639,8 @@ sub make_recommendations {
" Bug reports, feature requests, and downloads at http://mysqltuner.com/\n".
" Run with '--help' for additional options and output filtering\n";
os_setup; # Set up some OS variables
-get_all_vars; # Toss variables/status into hashes
+mysql_setup; # Gotta login first
+get_all_vars; # Toss variables/status into hashes
validate_mysql_version; # Check current MySQL version
check_architecture; # Suggest 64-bit upgrade
calculations; # Calculate everything we need

0 comments on commit bc69094

Please sign in to comment.