Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend slow queries logging when not enabled #517

Open
8ctopus opened this issue Dec 9, 2020 · 1 comment
Open

Recommend slow queries logging when not enabled #517

8ctopus opened this issue Dec 9, 2020 · 1 comment

Comments

@8ctopus
Copy link

8ctopus commented Dec 9, 2020

Thanks for a great script! Here's a little suggestion that will benefit beginners:

Add a general recommendation to log slow queries.
Here's the tuner's output on my server that has no logging for slow queries as well as the recommendations found in phpMyAdmin which recommends logging slow queries.

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA
[--] Data in MyISAM tables: 2.6G (Tables: 360)
[--] Data in InnoDB tables: 2.0G (Tables: 585)
[OK] Total fragmented tables: 0

-------- Analysis Performance Metrics --------------------------------------------------------------
[--] innodb_stats_on_metadata: OFF
[OK] No stat updates during querying INFORMATION_SCHEMA.

-------- Security Recommendations ------------------------------------------------------------------
[OK] There are no anonymous accounts for any database users
[OK] All database users have passwords assigned
[--] Bug #80860 MySQL 5.7: Avoid testing password when validate_password is activated

-------- CVE Security Recommendations --------------------------------------------------------------
[OK] NO SECURITY CVE FOUND FOR YOUR VERSION

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 14d 9h 15m 57s (6M q [5.114 qps], 939K conn, TX: 17G, RX: 2G)
[--] Reads / Writes: 50% / 50%
[--] Binary logging is enabled (GTID MODE: OFF)
[--] Physical Memory     : 3.7G
[--] Max MySQL memory    : 942.9M
[--] Other process memory: 0B
[--] Total buffers: 169.0M global + 5.1M per thread (151 max threads)
[--] P_S Max memory usage: 72B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 230.5M (6.09% of installed RAM)
[OK] Maximum possible memory usage: 942.9M (24.89% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 0% (0/6M)
[OK] Highest usage of available connections: 7% (12/151)
[OK] Aborted connections: 0.00%  (2/939846)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
[!!] Query cache may be disabled by default due to mutex contention.
[!!] Query cache efficiency: 0.0% (0 cached / 2M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 221K sorts)
[OK] No joins without indexes
[!!] Temporary tables created on disk: 73% (27K on disk / 37K total)
[OK] Thread cache hit rate: 99% (15 created / 939K connections)
[!!] Table cache hit rate: 4% (2K open / 41K opened)
[OK] table_definition_cache(1400) is upper than number of tables(1231)
[OK] Open file limit used: 20% (1K/5K)
[OK] Table locks acquired immediately: 99% (517K immediate / 517K locks)
[OK] Binlog cache memory access: 100.00% (1112758 Memory / 1112758 Total)

-------- Performance schema ------------------------------------------------------------------------
[--] Memory used by P_S: 72B
[--] Sys schema is installed.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is disabled.

-------- MyISAM Metrics ----------------------------------------------------------------------------
[OK] Key buffer used: 100.0% (8M used / 8M cache)
[!!] Key buffer size / total MyISAM indexes: 8.0M/352.0M
[!!] Read Key buffer hit rate: 83.6% (2B cached / 456M reads)
[!!] Write Key buffer hit rate: 89.1% (443K cached / 395K writes)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[!!] InnoDB buffer pool / data size: 128.0M/2.0G
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (75 %): 48.0M * 2/128.0M should be equal to 25%
[OK] InnoDB buffer pool instances: 1
[--] Number of InnoDB Buffer Pool Chunk : 1 for 1 Buffer Pool Instance(s)
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances
[OK] InnoDB Read buffer efficiency: 99.83% (314424103 hits/ 314960247 total)
[!!] InnoDB Write Log efficiency: 22.47% (1004951 hits/ 4471522 total)
[OK] InnoDB log waits: 0.00% (0 waits / 3466571 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is disabled.

-------- TokuDB Metrics ----------------------------------------------------------------------------
[--] TokuDB is disabled.

-------- XtraDB Metrics ----------------------------------------------------------------------------
[--] XtraDB is disabled.

-------- Galera Metrics ----------------------------------------------------------------------------
[--] Galera is disabled.

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] This server is acting as master for 1 server(s).
[--] Binlog format: MIXED
[--] XA support enabled: ON
[--] Semi synchronous replication Master: Not Activated
[--] Semi synchronous replication Slave: Not Activated
[!!] This replication slave is running with the read_only option disabled.
[OK] This replication slave is up to date with master.

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    Control warning line(s) into /var/log/mysqld.log file
    Control error line(s) into /var/log/mysqld.log file
    Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
    When making adjustments, make tmp_table_size/max_heap_table_size equal
    Reduce your SELECT DISTINCT queries which have no LIMIT clause
    Increase table_open_cache gradually to avoid file descriptor limits
    Read this before increasing table_open_cache over 64: https://bit.ly/2Fulv7r
    Read this before increasing for MariaDB https://mariadb.com/kb/en/library/optimizing-table_open_cache/
    This is MyISAM only table_cache scalability problem, InnoDB not affected.
    See more details here: https://bugs.mysql.com/bug.php?id=49177
    This bug already fixed in MySQL 5.7.9 and newer MySQL versions.
    Beware that open_files_limit (5000) variable
    should be greater than table_open_cache (2000)
    Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: https://bit.ly/2TcGgtU
Variables to adjust:
    query_cache_size (=0)
    query_cache_type (=0)
    query_cache_limit (> 1M, or use smaller result sets)
    tmp_table_size (> 16M)
    max_heap_table_size (> 16M)
    table_open_cache (> 2000)
    key_buffer_size (> 352.0M)
    innodb_buffer_pool_size (>= 2.0G) if possible.
    innodb_log_file_size should be (=16M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.

2020-12-09_110018

@grooverdan
Copy link
Contributor

In addition to the slow query log, I like the phpmyadmin suggestions here around adding indexes based on {handler_read,select,rows}_* system status variables which could be grouped under the same heading. These are a little hard to get right with a high level of accuracy, however its a good indication for the user that you just can't magicly tune your way out of every database problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants