当前位置: 首页 > news >正文

mongodb 使用内存过大分析

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 层面分析

查看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.lryc.cn/news/533356.html

相关文章:

  • CNN-day5-经典神经网络LeNets5
  • 登录到docker里
  • 利用PHP爬虫开发获取淘宝分类详情:解锁电商数据新视角
  • LeetCode 142题解|环形链表II的快慢指针法(含数学证明)
  • [图文]课程讲解片段-Fowler分析模式的剖析和实现01
  • Dify使用
  • 解锁 DeepSeek 模型高效部署密码:蓝耘平台全解析
  • 7.PPT:“中国梦”学习实践活动【20】
  • Linux系统-centos防火墙firewalld详解
  • 零基础都可以本地部署Deepseek R1
  • 通过Ollama本地部署DeepSeek R1以及简单使用的教程(超详细)
  • css实现长尾箭头(夹角小于45度的)
  • 封装descriptions组件,描述,灵活
  • OC-Block
  • 关于知识蒸馏的概念原理以及常见方法
  • C++轻量级桌面GUI库FLTK
  • C++20导出模块及使用
  • PID 算法简介(C语言)
  • Java中的继承及相关概念
  • 语言月赛 202308【小粉兔做麻辣兔头】题解(AC)
  • 云原生后端|实践?
  • GrassWebProxy
  • 6.Python函数:函数定义、函数的类型、函数参数、函数返回值、函数嵌套、局部变量、全局变量、递归函数、匿名函数
  • 青少年编程与数学 02-008 Pyhon语言编程基础 22课题、类的定义和使用
  • CosyVoice /F5-TTS /GPT-SoVITS /Fish-Speech 开源语音克隆与文本转语音(TTS)项目的对比整理
  • MySQL基于binlog和gtid主从搭建方案
  • 5 计算机网络
  • Vim跳转文件及文件行结束符EOL
  • 智能理解 PPT 内容,快速生成讲解视频
  • 【鸿蒙开发】第二十四章 AI - Core Speech Kit(基础语音服务)