GreatSQL社区

搜索

[已解决] MySQL内存持续上升,没有释放

1699 10 2024-4-23 09:18
MySQL版本:Ver 8.0.35 for Linux on x86_64 (MySQL Community Server - GPL)

OS:Ubuntu 22.04.4 LTS
CPU:8H
Memory:16G

my.cnf
  1. [client]
  2. socket = /data/mysql/mysql.sock

  3. [mysql]
  4. prompt = "\u@mysqldb \R:\m:\s [\d]> "
  5. no-auto-rehash

  6. [mysqldump]
  7. single-transaction

  8. [mysqld_safe]
  9. malloc-lib = /usr/lib/x86_64-linux-gnu/libjemalloc.so.2

  10. [mysqld]
  11. #basic settings#
  12. server-id = 100
  13. port = 3306
  14. user = mysql
  15. autocommit = 1
  16. socket = /data/mysql/mysql.sock
  17. character_set_server=utf8mb4
  18. datadir=/data/mysql/
  19. basedir=/usr/local/mysql/
  20. explicit_defaults_for_timestamp = 1
  21. sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
  22. transaction_isolation = READ-COMMITTED
  23. max_allowed_packet = 64M
  24. event_scheduler = 1
  25. #connection#
  26. interactive_timeout = 1800
  27. wait_timeout = 1800
  28. lock_wait_timeout = 1800
  29. skip_name_resolve = 1
  30. max_connections = 1024
  31. max_user_connections = 256
  32. max_connect_errors = 1000000
  33. #table cache performance settings#
  34. table_open_cache = 4096
  35. table_definition_cache = 4096
  36. table_open_cache_instances = 64
  37. #session memory settings#
  38. read_buffer_size = 2M
  39. read_rnd_buffer_size = 2M
  40. sort_buffer_size = 2M
  41. tmp_table_size = 2M
  42. join_buffer_size = 2M
  43. thread_cache_size = 64
  44. #log settings#
  45. log_error = error.log
  46. log_bin = binlog
  47. log_error_verbosity = 2
  48. slow_query_log = 1
  49. slow_query_log_file = slow.log
  50. log_queries_not_using_indexes = 1
  51. log_slow_admin_statements = 1
  52. log_slow_replica_statements = 1
  53. log_throttle_queries_not_using_indexes = 10
  54. binlog_expire_logs_seconds = 864000
  55. long_query_time = 2
  56. min_examined_row_limit = 100
  57. log-bin-trust-function-creators = 1
  58. binlog_cache_size  = 2M
  59. ########innodb settings########
  60. innodb_page_size = 16k
  61. innodb_buffer_pool_size = 9G
  62. innodb_buffer_pool_instances = 8
  63. innodb_buffer_pool_load_at_startup = 1
  64. innodb_buffer_pool_dump_at_shutdown = 1
  65. innodb_lru_scan_depth = 4096
  66. innodb_lock_wait_timeout = 5
  67. innodb_io_capacity = 20000
  68. innodb_io_capacity_max = 24000
  69. innodb_flush_method = O_DIRECT
  70. innodb_flush_neighbors = 0
  71. innodb_redo_log_capacity = 4G
  72. innodb_log_buffer_size = 64M
  73. innodb_purge_threads = 4
  74. innodb_thread_concurrency = 0
  75. innodb_print_all_deadlocks = 1
  76. innodb_strict_mode = 1
  77. innodb_sort_buffer_size = 64M
  78. innodb_write_io_threads = 8
  79. innodb_read_io_threads = 4
  80. innodb_file_per_table = 1
  81. innodb_stats_persistent_sample_pages = 64
  82. innodb_autoinc_lock_mode = 2
  83. innodb_online_alter_log_max_size=100M
  84. innodb_open_files=4096
  85. innodb_flush_log_at_trx_commit = 1
  86. #replication settings#
  87. sync_binlog = 1
  88. gtid_mode = on
  89. enforce_gtid_consistency = 1
  90. binlog_format = ROW
  91. binlog_rows_query_log_events = 1
  92. relay_log = relay.log
  93. relay_log_recovery = 1
  94. log_replica_updates = 1
  95. replica_skip_errors = ddl_exist_errors
  96. replica_parallel_workers = 8
  97. replica_preserve_commit_order = 1
  98. replica_transaction_retries = 128
  99. binlog_gtid_simple_recovery = 1
  100. log_timestamps = system
  101. #mgr settings
  102. loose-plugin_load_add = 'mysql_clone.so'
  103. loose-plugin_load_add = 'group_replication.so'
  104. loose-group_replication_group_name = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1"
  105. loose-group_replication_local_address = "10.20.12.106:33061"
  106. loose-group_replication_group_seeds = '10.20.12.106:33061,10.20.12.107:33061,10.20.12.108:33061'
  107. loose-group_replication_start_on_boot = OFF
  108. loose-group_replication_bootstrap_group = OFF
  109. loose-group_replication_exit_state_action = READ_ONLY
  110. loose-group_replication_flow_control_mode = "DISABLED"
  111. loose-group_replication_single_primary_mode = ON
  112. loose-group_replication_communication_max_message_size = 10M
  113. loose-group_replication_transaction_size_limit = 1G
  114. loose-group_replication_arbitrator = 0
  115. loose-group_replication_single_primary_fast_mode = 1
  116. loose-group_replication_request_time_threshold = 20000
  117. loose-group_replication_recovery_get_public_key = 1
  118. report-host = "10.20.12.106"
  119. #perforamnce_schema settings#
  120. performance-schema-instrument='memory/%=COUNTED'
  121. performance_schema_digests_size = 40000
  122. performance_schema_max_table_handles = 40000
  123. performance_schema_max_table_instances = 40000
  124. performance_schema_max_sql_text_length = 4096
  125. performance_schema_max_digest_length = 4096
  126. loose_innodb_numa_interleave = 1
  127. innodb_buffer_pool_dump_pct = 40
  128. innodb_page_cleaners = 8
  129. innodb_undo_log_truncate = 1
  130. innodb_max_undo_log_size = 4G
  131. innodb_purge_rseg_truncate_frequency = 128

  132. #innodb monitor settings
  133. innodb_monitor_enable = "module_innodb"
  134. innodb_monitor_enable = "module_server"
  135. innodb_monitor_enable = "module_dml"
  136. innodb_monitor_enable = "module_ddl"
  137. innodb_monitor_enable = "module_trx"
  138. innodb_monitor_enable = "module_os"
  139. innodb_monitor_enable = "module_purge"
  140. innodb_monitor_enable = "module_log"
  141. innodb_monitor_enable = "module_lock"
  142. innodb_monitor_enable = "module_buffer"
  143. innodb_monitor_enable = "module_index"
  144. innodb_monitor_enable = "module_ibuf_system"
  145. innodb_monitor_enable = "module_buffer_page"
  146. innodb_monitor_enable = "module_adaptive_hash"
复制代码


参考叶老师的深入浅出MGR搭建的MGR集群。目前master节点内存使用率大约89%,从启动数据库就一直处于上升趋势。有一些慢查询,但是慢查询应该不会导致内存一直上升,请帮忙看看,谢谢。

全部回复(10)
yejr 2024-4-23 11:05:22
gavin.zheng 2024-7-31 16:13:30
yejr 发表于 2024-4-23 11:05
有几篇参考可以先看下
- https://greatsql.cn/blog-10-1218.html
- https://greatsql.cn/thread-560-1-1.ht ...

叶老师您好,

       从你给我的帖子可以判断是内存泄漏了,但是我用命令:gdb --batch --pid 4757 --ex 'call malloc_trim(0)' 无法释放内存,这是为什么?





yejr 2024-8-1 09:17:45
gavin.zheng 发表于 2024-7-31 16:13
叶老师您好,

       从你给我的帖子可以判断是内存泄漏了,但是我用命令:gdb --batch --pid 4757 --ex ...

按你的描述,进程内存一直上升,那是不是到了一定时间就会把内存耗尽引发OOM kill了?

目前有发生过这种情况吗,还是说上升到一定程度就不再涨了?
reddey 2024-8-1 09:46:24
yejr 发表于 2024-8-1 09:17
按你的描述,进程内存一直上升,那是不是到了一定时间就会把内存耗尽引发OOM kill了?

目前有发生过这种 ...

如果发生OOM,内存全会吃光,应用直接不可用了。
一个学艺不精的国产数据库爱好者
gavin.zheng 2024-8-1 16:25:18
yejr 发表于 2024-8-1 09:17
按你的描述,进程内存一直上升,那是不是到了一定时间就会把内存耗尽引发OOM kill了?

目前有发生过这种 ...

会一直上升知道MySQL被OOM掉。
我按照你发的链接安装jemalloc替代glibc,但是好像不管用。我用的系统是ubuntu 22.04。因为用的是MGR架构,所以现在一般两三个月我就重启下VM。
我们另外一套环境用的是MHA内存倒是一直很稳定。但是MHA环境我没有开启以下参数:
#innodb monitor settings
innodb_monitor_enable = "module_innodb"
innodb_monitor_enable = "module_server"
innodb_monitor_enable = "module_dml"
innodb_monitor_enable = "module_ddl"
innodb_monitor_enable = "module_trx"
innodb_monitor_enable = "module_os"
innodb_monitor_enable = "module_purge"
innodb_monitor_enable = "module_log"
innodb_monitor_enable = "module_lock"
innodb_monitor_enable = "module_buffer"
innodb_monitor_enable = "module_index"
innodb_monitor_enable = "module_ibuf_system"
innodb_monitor_enable = "module_buffer_page"
innodb_monitor_enable = "module_adaptive_hash"

内存缓慢上涨会不会和上面这些参数也有关系?
gavin.zheng 2024-8-1 16:39:52
gavin.zheng 发表于 2024-8-1 16:25
会一直上升知道MySQL被OOM掉。
我按照你发的链接安装jemalloc替代glibc,但是好像不管用。我用的系统是ub ...

我看官方好像不建议在生产环境开启这些监控;
这些监控太多了,是否真的有必要开启?直接用show engine innodb status;是否也能达到相同的效果?
有没有合适的监控软件可以直接读取INNODB_METRICS里面的内容?
yejr 2024-8-1 17:47:41
gavin.zheng 发表于 2024-8-1 16:25
会一直上升知道MySQL被OOM掉。
我按照你发的链接安装jemalloc替代glibc,但是好像不管用。我用的系统是ub ...

那就把这些额外的先都关掉,并换成GreatSQL 8.0.32-25版本试试看,我们预计下周(2024.8.5)发布GreatSQL 8.0.32-26版本,届时也可以关注测试。
gavin.zheng 2024-8-1 17:56:52
yejr 发表于 2024-8-1 17:47
那就把这些额外的先都关掉,并换成GreatSQL 8.0.32-25版本试试看,我们预计下周(2024.8.5)发布GreatSQL  ...

谢谢叶老师。换GreatSQL我需要问下我们领导,看看他的意思,到时候我再给您留言。
gavin.zheng 2024-8-1 17:57:42
reddey 发表于 2024-8-1 09:46
如果发生OOM,内存全会吃光,应用直接不可用了。

的确发生过,但是我们用的MGR,所以down了一台也没关系
12下一页
gavin.zheng

1

主题

0

博客

8

贡献

新手上路

Rank: 1

积分
15

合作电话:010-64087828

社区邮箱:greatsql@greatdb.com

社区公众号
社区小助手
QQ群
GMT+8, 2024-10-31 16:27 , Processed in 0.022009 second(s), 20 queries , Redis On.
快速回复 返回顶部 返回列表