mongodb 使用内存过大分析

embedded/2025/2/8 12:34:59/

os 分析

内存使用

ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head -10

swap 使用

for i in $(ls /proc | grep "^[0-9]" | awk '$0>100'); do awk '/Swap:/{a=a+$2}END{print '"$i"',a/1024"M"}' /proc/$i/smaps;done| sort -k2nr | head

mongodb__12">mongodb 层面分析

查看tcmalloc内存分配器

data0data0:PRIMARY> db.version();
4.2.17data0data0:PRIMARY> db.serverStatus().tcmalloc.tcmalloc.formattedString
------------------------------------------------
MALLOC:    28062443328 (26762.4 MiB) Bytes in use by application
MALLOC: +  55441469440 (52873.1 MiB) Bytes in page heap freelist
MALLOC: +   8222845880 ( 7841.9 MiB) Bytes in central cache freelist
MALLOC: +        37632 (    0.0 MiB) Bytes in transfer cache freelist
MALLOC: +     20273672 (   19.3 MiB) Bytes in thread cache freelists
MALLOC: +    530448384 (  505.9 MiB) Bytes in malloc metadata
MALLOC:   ------------
MALLOC: =  92277518336 (88002.7 MiB) Actual memory used (physical + swap)
MALLOC: +   8146022400 ( 7768.7 MiB) Bytes released to OS (aka unmapped)
MALLOC:   ------------
MALLOC: = 100423540736 (95771.4 MiB) Virtual address space used
MALLOC:
MALLOC:        4213034              Spans in use
MALLOC:            118              Thread heaps in use
MALLOC:           4096              Tcmalloc page size
------------------------------------------------
Call ReleaseFreeMemory() to release freelist memory to the OS (via madvise()).
Bytes released to the OS take up virtual address space but no physical memory.

Bytes in use by application 对应的内存指 Mongod 节点实际消耗的内存
Bytes in page heap freelist 为未归还给操作系统的内存。

可以通过增大参数tcmallocReleaseRate提高释放内存速率

db.adminCommand( { getParameter: 1, tcmallocReleaseRate:1} )db.adminCommand( { setParameter: 1, tcmallocReleaseRate: 5.0 } )

进一步,如何希望立即释放内存,可以设置参数tcmallocAggressiveMemoryDecommit 为1

db.adminCommand( { getParameter: 1, tcmallocAggressiveMemoryDecommit:1} )db.adminCommand( { setParameter: 1, tcmallocAggressiveMemoryDecommit:1} )

查看wiredTiger cache

data0data0:PRIMARY> db.serverStatus().storageEngine;
{"name" : "wiredTiger","supportsCommittedReads" : true,"oldestRequiredTimestampForCrashRecovery" : Timestamp(1738804816, 1),"supportsPendingDrops" : true,"dropPendingIdents" : NumberLong(0),"supportsSnapshotReadConcern" : true,"readOnly" : false,"persistent" : true,"backupCursorOpen" : false
}

查看wiredTiger 内存当前使用大小

data0data0:PRIMARY> db.serverStatus().wiredTiger.cache

关注 bytes currently in the cache

{......"bytes belonging to page images in the cache":6511653424,"bytes belonging to the cache overflow table in the cache":65289,"bytes currently in the cache":8563140208,"bytes dirty in the cache cumulative":NumberLong("369249096605399"),......
}

查看 wiredTiger 内存配合的参数大小
单位字节

data0data0:PRIMARY> db.serverStatus().wiredTiger.cache["maximum bytes configured"]
1073741824

可以适当调小或者调大

data0data0:PRIMARY> db.adminCommand({setParameter: 1, "wiredTigerEngineRuntimeConfig": "cache_size=2GB" });

查看修改后的最新值

data0data0:PRIMARY> db.serverStatus().wiredTiger.cache["maximum bytes configured"];
2147483648

记得同步修改参数文件,避免实例重启后丢失修改值。

备注:
1、默认 WiredTiger 内部缓存大小为以下两者中的较大者:
(RAM 大小 - 1 GB)的 50%,或
256 MB.

https://www.mongodb.com/zh-cn/docs/v5.0/core/wiredtiger/#memory-use


http://www.ppmy.cn/embedded/160536.html

相关文章

【Linux网络编程】之配置阿里云安全组

【Linux网络编程】之配置阿里云安全组 配置阿里云安全组阿里云安全组的概念配置安全组规则入方向基本概念补充ICMP协议安全组配置UDP协议安全组配置 出方向 配置云服务器主机的防火墙什么是防火墙Linux中防火墙的管理工具防火墙的作用常用命令介绍(firewalld&#x…

【深度学习】图像识别模型与训练策略

一、预处理与数据增强模块 transforms transforms通常指torchvision.transforms 1.调整尺寸 transforms.Resize():将输入图像的尺寸调整为指定的大小 2.裁剪 transforms.CenterCrop():从图像中心进行裁剪,剪裁出指定大小的区域 transf…

leetcode_双指针 557. 反转字符串中的单词 III

557. 反转字符串中的单词 III 给定一个字符串 s ,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序。思路: 1.首先用split()切割字符串中用空格分隔的单词2.用切片法反转每个单词3.用join()把反转后的单词用空格连接 class Solu…

k8s集群外exporter怎么使用Prometheus监控

要在 A 的 Kubernetes 集群中运行 Prometheus 并监控 B 的 Kubernetes 集群,您可以通过以下步骤实现: 1. 设置网络连接 跨集群网络连接: 确保 A 集群中的 Prometheus 可以通过网络访问 B 集群中的 Kubernetes API 和监控目标。通常&#xf…

7.list

本篇博客梳理C的STL中的list容器 一、list的基本结构与使用 1.list的介绍 list的底层是带头循环双向链表 带头:含哨兵位 循环:尾节点的next指针指向哨兵位 双向:每个节点具有两个指针域,一个指针指向前一个结点 2…

2025蓝桥杯JAVA编程题练习Day3

1.黛玉泡茶【算法赛】 问题描述 话说林黛玉闲来无事,打算在潇湘馆摆个茶局,邀上宝钗、探春她们一起品茗赏花。黛玉素来讲究,用的茶杯也各有不同,大的小的,高的矮的,煞是好看。这不,她从柜子里…

TikTok 推出了一款 IDE,用于快速构建 AI 应用

字节跳动(TikTok 的母公司)刚刚推出了一款名为 Trae 的新集成开发环境(IDE)。 Trae 基于 Visual Studio Code(VS Code)构建,继承了这个熟悉的平台,并加入了 AI 工具,帮助开发者更快、更轻松地构建应用——有时甚至无需编写任何代码。 如果你之前使用过 Cursor AI,T…

机器学习数学基础:19.线性相关与线性无关

一、线性相关与线性无关的定义 (一)线性相关 想象我们有一组向量,就好比是一群有着不同“力量”和“方向”的小伙伴。给定的向量组 α ⃗ 1 , α ⃗ 2 , ⋯ , α ⃗ m \vec{\alpha}_1, \vec{\alpha}_2, \cdots, \vec{\alpha}_m α 1​,α 2…