MySQL优化 - MySQL的最大内存使用率非常高

时间:2017-02-13 09:06:33

标签: mysql optimization

我运行了MySQLTuner脚本,并按照他们给出的建议,但它仍然建议增加,同时告诉我MySQL的最大内存使用率非常高。

  • 我有一个64 GB RAM的CentOS 6.5。

  • 此服务器上部署了车辆地理定位应用程序(大量数据/超过4000个连接到此服务器的标签)

  • 数据库的大小超过28GB(超过18726个表)

我在my.cnf文件中的当前配置是:

[mysqld]

server-id = 1
auto_increment_increment=2
log-slave-updates
slave-skip-errors =1146,1062,126
expire_logs_days        = 10
max_binlog_size         = 100M
relay-log = "/var/lib/mysql/mysql-relay-bin"
relay-log-index = "/var/lib/mysql/mysql-relay-bin.index"
log-error = "/var/lib/mysql/mysql.err"
master-info-file = "/var/lib/mysql/mysql-master.info"
relay-log-info-file = "/var/lib/mysql/mysql-relay-log.info"
datadir="/var/lib/mysql"
socket="/var/lib/mysql/mysql.sock"
symbolic-links=0

skip-host-cache
skip-name-resolve

open_files_limit=65535
query_cache_size=0
max_connections=500
max_user_connections=800
wait_timeout=120
tmp_table_size=32M
max_heap_table_size=32M
thread_cache_size=50
key_buffer_size=3G
max_allowed_packet=16M
table_cache=64K
join_buffer_size =32M
table_definition_cache=4096
table-open-cache=10240

myisam_sort_buffer_size=64M 
read_buffer_size=64M 
log-output=NONE 

innodb_file_per_table=1
innodb_flush_method=O_DIRECT
innodb_buffer_pool_size=38G
innodb_additional_mem_pool_size=2048M
innodb_log_buffer_size=1024M
innodb_thread_concurrency=16 
innodb_flush_log_at_trx_commit=0

[mysqld_safe]
log-error="/var/log/mysqld.log"
pid-file="/var/run/mysqld/mysqld.pid"

当我运行mysqltuner.pl时,这就是我得到的:

-------- Log file Recommendations ------------------------------------------------------------------
[--] Log file: /var/log/mysqld.log(10B)
[OK] Log file /var/log/mysqld.log exists
[OK] Log file /var/log/mysqld.log is readable.
[OK] Log file /var/log/mysqld.log is not empty
[OK] Log file /var/log/mysqld.log is smaller than 32 Mb
[OK] /var/log/mysqld.log doesn't contain any warning.
[OK] /var/log/mysqld.log doesn't contain any error.
[--] 0 start(s) detected in /var/log/mysqld.log
[--] 0 shutdown(s) detected in /var/log/mysqld.log

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA
[--] Data in MyISAM tables: 3G (Tables: 2341)
[--] Data in InnoDB tables: 23G (Tables: 16806)
[OK] Total fragmented tables: 0

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

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 20m 8s (1M q [930.905 qps], 117K conn, TX: 1G, RX: 138M)
[--] Reads / Writes: 19% / 81%
[--] Binary logging is disabled
[--] Physical Memory     : 62.9G
[--] Max MySQL memory    : 92.1G
[--] Other process memory: 10.6G
[--] Total buffers: 44.0G global + 98.5M per thread (500 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[!!] Maximum reached memory usage: 54.9G (87.30% of installed RAM)
[!!] Maximum possible memory usage: 92.1G (146.50% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[OK] Slow queries: 0% (5/1M)
[OK] Highest usage of available connections: 22% (113/500)
[OK] Aborted connections: 0.00%  (3/117330)
[!!] Query cache is disabled
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 6K sorts)
[!!] Joins performed without indexes: 133
[OK] Temporary tables created on disk: 0% (541 on disk / 233K total)
[OK] Thread cache hit rate: 99% (132 created / 117K connections)
[!!] Table cache hit rate: 7% (10K open / 129K opened)
[OK] Open file limit used: 3% (2K/65K)
[OK] Table locks acquired immediately: 99% (304K immediate / 304K 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 ----------------------------------------------------------------------------
[!!] Key buffer used: 18.8% (605M used / 3B cache)
[OK] Key buffer size / total MyISAM indexes: 3.0G/169.9M
[OK] Read Key buffer hit rate: 99.3% (1M cached / 10K reads)
[!!] Write Key buffer hit rate: 0.3% (24K cached / 24K writes)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 16
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 38.0G/23.5G
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (0.0256990131578947 %): 5.0M * 2/38.0G should be equal 25%
[!!] InnoDB buffer pool instances: 1
[--] InnoDB Buffer Pool Chunk Size not used or defined in your version
[OK] InnoDB Read buffer efficiency: 95.56% (9270734 hits/ 9701289 total)
[OK] InnoDB Write log efficiency: 98.14% (65038 hits/ 66268 total)
[OK] InnoDB log waits: 0.00% (0 waits / 1230 writes)

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

-------- 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 replication slave is not running but seems to be configured.

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    MySQL started within last 24 hours - recommendations may be inaccurate
    Reduce your overall MySQL memory footprint for system stability
    Dedicate this server to your database for highest performance.
    Enable the slow query log to troubleshoot bad queries
    Adjust your join queries to always utilize indexes
    Increase table_open_cache gradually to avoid file descriptor limits
    Read this before increasing table_open_cache over 64

    Beware that open_files_limit (65535) variable
    should be greater than table_open_cache (10240)
    Performance should be activated for better diagnostics
    Consider installing Sys schema 

Variables to adjust:
  *** MySQL's maximum memory usage is dangerously high ***
  *** Add RAM before increasing MySQL buffer variables ***
    query_cache_size (>= 8M)
    join_buffer_size (> 32.0M, or always use indexes with joins)
    table_open_cache (> 10240)
    performance_schema = ON enable PFS
    innodb_log_file_size * innodb_log_files_in_group should be equals to 1/4 of buffer pool size (=19G) if possible.
    innodb_buffer_pool_instances(=38)

我该怎么做才能解决这个问题? 提前谢谢

1 个答案:

答案 0 :(得分:1)

没有有效的公式,表明MySQL 可以实现的最大内存使用量。 实际考虑因素。

  • 调谐器无法对仅持续20分钟的系统做出真正的判断。等一天(20m可以解释“表缓存命中率:7%”。以及其他。)
  • 您可能应该将所有表移动到InnoDB。 Tips.
  • 对于生产机器,关闭查询缓存通常通常
  • “没有索引的连接:133” - 这不一定是坏事。桌子很小吗?查询“足够快”吗?
  • “slave-skip-errors = 1146,1062,126” - 这扫描了应该修复的地毯。
  • 19K表?这可能是一个问题;发生了什么事?
  • “InnoDB缓冲池实例:1” - 在您的情况下首选16。
  • “此复制从站未运行但似乎已配置。” - 它是奴隶吗?
  • “减少整体MySQL内存占用以保持系统稳定性” - 我不知道它的目标是什么。
  • “启用慢查询日志以排除错误查询” - 我同意,同时设置long_query_time = 2。然后,让我们看看一些最糟糕的问题。
  • 由于您运行的是MyISAM和InnoDB的重要组合,我会将innodb_buffer_pool_size降低到25G。这会使调谐器的一些抱怨变得沉寂,并且对内存有点安全,同时不会对性能产生太大影响。

对于其他分析,请在至少一天后提供SHOW VARIABLES;SHOW GLOBAL STATUS;。我将研究调谐器错过的几十件事。