@@ -68,7 +68,8 @@ package main;
6868# Set up a few variables for use in the script
6969our $tunerversion = " 2.8.41" ;
7070our ( @adjvars , @generalrec , @modeling , @sysrec , @secrec );
71- our ( %result , %myvar , %real_vars , %mystat , %mycalc , %myrepl , %myreplicas , $dummyselect );
71+ our ( %result , %myvar , %real_vars , %mystat , %mycalc , %myrepl , %myreplicas ,
72+ $dummyselect );
7273
7374# Set defaults
7475# Central metadata for CLI options
@@ -309,8 +310,9 @@ package main;
309310 },
310311 ' schemadir' => {
311312 type => ' =s' ,
312- default => undef ,
313- desc => ' Path to a directory where to dump one markdown file per schema' ,
313+ default => undef ,
314+ desc =>
315+ ' Path to a directory where to dump one markdown file per schema' ,
314316 placeholder => ' <path>' ,
315317 cat => ' PERFORMANCE'
316318 },
@@ -2163,7 +2165,8 @@ sub mysql_setup {
21632165 return 1;
21642166 }
21652167 else {
2166- badprint " Attempted to use login credentials, but they were invalid." ;
2168+ badprint
2169+ " Attempted to use login credentials, but they were invalid." ;
21672170 debugprint " Login failure output: $loginstatus " ;
21682171 }
21692172 }
@@ -2348,7 +2351,7 @@ sub mysql_setup {
23482351 system (" stty echo >$devnull 2>&1" );
23492352 }
23502353 $password = " " unless defined $password ;
2351- $name = " " unless defined $name ;
2354+ $name = " " unless defined $name ;
23522355 chomp ($password );
23532356 chomp ($name );
23542357 $mysqllogin = " $defaults_options -u $name " ;
@@ -2861,7 +2864,7 @@ sub get_all_vars {
28612864 my @lineitems = ();
28622865 foreach my $line (@mysqlreplicas ) {
28632866 debugprint " L: $line " ;
2864- @lineitems = split /\s +/, $line ;
2867+ @lineitems = split /\s +/, $line ;
28652868 $myreplicas { $lineitems [0] } = $line ;
28662869 $result {' Replication' }{' Replicas' }{ $lineitems [0] } = $lineitems [4];
28672870 }
@@ -3851,7 +3854,7 @@ sub system_recommendations {
38513854 }
38523855 else {
38533856 get_fs_info;
3854- if ( !is_docker() && ($opt {' container' } // ' ' ) eq ' ' ) {
3857+ if ( !is_docker() && ( $opt {' container' } // ' ' ) eq ' ' ) {
38553858 subheaderprint " Kernel Information Recommendations" ;
38563859 get_kernel_info;
38573860 }
@@ -4988,10 +4991,11 @@ sub check_storage_engines {
49884991 my ( $name , $rows , $autoincrement ) = @$tbl ;
49894992
49904993 if ( $autoincrement && $autoincrement =~ / ^\d +?$ / ) {
4991- # Issue #37: Skip tables where AUTO_INCREMENT is at default (never used) and table is empty
4994+
4995+ # Issue #37: Skip tables where AUTO_INCREMENT is at default (never used) and table is empty
49924996 next if ( $autoincrement <= 1 && ( $rows // 0 ) == 0 );
49934997
4994- # Issue #37: Guard against unresolved column max producing a false 100%
4998+ # Issue #37: Guard against unresolved column max producing a false 100%
49954999 next unless defined $maxint && $maxint > 0;
49965000
49975001 my $percent = percentage( $autoincrement , $maxint );
@@ -5008,7 +5012,7 @@ sub check_storage_engines {
50085012sub dump_into_file {
50095013 my $file = shift ;
50105014 my $content = shift ;
5011- if ( defined ($opt {dumpdir }) && $opt {dumpdir } ne ' ' && -d $opt {dumpdir } ) {
5015+ if ( defined ( $opt {dumpdir } ) && $opt {dumpdir } ne ' ' && -d $opt {dumpdir } ) {
50125016 $file = " $opt {dumpdir}/$file " ;
50135017 open ( FILE, " >$file " ) or die " Can't open $file : $! " ;
50145018 print FILE $content ;
@@ -5295,8 +5299,8 @@ sub calculations {
52955299 }
52965300 else {
52975301 if ( ( $mystat {' Uptime' } || 0 ) > 0 ) {
5298- $mycalc {' query_cache_prunes_per_day' } = int (
5299- $mystat {' Qcache_lowmem_prunes' } /
5302+ $mycalc {' query_cache_prunes_per_day' } =
5303+ int ( $mystat {' Qcache_lowmem_prunes' } /
53005304 ( $mystat {' Uptime' } / 86400 ) );
53015305 }
53025306 else {
@@ -5316,7 +5320,7 @@ sub calculations {
53165320 # Joins
53175321 $mycalc {' joins_without_indexes' } =
53185322 ( $mystat {' Select_range_check' } || 0 ) +
5319- ( $mystat {' Select_full_join' } || 0 );
5323+ ( $mystat {' Select_full_join' } || 0 );
53205324 if ( ( $mystat {' Uptime' } || 0 ) > 0 ) {
53215325 $mycalc {' joins_without_indexes_per_day' } = int (
53225326 $mycalc {' joins_without_indexes' } / ( $mystat {' Uptime' } / 86400 ) );
@@ -5382,10 +5386,11 @@ sub calculations {
53825386
53835387 # Thread cache
53845388 if ( ( $mystat {' Connections' } || 0 ) > 0 ) {
5385- $mycalc {' thread_cache_hit_rate' } =
5386- int ( 100 -
5387- ( ( $mystat {' Threads_created' } / $mystat {' Connections' } ) * 100 )
5388- );
5389+ $mycalc {' thread_cache_hit_rate' } = int (
5390+ 100 - (
5391+ ( $mystat {' Threads_created' } / $mystat {' Connections' } ) * 100
5392+ )
5393+ );
53895394 }
53905395 else {
53915396 $mycalc {' thread_cache_hit_rate' } = 100;
@@ -5514,7 +5519,8 @@ sub mysql_stats {
55145519 # Show uptime, queries per second, connections, traffic stats
55155520 my $qps = 0;
55165521 if ( ( $mystat {' Uptime' } || 0 ) > 0 ) {
5517- $qps = sprintf ( " %.3f" , ( $mystat {' Questions' } || 0 ) / $mystat {' Uptime' } );
5522+ $qps =
5523+ sprintf ( " %.3f" , ( $mystat {' Questions' } || 0 ) / $mystat {' Uptime' } );
55185524 }
55195525 push ( @generalrec ,
55205526" MySQL was started within the last 24 hours: recommendations may be inaccurate"
@@ -5612,31 +5618,36 @@ sub mysql_stats {
56125618 badprint
56135619 " Allocating > 2GB RAM on 32-bit systems can cause system instability" ;
56145620 badprint " Maximum reached memory usage: "
5615- . hr_bytes( $mycalc {' max_used_memory' } )
5616- . " (" . ( $mycalc {' pct_max_used_memory' } // 0 ) . " % of installed RAM)" ;
5621+ . hr_bytes( $mycalc {' max_used_memory' } ) . " ("
5622+ . ( $mycalc {' pct_max_used_memory' } // 0 )
5623+ . " % of installed RAM)" ;
56175624 }
56185625 elsif ( ( $mycalc {' pct_max_used_memory' } || 0 ) > 85 ) {
56195626 badprint " Maximum reached memory usage: "
5620- . hr_bytes( $mycalc {' max_used_memory' } )
5621- . " (" . ( $mycalc {' pct_max_used_memory' } // 0 ) . " % of installed RAM)" ;
5627+ . hr_bytes( $mycalc {' max_used_memory' } ) . " ("
5628+ . ( $mycalc {' pct_max_used_memory' } // 0 )
5629+ . " % of installed RAM)" ;
56225630 }
56235631 else {
56245632 goodprint " Maximum reached memory usage: "
5625- . hr_bytes( $mycalc {' max_used_memory' } )
5626- . " (" . ( $mycalc {' pct_max_used_memory' } // 0 ) . " % of installed RAM)" ;
5633+ . hr_bytes( $mycalc {' max_used_memory' } ) . " ("
5634+ . ( $mycalc {' pct_max_used_memory' } // 0 )
5635+ . " % of installed RAM)" ;
56275636 }
56285637
56295638 if ( ( $mycalc {' pct_max_physical_memory' } || 0 ) > 85 ) {
56305639 badprint " Maximum possible memory usage: "
5631- . hr_bytes( $mycalc {' max_peak_memory' } )
5632- . " (" . ( $mycalc {' pct_max_physical_memory' } // 0 ) . " % of installed RAM)" ;
5640+ . hr_bytes( $mycalc {' max_peak_memory' } ) . " ("
5641+ . ( $mycalc {' pct_max_physical_memory' } // 0 )
5642+ . " % of installed RAM)" ;
56335643 push ( @generalrec ,
56345644 " Reduce your overall MySQL memory footprint for system stability" );
56355645 }
56365646 else {
56375647 goodprint " Maximum possible memory usage: "
5638- . hr_bytes( $mycalc {' max_peak_memory' } )
5639- . " (" . ( $mycalc {' pct_max_physical_memory' } // 0 ) . " % of installed RAM)" ;
5648+ . hr_bytes( $mycalc {' max_peak_memory' } ) . " ("
5649+ . ( $mycalc {' pct_max_physical_memory' } // 0 )
5650+ . " % of installed RAM)" ;
56405651 }
56415652
56425653 if ( ( $physical_memory || 0 ) <
@@ -5685,32 +5696,42 @@ sub mysql_stats {
56855696
56865697 # Connections
56875698 if ( ( $mycalc {' pct_connections_used' } || 0 ) > 85 ) {
5688- badprint
5689- " Highest connection usage: " . ( $mycalc {' pct_connections_used' } // 0 ) . " % (" . ( $mystat {' Max_used_connections' } // 0 ) . " /" . ( $myvar {' max_connections' } // 0 ) . " )" ;
5699+ badprint " Highest connection usage: "
5700+ . ( $mycalc {' pct_connections_used' } // 0 ) . " % ("
5701+ . ( $mystat {' Max_used_connections' } // 0 ) . " /"
5702+ . ( $myvar {' max_connections' } // 0 ) . " )" ;
56905703 push ( @adjvars ,
56915704 " max_connections (> " . ( $myvar {' max_connections' } // 0 ) . " )" );
56925705 push ( @adjvars ,
56935706 " wait_timeout (< " . ( $myvar {' wait_timeout' } // 0 ) . " )" ,
5694- " interactive_timeout (< " . ( $myvar {' interactive_timeout' } // 0 ) . " )" );
5707+ " interactive_timeout (< "
5708+ . ( $myvar {' interactive_timeout' } // 0 )
5709+ . " )" );
56955710 push ( @generalrec ,
56965711" Reduce or eliminate persistent connections to reduce connection usage"
56975712 );
56985713 }
56995714 else {
5700- goodprint
5701- " Highest usage of available connections: " . ( $mycalc {' pct_connections_used' } // 0 ) . " % (" . ( $mystat {' Max_used_connections' } // 0 ) . " /" . ( $myvar {' max_connections' } // 0 ) . " )" ;
5715+ goodprint " Highest usage of available connections: "
5716+ . ( $mycalc {' pct_connections_used' } // 0 ) . " % ("
5717+ . ( $mystat {' Max_used_connections' } // 0 ) . " /"
5718+ . ( $myvar {' max_connections' } // 0 ) . " )" ;
57025719 }
57035720
57045721 # Aborted Connections
57055722 if ( ( $mycalc {' pct_connections_aborted' } || 0 ) > 3 ) {
5706- badprint
5707- " Aborted connections: " . ( $mycalc {' pct_connections_aborted' } // 0 ) . " % (" . ( $mystat {' Aborted_connects' } // 0 ) . " /" . ( $mystat {' Connections' } // 0 ) . " )" ;
5723+ badprint " Aborted connections: "
5724+ . ( $mycalc {' pct_connections_aborted' } // 0 ) . " % ("
5725+ . ( $mystat {' Aborted_connects' } // 0 ) . " /"
5726+ . ( $mystat {' Connections' } // 0 ) . " )" ;
57085727 push ( @generalrec ,
57095728 " Reduce or eliminate unclosed connections and network issues" );
57105729 }
57115730 else {
5712- goodprint
5713- " Aborted connections: " . ( $mycalc {' pct_connections_aborted' } // 0 ) . " % (" . ( $mystat {' Aborted_connects' } // 0 ) . " /" . ( $mystat {' Connections' } // 0 ) . " )" ;
5731+ goodprint " Aborted connections: "
5732+ . ( $mycalc {' pct_connections_aborted' } // 0 ) . " % ("
5733+ . ( $mystat {' Aborted_connects' } // 0 ) . " /"
5734+ . ( $mystat {' Connections' } // 0 ) . " )" ;
57145735 }
57155736
57165737 # name resolution
@@ -5863,7 +5884,8 @@ sub mysql_stats {
58635884 . " , or always use indexes with JOINs)" );
58645885 }
58655886 else {
5866- push ( @adjvars , " join_buffer_size (always use indexes with JOINs)" );
5887+ push ( @adjvars ,
5888+ " join_buffer_size (always use indexes with JOINs)" );
58675889 }
58685890 push (
58695891 @generalrec ,
@@ -6020,7 +6042,7 @@ sub mysql_stats {
60206042 badprint
60216043" table_open_cache_instances is set to $myvar {'table_open_cache_instances'} but $recommended_instances is recommended based on CPU cores." ;
60226044 push ( @adjvars ,
6023- " table_open_cache_instances (=$recommended_instances )"
6045+ " table_open_cache_instances (=$recommended_instances )"
60246046 );
60256047 }
60266048 }
@@ -8401,8 +8423,9 @@ sub mysql_80_modeling_checks {
84018423 return unless mysql_version_ge( 8, 0 );
84028424
84038425 my $is_mariadb = (
8404- ( defined $myvar {' version' } && $myvar {' version' } =~ / MariaDB/i )
8405- or ( defined $myvar {' version_comment' } && $myvar {' version_comment' } =~ / MariaDB/i )
8426+ ( defined $myvar {' version' } && $myvar {' version' } =~ / MariaDB/i )
8427+ or ( defined $myvar {' version_comment' }
8428+ && $myvar {' version_comment' } =~ / MariaDB/i )
84068429 );
84078430 my $header =
84088431 $is_mariadb
@@ -8782,7 +8805,7 @@ sub mariadb_galera {
87828805 badprint
87838806 " innodb_autoinc_lock_mode is incorrect with parallel replica" ;
87848807 push @adjvars ,
8785- " innodb_autoinc_lock_mode should be 2 when using parallel replica" ;
8808+ " innodb_autoinc_lock_mode should be 2 when using parallel replica" ;
87868809 }
87878810 }
87888811
@@ -9193,21 +9216,26 @@ sub mysql_innodb {
91939216 infoprint " InnoDB Redo Log Capacity is set to "
91949217 . hr_bytes( $myvar {' innodb_redo_log_capacity' } );
91959218
9196- if ( defined $myvar {' innodb_dedicated_server' }
9219+ if ( defined $myvar {' innodb_dedicated_server' }
91979220 and $myvar {' innodb_dedicated_server' } eq ' ON' )
91989221 {
91999222 goodprint
92009223" innodb_dedicated_server is ON. MySQL is managing Redo Log Capacity automatically." ;
9201- if ( defined $opt {' defaults-file' } || defined $opt {' defaults-extra-file' } ) {
9202- infoprint " If innodb_redo_log_capacity is manually set in config, consider removing it." ;
9224+ if ( defined $opt {' defaults-file' }
9225+ || defined $opt {' defaults-extra-file' } )
9226+ {
9227+ infoprint
9228+ " If innodb_redo_log_capacity is manually set in config, consider removing it." ;
92039229 }
92049230 }
92059231 else {
9206- my $innodb_os_log_written = $mystat {' Innodb_os_log_written' } || 0;
9207- my $uptime = $mystat {' Uptime' } || 1;
9232+ my $innodb_os_log_written =
9233+ $mystat {' Innodb_os_log_written' } || 0;
9234+ my $uptime = $mystat {' Uptime' } || 1;
92089235
92099236 if ( $uptime > 3600 ) {
9210- my $hourly_rate = $innodb_os_log_written / ( $uptime / 3600 );
9237+ my $hourly_rate =
9238+ $innodb_os_log_written / ( $uptime / 3600 );
92119239 infoprint " Hourly InnoDB log write rate: "
92129240 . hr_bytes($hourly_rate ) . " /hour" ;
92139241
@@ -9219,35 +9247,45 @@ sub mysql_innodb {
92199247 if ( $physical_memory > 8 * 1024 * 1024 * 1024 ) {
92209248 $min_bytes = 1 * 1024 * 1024 * 1024;
92219249 }
9222- $recommended_bytes = $min_bytes if $recommended_bytes < $min_bytes ;
9250+ $recommended_bytes = $min_bytes
9251+ if $recommended_bytes < $min_bytes ;
92239252
92249253 # Cap at 16GB
92259254 my $max_bytes = 16 * 1024 * 1024 * 1024;
9226- $recommended_bytes = $max_bytes if $recommended_bytes > $max_bytes ;
9255+ $recommended_bytes = $max_bytes
9256+ if $recommended_bytes > $max_bytes ;
92279257
92289258 # Rounding
92299259 if ( $recommended_bytes < 1024 * 1024 * 1024 ) {
92309260 $recommended_bytes =
9231- POSIX::ceil( $recommended_bytes / ( 100 * 1024 * 1024 ) )
9232- * ( 100 * 1024 * 1024 );
9261+ POSIX::ceil(
9262+ $recommended_bytes / ( 100 * 1024 * 1024 ) ) *
9263+ ( 100 * 1024 * 1024 );
92339264 }
92349265 else {
92359266 $recommended_bytes =
9236- POSIX::ceil( $recommended_bytes / ( 1024 * 1024 * 1024 ) )
9237- * ( 1024 * 1024 * 1024 );
9267+ POSIX::ceil(
9268+ $recommended_bytes / ( 1024 * 1024 * 1024 ) ) *
9269+ ( 1024 * 1024 * 1024 );
92389270 }
92399271
92409272 my $recommended_str = hr_bytes($recommended_bytes );
9241- if ( $myvar {' innodb_redo_log_capacity' } < $recommended_bytes * 0.9 ) {
9242- badprint " Your innodb_redo_log_capacity is smaller than the recommended $recommended_str based on your workload." ;
9243- push @adjvars , " innodb_redo_log_capacity (>= $recommended_str )" ;
9273+ if ( $myvar {' innodb_redo_log_capacity' } <
9274+ $recommended_bytes * 0.9 )
9275+ {
9276+ badprint
9277+ " Your innodb_redo_log_capacity is smaller than the recommended $recommended_str based on your workload." ;
9278+ push @adjvars ,
9279+ " innodb_redo_log_capacity (>= $recommended_str )" ;
92449280 }
92459281 else {
9246- goodprint " Your innodb_redo_log_capacity is sized correctly for your workload ($recommended_str recommended)." ;
9282+ goodprint
9283+ " Your innodb_redo_log_capacity is sized correctly for your workload ($recommended_str recommended)." ;
92479284 }
92489285 }
92499286 else {
9250- infoprint " Server uptime is less than 1 hour. Cannot make a reliable recommendation for innodb_redo_log_capacity." ;
9287+ infoprint
9288+ " Server uptime is less than 1 hour. Cannot make a reliable recommendation for innodb_redo_log_capacity." ;
92519289 }
92529290 }
92539291 }
0 commit comments