许多表的MySQL内存使用情况

时间:2018-06-24 08:29:12

标签: mysql memory-consumption

我有一个带有100,000个表的MySQL。目前,这是我系统的最佳设计,因为这些表彼此不相关,并且选择查询仅位于单个表上。此外,用户很可能不会经常访问相同的表。

我有16GB RAM,但是大约一天后,MySQL消耗了其中的90%,而我对系统的总内存使用率为99-100%。我尝试了很多事情,但无法降低内存使用量。

我的innodb_buffer_pool_size当前为8GB,但我在1G上遇到了同样的问题。我也尝试减少open_files_limit,但这也无济于事。

这是我的输出

SHOW GLOBAL STATUS LIKE '%Open_%';
+----------------------------+----------+
| Variable_name              | Value    |
+----------------------------+----------+
| Com_show_open_tables       | 0        |
| Innodb_num_open_files      | 431      |
| Open_files                 | 0        |
| Open_streams               | 0        |
| Open_table_definitions     | 615      |
| Open_tables                | 416      |
| Opened_files               | 4606655  |
| Opened_table_definitions   | 4598528  |
| Opened_tables              | 4661002  |
| Slave_open_temp_tables     | 0        |
| Table_open_cache_hits      | 30024782 |
| Table_open_cache_misses    | 4661002  |
| Table_open_cache_overflows | 4660579  |
+----------------------------+----------+

这是我的mysqld配置:

sql-mode=''
innodb_buffer_pool_size = 8G
open_files_limit=100000
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket  = /var/run/mysqld/mysqld.sock
port        = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir  = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
bind-address        = 127.0.0.1
key_buffer_size     = 16M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size       = 8
myisam-recover-options  = BACKUP
query_cache_limit   = 1M
query_cache_size        = 16M
log_error = /var/log/mysql/error.log
expire_logs_days    = 10
max_binlog_size   = 100M

任何人都知道如何有效处理这数千个表吗?

其他信息

A)Mysqld:https://pastebin.com/PTiz6uRD

B)显示全局状态:https://pastebin.com/K4sCmvFz

C)显示全局变量:https://pastebin.com/Cc64BAUw

D)MySQLTuner:https://pastebin.com/zLzayi56

E)显示引擎的INNODB状态:https://pastebin.com/hHDuw6gY

F)顶部:https://pastebin.com/6WYnSnPm

服务器重启后的测试(消耗少量内存):

A)ulimit -a:https://pastebin.com/FmPrAKHU

B)iostat -x:https://pastebin.com/L0G7H8s4

C)df -h:https://pastebin.com/d3EttR19

D)MySQLTuner:https://pastebin.com/T3DYDLg8

1 个答案:

答案 0 :(得分:1)

要删除的第一个块将在Linux命令行中, ulimit -n 124000超过当前打开的1024个文件的限制 现在可以完成此操作,无需关闭/重新启动Linux即可。

您的my.cnf [mysqld]部分要考虑的建议

table_open_cache=10000  # from 431 available today to a practical upper limit
table_definition_cache=10000  # from 615 available today to a practical upper limit
thread_cache_size=100  # from 8 for V8 refman CAP suggested to avoid OOM
max_heap_table_size=64M  # from 16M to reduce created_tmp_disk_tables
tmp_table_size=64M  # from 16M should always be equal to max_heap_table_size
innodb_lru_scan_depth=100  # from 1024 to reduce CPU workload every SECOND
innodb_log_buffer_size=512M  # from 50M to avoid log rotation every 7 minutes

考虑到您的情况,我将跳过一天的规则并进行监控 下一个全局变量更改。进行所有cnf更改。需要停止/启动服务,因为即使您请求100,000 ulimit,MySQL仍将您限制为open_files_limit,这会导致运行时将您限制为1024。

如果您复制该块,请将其粘贴到MySQLD部分的END, 仅删除MYSQLD部分中块上方的相同命名变量, 您将摆脱下一个分析师的“多变量混乱”。

请查看个人资料以获取联系信息并取得联系。