2017-02-13 210 views
0

我运行了MySQLTuner脚本,并遵循了他们给出的建议,但它仍然建议增加,同时告诉我MySQL的最大内存使用率很高。MySQL优化 - 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) 

我该怎么做才能解决这个问题? 预先感谢您

+0

您的数据库可以使用更多的内存,然后在您的系统上可用。更改配置中的最大内存。 –

+0

如果不知道如何使用此服务器,很难提出建议。如果你需要帮助,你需要解释一下你的应用程序。请[编辑]你的问题。你肯定在这台服务器上花了很多钱 - 64G的RAM!你真的需要64K同时打开文件吗?你的数据库真的有成千上万的表吗? –

+0

在此服务器上部署车辆地理位置应用程序(一个巨大的数据流/连接到此服务器的超过4000个标记) 数据库的大小超过28GB(超过18726个表) – BOUMARTA

回答

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;。我将调查调谐器错过的数十件事。

+0

非常感谢您的快速回复 – BOUMARTA