【问题标题】:High CPU usage by MySQL Server [closed]MySQL服务器的高CPU使用率[关闭]
【发布时间】:2020-03-31 17:25:30
【问题描述】:

我有一个游戏服务器,MySQL 一直处于 100-200% CPU,我尝试优化查询缓存大小但没有帮助。我有一些“大”表,我猜有超过一百万条记录。我有另一个有 150k 记录的表,我怀疑这是因为它在一分钟内被多次写入和读取。我已经运行了 MySQLTuner,结果如下:

[--] Skipped version check for MySQLTuner script
Please enter your MySQL administrative login: root
Please enter your MySQL administrative password: [!!] Your MySQL version 5.5.62 is EOL software!  Upgrade soon!
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[!!] Log file ./srv.err doesn't exist

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +CSV +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA
[--] Data in MyISAM tables: 1.5G (Tables: 130)
[!!] InnoDB is enabled but isn't being used
[OK] Total fragmented tables: 0

-------- Analysis Performance Metrics --------------------------------------------------------------
[--] innodb_stats_on_metadata: ON
[!!] Stat are updated during querying INFORMATION_SCHEMA.

-------- Security Recommendations ------------------------------------------------------------------
[OK] There are no anonymous accounts for any database users
[OK] All database users have passwords assigned
[!!] User 'root@%' does not specify hostname restrictions.
[!!] There is no basic password file list!

-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 90d 23h 30m 41s (639M q [81.385 qps], 955K conn, TX: 102G, RX: 90G)
[--] Reads / Writes: 3% / 97%
[--] Binary logging is disabled
[--] Physical Memory     : 12.0G
[--] Max MySQL memory    : 583.2M
[--] Other process memory: 0B
[--] Total buffers: 168.0M global + 2.8M per thread (151 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 349.5M (2.86% of installed RAM)
[OK] Maximum possible memory usage: 583.2M (4.77% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 0% (107/639M)
[OK] Highest usage of available connections: 43% (66/151)
[OK] Aborted connections: 0.55%  (5273/955610)
[!!] 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 / 25M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (456 temp sorts / 3M sorts)
[OK] No joins without indexes
[!!] Temporary tables created on disk: 35% (2K on disk / 6K total)
[!!] Thread cache is disabled
[OK] Table cache hit rate: 96% (236 open / 245 opened)
[OK] table_definition_cache(400) is upper than number of tables(211)
[OK] Open file limit used: 0% (359/352K)
[OK] Table locks acquired immediately: 99% (632M immediate / 633M locks)

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

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

-------- MyISAM Metrics ----------------------------------------------------------------------------
[OK] Key buffer used: 100.0% (8M used / 8M cache)
[OK] Key buffer size / total MyISAM indexes: 8.0M/379.3M
[OK] Read Key buffer hit rate: 99.6% (3B cached / 15M reads)
[!!] Write Key buffer hit rate: 86.2% (77M cached / 66M writes)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is disabled.
[!!] InnoDB Storage engine is disabled. InnoDB is the default storage engine

-------- 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
[--] No replication slave(s) for this server.
[--] Binlog format: STATEMENT
[--] XA support enabled: ON
[--] Semi synchronous replication Master: Not Activated
[--] Semi synchronous replication Slave: Not Activated
[--] This is a standalone server

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    Add skip-innodb to MySQL configuration to disable InnoDB
    Restrict Host for 'root'@% to root@SpecificDNSorIp
    UPDATE mysql.user SET host ='SpecificDNSorIp' WHERE user='root' AND host ='%'; FLUSH PRIVILEGES;
    Enable the slow query log to troubleshoot bad queries
    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
    Set thread_cache_size to 4 as a starting value
Variables to adjust:
    SET innodb_stats_on_metadata = OFF
    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)
    thread_cache_size (start at 4)

你怎么看?我该怎么办? 配备 Intel Xeon 5570 + 12G RAM + RAID1 中的 2x750GB HDD 的专用服务器

提前致谢。

【问题讨论】:

  • 我会尝试分析报告底部列出的建议。
  • 在服务器上运行 show full processlist。查看那里经常出现的查询并对其进行优化。
  • "InnoDB 已启用但未使用" - MyISAM 在高并发环境中表现不佳。切换到 InnoDB。
  • A) 尽快切换到 InnoDB。 B) 调整您的 InnoDB 安装并确保将内存分配给 InnoDB 缓冲池。 C) 升级 MySQL,因为新版本的性能明显更好,尤其是与 5.5 相比。 D) 获得更多内存。另一个 64GB 不会破坏银行,它会是几百美元,并且可以改变世界。 E) 如果遇到 IO 问题,请切换到 SSD。
  • 附加信息请求。 # 核心,MySQL 主机服务器上的任何 SSD 设备。在 pastebin.com 上发布并分享链接。 A) 完整(未编辑)my.cnf 或 my.ini 来自 SSH 登录根,文本结果为:B) SHOW GLOBAL STATUS;至少 24 小时正常运行时间后 C) 显示全局变量; D) 显示完整的处理程序;和 可选的非常有用的信息,如果可用,包括 - htop 或 top 用于大多数活动应用程序,ulimit -a 用于 Linux/Unix 限制列表,iostat -xm 5 3 用于按设备和核心/cpu 计数的 IOPS,用于服务器工作负载调整分析提供建议。

标签: mysql caching freebsd lag


【解决方案1】:

有很多事情可以做,但它“取决于”,可能是 CPU 使用率是由于正在运行的备份,一些插入取决于缺少索引的子查询等,无论如何,在详细检查后您的环境,如果问题主要与 MySQL 有关,您可以在https://dba.stackexchange.com/ 中寻求更好的答案

这些是一些额外的检查,以补充 cmets 中已经建议的内容。

【讨论】:

    【解决方案2】:

    每秒速率 = RPS

    为您的 my.cnf [mysqld] 部分版本 5.5.62(生命周期结束)考虑的建议

    innodb_stats_on_metadata=OFF  # from ON to conserve CPU cycles
    query_cache_size=0  # to ensure it is not used
    query_cache_type=0  # to ensure QC Type is OFF
    query_cache_limit=0  # from 1M to conserve RAM
    tmp_table_size=32M  # from 16M to expand RAM availability 
    max_heap_table_size=32M  # from 16M to keep same size as tmp_table_size
    thread_cache_size=64  # from 0 to support your highest use of 66 connections
    slow_query_log=ON  # from OFF to allow log review and corrective action for 107 in 90 days
    skip_name_resolve=ON  # from OFF to conserve CPU cycle for each connection
    key_buffer_size=200M  # from 8M - you have 379M of MyISAM indexes, keep 1/2 in RAM
    key_cache_age_threshold=7200  # from 300 seconds to reduce key_reads RPS
    key_cache_division_limit=50  # from 100 for hot/warm separation
    key_cache_block_size=16384  # from 1024 to reduce frequency of management
    

    您会发现这些配置更改将显着减少 CPU 繁忙。

    【讨论】:

      猜你喜欢
      • 2010-11-19
      • 1970-01-01
      • 2015-08-05
      • 1970-01-01
      • 1970-01-01
      • 2014-07-13
      • 2018-07-08
      相关资源
      最近更新 更多