mongodb 使用内存过大分析

ps aux

内存使用

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 命令

data0data0:PRIMARY> db.version();
4.2.17

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["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

你可能感兴趣的:(#,mongodb,mongodb,数据库)