GreatSQL社区

搜索

[已解决] mgr 数据库使用内存一直在上涨,是不是内存泄露了。

628 7 2023-10-27 11:41
PC 信息: 16C , 32G

数据库关键参数配置: innodb_buffer_size 一开始 21G ,目前已经调整到了12G
                                   join_buffer_size   由 默认调整到了 16M
                                   sort_buffer_size   由 默认调整到     4M
状态查看:
show global status like '%open%tables%';
Open_tables1798             由4000 变道了 现在 不到2000
Opened_tables356472

show variables like '%table_open_cache%';
Variable_nameValue
table_open_cache
4000
table_open_cache_instances
16

找到了 排名执行次数最多的慢sql 语句,发给开发来做优化了,刚发的还没有优化。


问题是: 为啥 我调整了这些参数后,Open_tables 会变少,看其他人解释说,open_tables 似乎和这些关系不大,求解释。








全部回复(7)
yejr 2023-10-27 15:33:57
补充几个信息:
1. 什么版本
2. my.cnf配置
3. mysqld进程内存消耗从多少涨到多少
4. 查看下面几个数据
  1. select event_name,SUM_NUMBER_OF_BYTES_ALLOC  from

  2.   memory_summary_global_by_event_name

  3.     order by SUM_NUMBER_OF_BYTES_ALLOC desc LIMIT 10;

  4. select event_name, SUM_NUMBER_OF_BYTES_ALLOC from

  5.   memory_summary_by_thread_by_event_name

  6.     order by SUM_NUMBER_OF_BYTES_ALLOC desc limit 20;
复制代码
li15130686553 2023-10-28 15:44:36
yejr 发表于 2023-10-27 15:33
补充几个信息:
1. 什么版本
2. my.cnf配置

root@performance_schema 03:41:59>select event_name,SUM_NUMBER_OF_BYTES_ALLOC  from
    ->
    ->   memory_summary_global_by_event_name
    ->
    ->     order by SUM_NUMBER_OF_BYTES_ALLOC desc LIMIT 10;
+--------------------------------------+---------------------------+
| event_name                           | SUM_NUMBER_OF_BYTES_ALLOC |
+--------------------------------------+---------------------------+
| memory/sql/THD::main_mem_root        |           119328450733152 |
| memory/temptable/physical_ram        |            65065471361216 |
| memory/innodb/memory                 |            13695319856168 |
| memory/mysqld_openssl/openssl_malloc |            12590189587542 |
| memory/sql/String::value             |             2867819142280 |
| memory/sql/hash_join                 |             2694224319960 |
| memory/sql/TABLE                     |             2403680130583 |
| memory/sql/test_quick_select         |             1237054862744 |
| memory/mysys/IO_CACHE                |              362257393448 |
| memory/sql/Row_data_memory::memory   |              176959463210 |
+--------------------------------------+---------------------------+
10 rows in set (0.00 sec)

root@performance_schema 03:42:16>
root@performance_schema 03:42:16>select event_name, SUM_NUMBER_OF_BYTES_ALLOC from
    ->
    ->   memory_summary_by_thread_by_event_name
    ->
    ->     order by SUM_NUMBER_OF_BYTES_ALLOC desc limit 20;
+-------------------------------------+---------------------------+
| event_name                          | SUM_NUMBER_OF_BYTES_ALLOC |
+-------------------------------------+---------------------------+
| memory/innodb/memory                |               31132935352 |
| memory/innodb/memory                |               22228308000 |
| memory/sql/Log_event                |               14081100725 |
| memory/innodb/memory                |               13536202080 |
| memory/sql/dd::infrastructure       |               13138399888 |
| memory/sql/Sid_map::Node            |               12164665576 |
| memory/innodb/memory                |                9869635408 |
| memory/sql/Gtid_set::Interval_chunk |                5027081056 |
| memory/sql/Sid_map::Node            |                3988104932 |
| memory/innodb/memory                |                3493758992 |
| memory/innodb/memory                |                3399600480 |
| memory/innodb/ha_innodb             |                 986669008 |
| memory/sql/dd::String_type          |                 860577448 |
| memory/innodb/std                   |                 469203128 |
| memory/sql/String::value            |                 469152288 |
| memory/sql/MYSQL_LOCK               |                 417083448 |
| memory/sql/Gtid_set::Interval_chunk |                 408813168 |
| memory/innodb/std                   |                 370458324 |
| memory/innodb/std                   |                 370186164 |
| memory/innodb/std                   |                 369935360 |
+-------------------------------------+---------------------------+
20 rows in set (0.01 sec)

root@performance_schema 03:42:16>\s
--------------
mysql  Ver 8.0.32 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:          63282582
Current database:       performance_schema
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         8.0.32 MySQL Community Server - GPL
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
UNIX socket:            /data/mysql.sock
Binary data as:         Hexadecimal
Uptime:                 115 days 2 hours 10 min 9 sec

Threads: 63  Questions: 794371227  Slow queries: 38535150  Opens: 362664  Flush tables: 96  Open tables: 3715  Queries per second avg: 79.886
--------------
li15130686553 2023-10-28 15:46:44
li15130686553 发表于 2023-10-28 15:44
root@performance_schema 03:41:59>select event_name,SUM_NUMBER_OF_BYTES_ALLOC  from
    ->
    -> ...

[mysqld]
authentication_policy=mysql_native_password
server_id=1
basedir=/usr/local/mysql
datadir=/data
socket=/data/mysql.sock
pid-file=/data/mysqld.pid
lower_case_table_names=1
log_error=/data/error.log
default-time_zone='+8:00'
back_log=1024
binlog_checksum  =  CRC32
character_set_server  =  utf8mb4
collation_server  =  utf8mb4_0900_ai_ci
binlog_expire_logs_seconds = 259200
general_log_file=/data/general.log
slow_query_log=1
slow_query_log_file=/data/slow.log
log_queries_not_using_indexes  =  ON
log_throttle_queries_not_using_indexes  =  0
long_query_time  =  3
# Disabling symbolic-links is recommended to prevent assorted security risks
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
transaction_isolation=READ-COMMITTED
enforce_gtid_consistency=on
gtid_mode=on
log_bin=binlog
#log_slave_updates=on
log_replica_updates=on
# mgr settings
loose-plugin_load_add='mysql_clone.so'
loose-plugin_load_add='group_replication.so'
# group_replication
disabled_storage_engines="MyISAM,BLACKHOLE,FEDERATED,ARCHIVE,MEMORY"
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "10.0.xx.xx:33061"
loose-group_replication_group_seeds= "10.0.xx.xx:33061,10.0.xx.xx:33061,10.0.xx.xx:33061"
loose-group_replication_bootstrap_group=off

max_connections  =  4500      
max_allowed_packet = 1073741824
max_connect_errors = 100000
skip_name_resolve = on

#binlog
##gtid
log_bin=on
#gtid_mode=ON
#enforce-gtid-consistency = ON
binlog_format = ROW
sync_binlog = 1
open_files_limit=65536


innodb_buffer_pool_size  =  22548578304
innodb_buffer_pool_instances  =  8
innodb_data_file_path=ibdata1:12M:autoextend
innodb_redo_log_capacity=2147483648
innodb_thread_concurrency=16
innodb_io_capacity =  10000
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
li15130686553 2023-10-28 15:47:45
li15130686553 发表于 2023-10-28 15:46
[mysqld]
authentication_policy=mysql_native_password
server_id=1

改完参数后今天 还算正常,从内存从76% 到了 76.3% 。
li15130686553 2023-10-28 15:50:20
li15130686553 发表于 2023-10-28 15:46
[mysqld]
authentication_policy=mysql_native_password
server_id=1

参数用的是 set @@global.xxx = xx 改的。 没有在这个my.cnf 中体现
yejr 2023-10-28 22:20:41
li15130686553 发表于 2023-10-28 15:50
参数用的是 set @@global.xxx = xx 改的。 没有在这个my.cnf 中体现

1. 建议启用jemalloc,参考:https://greatsql.cn/docs/8032/us ... nstall-prepare.html

2. 看起来你的这个数据库业务中挺多垃圾SQL的,抓紧优化吧,参考: https://greatsql.cn/docs/8032/us ... 6%9F%A5%E8%AF%A2sql
li15130686553 2023-10-30 08:59:19
yejr 发表于 2023-10-28 22:20
1. 建议启用jemalloc,参考:https://greatsql.cn/docs/8032/user-manual/4-install-guide/1-install-pre ...

感谢感谢: 第一条,建议启用 jemalloc ,目前内存使用正常,经过了2天的观察。
                 第二条,嗯,垃圾SQL 是很多,三方的成熟的产品,业务和开发不反馈,我只能,定时发一下,运行缓慢的top10。

li15130686553

1

主题

0

博客

9

贡献

新手上路

Rank: 1

积分
15

合作电话:010-64087828

社区邮箱:greatsql@greatdb.com

社区公众号
社区小助手
QQ群
GMT+8, 2024-5-21 09:04 , Processed in 0.023782 second(s), 19 queries , Redis On.
快速回复 返回顶部 返回列表