Skip to content

Commit 21860fe

Browse files
committed
Incorrect suggestion for ratio InnoDB log file size / InnoDB buffer pool size #322
1 parent f180eae commit 21860fe

File tree

1 file changed

+49
-76
lines changed

1 file changed

+49
-76
lines changed

mysqltuner.pl

+49-76
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,9 @@ sub infoprinthcmd {
300300
infoprintcmd "$_[1]";
301301
}
302302

303-
# Calculates the number of phyiscal cores considering HyperThreading
303+
# Calculates the number of phyiscal cores considering HyperThreading
304304
sub cpu_cores {
305-
my $cntCPU =
306-
`awk -F: '/^core id/ && !P[\$2] { CORES++; P[\$2]=1 }; /^physical id/ && !N[\$2] { CPUs++; N[\$2]=1 }; END { print CPUs*CORES }' /proc/cpuinfo`;
305+
my $cntCPU = `awk -F: '/^core id/ && !P[\$2] { CORES++; P[\$2]=1 }; /^physical id/ && !N[\$2] { CPUs++; N[\$2]=1 }; END { print CPUs*CORES }' /proc/cpuinfo`;
307306
return ( $cntCPU == 0 ? `nproc` : $cntCPU );
308307
}
309308

@@ -538,8 +537,7 @@ sub validate_tuner_version {
538537
}
539538

540539
my $update;
541-
my $url =
542-
"https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl";
540+
my $url = "https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl";
543541
my $httpcli = get_http_cli();
544542
if ( $httpcli =~ /curl$/ ) {
545543
debugprint "$httpcli is available.";
@@ -614,9 +612,9 @@ sub update_tuner_version {
614612
debugprint "$httpcli is available.";
615613

616614
debugprint
617-
"$httpcli -qe timestamping=off -t 1 -T 3 -O $script '$url$script'";
615+
"$httpcli -qe timestamping=off -t 1 -T 3 -O $script '$url$script'";
618616
$update =
619-
`$httpcli -qe timestamping=off -t 1 -T 3 -O $script '$url$script'`;
617+
`$httpcli -qe timestamping=off -t 1 -T 3 -O $script '$url$script'`;
620618
chomp($update);
621619

622620
if ( -s $script eq 0 ) {
@@ -723,7 +721,7 @@ sub mysql_setup {
723721
if ( $opt{socket} ne 0 ) {
724722
$remotestring = " -S $opt{socket} -P $opt{port}";
725723
}
726-
724+
727725
# Are we being asked to connect to a remote server?
728726
if ( $opt{host} ne 0 ) {
729727
chomp( $opt{host} );
@@ -741,9 +739,8 @@ sub mysql_setup {
741739
if ( ( $opt{host} ne "127.0.0.1" ) && ( $opt{host} ne "localhost" ) ) {
742740
$doremote = 1;
743741
}
744-
}
745-
else {
746-
$opt{host} = '127.0.0.1';
742+
} else {
743+
$opt{host}='127.0.0.1';
747744
}
748745

749746
# Did we already get a username without password on the command line?
@@ -872,7 +869,6 @@ sub mysql_setup {
872869
}
873870
}
874871
else {
875-
876872
# It's not Plesk or debian, we should try a login
877873
debugprint "$mysqladmincmd $remotestring ping 2>&1";
878874
my $loginstatus = `$mysqladmincmd $remotestring ping 2>&1`;
@@ -1471,8 +1467,7 @@ sub get_kernel_info {
14711467
badprint
14721468
"Swappiness is > 10, please consider having a value lower than 10";
14731469
push @generalrec, "setup swappiness lower or equals to 10";
1474-
push @adjvars,
1475-
'vm.swappiness <= 10 (echo 10 > /proc/sys/vm/swappiness)';
1470+
push @adjvars, 'vm.swappiness <= 10 (echo 10 > /proc/sys/vm/swappiness)';
14761471
}
14771472
else {
14781473
infoprint "Swappiness is < 10.";
@@ -1827,7 +1822,7 @@ sub get_replication_status {
18271822
"This replication slave is not running but seems to be configured.";
18281823
}
18291824
if ( defined($io_running)
1830-
&& $io_running =~ /yes/i
1825+
&& $io_running =~ /yes/i
18311826
&& $sql_running =~ /yes/i )
18321827
{
18331828
if ( $myvar{'read_only'} eq 'OFF' ) {
@@ -2093,7 +2088,7 @@ sub check_storage_engines {
20932088
debugprint "Data dump " . Dumper(@$tbl);
20942089
my ( $engine, $size, $datafree ) = @$tbl;
20952090
next if $engine eq 'NULL';
2096-
$size = 0 if $size eq 'NULL';
2091+
$size = 0 if $size eq 'NULL';
20972092
$datafree = 0 if $datafree eq 'NULL';
20982093
if ( defined $enginestats{$engine} ) {
20992094
$enginestats{$engine} += $size;
@@ -2330,7 +2325,7 @@ sub calculations {
23302325
$myvar{'key_cache_block_size'}
23312326
) / $myvar{'key_buffer_size'}
23322327
)
2333-
) * 100
2328+
) * 100
23342329
);
23352330
}
23362331
else {
@@ -2371,9 +2366,8 @@ sub calculations {
23712366
}
23722367

23732368
if ( $mystat{'Key_write_requests'} > 0 ) {
2374-
$mycalc{'pct_wkeys_from_mem'} = sprintf( "%.1f",
2375-
( ( $mystat{'Key_writes'} / $mystat{'Key_write_requests'} ) * 100 )
2376-
);
2369+
$mycalc{'pct_wkeys_from_mem'} = sprintf(
2370+
"%.1f",( ($mystat{'Key_writes'} / $mystat{'Key_write_requests'} ) * 100 ) );
23772371
}
23782372
else {
23792373
$mycalc{'pct_wkeys_from_mem'} = 0;
@@ -2417,14 +2411,14 @@ sub calculations {
24172411
(
24182412
$mystat{'Qcache_hits'} /
24192413
( $mystat{'Com_select'} + $mystat{'Qcache_hits'} )
2420-
) * 100
2414+
) * 100
24212415
);
24222416
if ( $myvar{'query_cache_size'} ) {
24232417
$mycalc{'pct_query_cache_used'} = sprintf(
24242418
"%.1f",
24252419
100 - (
24262420
$mystat{'Qcache_free_memory'} / $myvar{'query_cache_size'}
2427-
) * 100
2421+
) * 100
24282422
);
24292423
}
24302424
if ( $mystat{'Qcache_lowmem_prunes'} == 0 ) {
@@ -2649,7 +2643,7 @@ sub mysql_stats {
26492643

26502644
if ( defined $myvar{'query_cache_type'} ) {
26512645
infoprint "Query Cache Buffers";
2652-
infoprint " +-- Query Cache: "
2646+
infoprint " +-- Query Cache: "
26532647
. $myvar{'query_cache_type'} . " - "
26542648
. (
26552649
$myvar{'query_cache_type'} eq 0 |
@@ -3152,7 +3146,6 @@ sub mysql_myisam {
31523146
}
31533147
}
31543148
else {
3155-
31563149
# No queries have run that would use keys
31573150
debugprint "Key buffer used: $mycalc{'pct_key_buffer_used'}% ("
31583151
. hr_num(
@@ -3212,7 +3205,6 @@ sub mysql_myisam {
32123205
}
32133206
}
32143207
else {
3215-
32163208
# No queries have run that would use keys
32173209
debugprint "Key buffer size / total MyISAM indexes: "
32183210
. hr_bytes( $myvar{'key_buffer_size'} ) . "/"
@@ -3237,7 +3229,6 @@ sub mysql_myisam {
32373229
}
32383230
}
32393231
else {
3240-
32413232
# No queries have run that would use keys
32423233
debugprint
32433234
"Write Key buffer hit rate: $mycalc{'pct_wkeys_from_mem'}% ("
@@ -5048,11 +5039,11 @@ sub mariadb_galera {
50485039
having sum(if(c.column_key in ('PRI','UNI'), 1,0)) = 0"
50495040
);
50505041

5051-
if ( get_wsrep_option('wsrep_slave_threads') > cpu_cores *4
5052-
or get_wsrep_option('wsrep_slave_threads') < cpu_cores *3 )
5042+
if ( get_wsrep_option('wsrep_slave_threads') > cpu_cores * 4
5043+
or get_wsrep_option('wsrep_slave_threads') < cpu_cores * 3 )
50535044
{
50545045
badprint
5055-
"wsrep_slave_threads is not equal to 2, 3 or 4 times number of CPU(s)";
5046+
"wsrep_slave_threads is not equal to 2, 3 or 4 times number of CPU(s)";
50565047
push @adjvars, "wsrep_slave_threads= Nb of Core CPU * 4";
50575048
}
50585049
else {
@@ -5065,55 +5056,43 @@ sub mariadb_galera {
50655056
{
50665057
badprint "gcs.limit should be equal to 5 * wsrep_slave_threads";
50675058
push @adjvars, "gcs.limit= wsrep_slave_threads * 5";
5068-
}
5069-
else {
5059+
} else {
50705060
goodprint "gcs.limit should be equal to 5 * wsrep_slave_threads";
50715061
}
50725062

5073-
if ( get_wsrep_option('wsrep_slave_threads') > 1 ) {
5074-
infoprint
5075-
"wsrep parallel slave can cause frequent inconsistency crash.";
5076-
push @adjvars,
5077-
"Set wsrep_slave_threads to 1 in case of HA_ERR_FOUND_DUPP_KEY crash on slave";
5078-
5063+
if (get_wsrep_option('wsrep_slave_threads') > 1) {
5064+
infoprint "wsrep parallel slave can cause frequent inconsistency crash.";
5065+
push @adjvars, "Set wsrep_slave_threads to 1 in case of HA_ERR_FOUND_DUPP_KEY crash on slave";
50795066
# check options for parallel slave
5080-
if ( get_wsrep_option('wsrep_slave_FK_checks') eq "OFF" ) {
5067+
if (get_wsrep_option('wsrep_slave_FK_checks') eq "OFF") {
50815068
badprint "wsrep_slave_FK_checks is off with parallel slave";
5082-
push @adjvars,
5083-
"wsrep_slave_FK_checks should be ON when using parallel slave";
5069+
push @adjvars, "wsrep_slave_FK_checks should be ON when using parallel slave";
50845070
}
5085-
50865071
# wsrep_slave_UK_checks seems useless in MySQL source code
5087-
if ( $myvar{'innodb_autoinc_lock_mode'} != 2 ) {
5088-
badprint
5089-
"innodb_autoinc_lock_mode is incorrect with parallel slave";
5090-
push @adjvars,
5091-
"innodb_autoinc_lock_mode should be 2 when using parallel slave";
5072+
if ($myvar{'innodb_autoinc_lock_mode'} != 2) {
5073+
badprint "innodb_autoinc_lock_mode is incorrect with parallel slave";
5074+
push @adjvars, "innodb_autoinc_lock_mode should be 2 when using parallel slave";
50925075
}
50935076
}
5094-
5095-
if ( get_wsrep_option('gcs.fc_limit') != $myvar{'wsrep_slave_threads'} * 5 )
5096-
{
5077+
5078+
if (get_wsrep_option('gcs.fc_limit') != $myvar{'wsrep_slave_threads'} * 5 ) {
50975079
badprint "gcs.fc_limit should be equal to 5 * wsrep_slave_threads";
50985080
push @adjvars, "gcs.fc_limit= wsrep_slave_threads * 5";
5099-
}
5100-
else {
5081+
} else {
51015082
goodprint "gcs.fc_limit is equal to 5 * wsrep_slave_threads";
51025083
}
5103-
5104-
if ( get_wsrep_option('gcs.fc_factor') != 0.8 ) {
5084+
5085+
if (get_wsrep_option('gcs.fc_factor') != 0.8 ) {
51055086
badprint "gcs.fc_factor should be equal to 0.8";
51065087
push @adjvars, "gcs.fc_factor=0.8";
51075088
}
51085089
else {
51095090
goodprint "gcs.fc_factor is equal to 0.8";
51105091
}
5111-
if ( get_wsrep_option('wsrep_flow_control_paused') > 0.02 ) {
5092+
if ( get_wsrep_option('wsrep_flow_control_paused') > 0.02 ) {
51125093
badprint "Fraction of time node pause flow control > 0.02";
5113-
}
5114-
else {
5115-
goodprint
5116-
"Flow control fraction seems to be OK (wsrep_flow_control_paused<=0.02)";
5094+
} else {
5095+
goodprint "Flow control fraction seems to be OK (wsrep_flow_control_paused<=0.02)";
51175096
}
51185097

51195098
if ( scalar(@primaryKeysNbTables) > 0 ) {
@@ -5122,8 +5101,7 @@ sub mariadb_galera {
51225101
badprint "\t$badtable";
51235102
push @{ $result{'Tables without PK'} }, $badtable;
51245103
}
5125-
}
5126-
else {
5104+
} else {
51275105
goodprint "All tables get a primary key";
51285106
}
51295107
my @nonInnoDBTables = select_array(
@@ -5136,22 +5114,19 @@ sub mariadb_galera {
51365114
foreach my $badtable (@nonInnoDBTables) {
51375115
badprint "\t$badtable";
51385116
}
5139-
}
5140-
else {
5117+
} else {
51415118
goodprint "All tables are InnoDB tables";
51425119
}
51435120
if ( $myvar{'binlog_format'} ne 'ROW' ) {
51445121
badprint "Binlog format should be in ROW mode.";
51455122
push @adjvars, "binlog_format = ROW";
5146-
}
5147-
else {
5123+
} else {
51485124
goodprint "Binlog format is in ROW mode.";
51495125
}
51505126
if ( $myvar{'innodb_flush_log_at_trx_commit'} != 0 ) {
51515127
badprint "InnoDB flush log at each commit should be disabled.";
51525128
push @adjvars, "innodb_flush_log_at_trx_commit = 0";
5153-
}
5154-
else {
5129+
} else {
51555130
goodprint "InnoDB flush log at each commit is disabled for Galera.";
51565131
}
51575132

@@ -5417,7 +5392,7 @@ sub mysql_innodb {
54175392
. " should be equal 25%";
54185393
push(
54195394
@adjvars,
5420-
"innodb_log_file_size * innodb_log_files_in_group should be equals to 1/4 of buffer pool size (="
5395+
"innodb_log_file_size * innodb_log_files_in_group should be equal to 1/4 of buffer pool size (="
54215396
. hr_bytes_rnd(
54225397
$myvar{'innodb_buffer_pool_size'} *
54235398
$myvar{'innodb_log_files_in_group'} / 4
@@ -5840,13 +5815,13 @@ sub mysql_indexes {
58405815
infoprint " +-- TYPE : " . $info[6];
58415816
infoprint " +-- SELECTIVITY : " . $info[7] . "%";
58425817

5843-
$result{'Indexes'}{ $info[1] }{'Column'} = $info[0];
5844-
$result{'Indexes'}{ $info[1] }{'Sequence number'} = $info[2];
5845-
$result{'Indexes'}{ $info[1] }{'Number of column'} = $info[3];
5846-
$result{'Indexes'}{ $info[1] }{'Cardinality'} = $info[4];
5847-
$result{'Indexes'}{ $info[1] }{'Row number'} = $info[5];
5848-
$result{'Indexes'}{ $info[1] }{'Index Type'} = $info[6];
5849-
$result{'Indexes'}{ $info[1] }{'Selectivity'} = $info[7];
5818+
$result{'Indexes'}{ $info[1] }{'Column'} = $info[0];
5819+
$result{'Indexes'}{ $info[1] }{'Sequence number'} = $info[2];
5820+
$result{'Indexes'}{ $info[1] }{'Number of column'} = $info[3];
5821+
$result{'Indexes'}{ $info[1] }{'Cardinality'} = $info[4];
5822+
$result{'Indexes'}{ $info[1] }{'Row number'} = $info[5];
5823+
$result{'Indexes'}{ $info[1] }{'Index Type'} = $info[6];
5824+
$result{'Indexes'}{ $info[1] }{'Selectivity'} = $info[7];
58505825
if ( $info[7] < 25 ) {
58515826
badprint "$info[1] has a low selectivity";
58525827
}
@@ -5942,7 +5917,6 @@ sub file2string {
59425917
$templateModel = file2string( $opt{'template'} );
59435918
}
59445919
else {
5945-
59465920
# DEFAULT REPORT TEMPLATE
59475921
$templateModel = <<'END_TEMPLATE';
59485922
<!DOCTYPE html>
@@ -6063,7 +6037,6 @@ sub which {
60636037
1;
60646038

60656039
__END__
6066-
60676040
=pod
60686041
60696042
=encoding UTF-8

0 commit comments

Comments
 (0)