mysqld 性能高 CPU 和内存使用率

标签 mysql mysqltuner

如果您能帮助解决如下所示的 mysqld 性能问题,我将不胜感激。顶部显示 2 个 mysqld,CPU 使用率为 99%,内存使用率为 73%。

我总共有 6 个 CPU 和 8GB RAM。您可以轻松查看最近24小时内CPU的性能。

我也发送 mysql 调谐器的输出。

CPU usage 24h

top output

--> mysqltuner 输出:

[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 10.1.24-MariaDB
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[--] Log file: (0B)
[!!] Log file  doesn't exist
[!!] Log file  isn't readable.

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +Aria +CSV +InnoDB +MEMORY +MRG_MyISAM +MyISAM +PERFORMANCE_SCHEMA +SEQUENCE
[--] Data in InnoDB tables: 15G (Tables: 121)
[--] Data in MEMORY tables: 0B (Tables: 2)
[OK] Total fragmented tables: 0

-------- Security Recommendations ------------------------------------------------------------------
[OK] There are no anonymous accounts for any database users
[OK] All database users have passwords assigned
[!!] User 'kepmark_readonly@%' hasn't specific host restriction.
[!!] User 'kpm_zeus_fsm@%' hasn't specific host restriction.
[!!] User 'root@%' hasn't specific host restriction.
[--] There are 612 basic passwords in the list.

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

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 11d 19h 19m 33s (37M q [36.944 qps], 3M conn, TX: 30G, RX: 3G)
[--] Reads / Writes: 50% / 50%
[--] Binary logging is disabled
[--] Physical Memory     : 11.7G
[--] Max MySQL memory    : 8.7G
[--] Other process memory: 702.6M
[--] Total buffers: 8.3G global + 2.9M per thread (151 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 8.5G (72.61% of installed RAM)
[OK] Maximum possible memory usage: 8.7G (74.32% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 0% (18K/37M)
[OK] Highest usage of available connections: 52% (80/151)
[OK] Aborted connections: 0.35%  (10593/3009097)
[!!] Query cache may be disabled by default due to mutex contention.
[!!] Query cache efficiency: 0.0% (0 cached / 16M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (165 temp sorts / 34K sorts)
[OK] No joins without indexes
[OK] Temporary tables created on disk: 0% (1K on disk / 4M total)
[!!] Thread cache is disabled
[!!] Table cache hit rate: 11% (398 open / 3K opened)
[OK] Open file limit used: 0% (66/16K)
[OK] Table locks acquired immediately: 99% (41M immediate / 41M locks)

-------- Performance schema ------------------------------------------------------------------------
[--] Performance schema is disabled.
[--] Memory used by P_S: 0B
[--] Sys schema isn't installed.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is enabled.
[--] Thread Pool Size: 6 thread(s).
[--] Using default value is good enough for your version (10.1.24-MariaDB)

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 18.2% (24M used / 134M cache)
[OK] Key buffer size / total MyISAM indexes: 128.0M/126.0K
[OK] Read Key buffer hit rate: 100.0% (709K cached / 50 reads)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[!!] InnoDB buffer pool / data size: 8.0G/15.2G
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (1.171875 %): 48.0M * 2/8.0G should be equal 25%
[!!] InnoDB buffer pool instances: 6
[--] InnoDB Buffer Pool Chunk Size not used or defined in your version
[OK] InnoDB Read buffer efficiency: 100.00% (299698901815 hits/ 299706339317 total)
[!!] InnoDB Write Log efficiency: 22.18% (1601644 hits/ 7221004 total)
[OK] InnoDB log waits: 0.00% (0 waits / 5619360 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is enabled.
[OK] Aria pagecache size / total Aria indexes: 128.0M/1B
[!!] Aria pagecache hit rate: 75.8% (4K cached / 1K reads)

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

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

-------- RocksDB Metrics ---------------------------------------------------------------------------
[--] RocksDB is disabled.

-------- Spider Metrics ----------------------------------------------------------------------------
[--] Spider is disabled.

-------- Connect Metrics ---------------------------------------------------------------------------
[--] Connect is disabled.

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

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] This is a standalone server.

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    Restrict Host for user@% to user@SpecificDNSorIp
    Set thread_cache_size to 4 as a starting value
    Increase table_open_cache gradually to avoid file descriptor limits
    Read this before increasing table_open_cache over 64: 
    Beware that open_files_limit (16364) variable
    should be greater than table_open_cache (2000)
    Performance should be activated for better diagnostics
    Consider installing Sys schema from https://github.com/mysql/mysql-sys
Variables to adjust:
    query_cache_size (=0)
    query_cache_type (=0)
    query_cache_limit (> 4M, or use smaller result sets)
    thread_cache_size (start at 4)
    table_open_cache (> 2000)
    performance_schema = ON enable PFS
    innodb_buffer_pool_size (>= 15G) if possible.
    innodb_log_file_size * innodb_log_files_in_group should be equal to 1/4 of buffer pool size (=4G) if possible.
    innodb_buffer_pool_instances(=8)

最佳答案

“99% cpu 使用率”——“你无法通过调整来解决性能问题。”

因此,找到最慢的查询。修理它。冲洗并重复。 (通常)2-3 次查询后,CPU 利用率可能会下降到 10%。

如何找到他们?使用 long_query_time=1 打开慢速日志。

如何解决查询?向我们展示一个查询以及EXPLAIN ...SHOW CREATE TABLE。同时,了解“复合”索引。

(内存使用率达到 73% 就可以了。)

关于mysqld 性能高 CPU 和内存使用率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45720283/

相关文章:

mysql - 使用查询从连接的表中检索数据

MySql 转换选择查询以更新

java - 如何在recyclerview中提供onclick以从mysql获取另一个 Activity 的值

php - 将mysql表保存为csv修改文件php中的一些单元格数据

php - Mysqltuner 优化配置和表、报告

mysql - "key buffer size"和 "total MyISAM indexes"单位大小是什么意思?

mysql - MariaDB 优化和 mysqltuner.pl - RAM 和调整

mysql - 如何在一个查询中使用带有两个条件的mysql函数 "min()"

MySqlTuner - 失败 : return code 256

mysqltuner - 需要临时表的排序