产品动态
公告
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"),......}
threads_max=4,threads_min=1,其设置方式如下:db.runCommand({"setParameter":1, "wiredTigerEngineRuntimeConfig":"eviction=(threads_max=8,threads_min=4)"})
tcmalloc。tcmalloc 会优先将这些缓冲区返回到自己的缓存中,然后逐步将它们归还给操作系统。很多情况下,内存使用率高的原因是 tcmalloc 未能及时将内存归还给操作系统,导致内存最大可能达到几十GB。tcmalloc未归给操作系统的内存大小,可以通过命令db.serverStatus().tcmalloc.tcmalloc.formattedString或者
db.serverStatus().tcmalloc 查看。如下图所示,使用db.serverStatus().tcmalloc.tcmalloc.formattedString查询内存信息。其中的Bytes in use by application对应的内存指 Mongod 节点实际消耗的内存,Bytes in page heap freelist 为未归还给操作系统的内存。
tcmallocReleaseRate是一个用于控制内存释放的参数,它指定了当内存占用超过一定比例时,应该释放多少内存。tcmallocReleaseRate的值越高,MongoDB 释放内存的速度就越快,但是也会对性能产生一定的影响。在配置tcmallocReleaseRate时需要根据实际情况进行调整,以平衡内存使用和性能需求。执行如下命令,可配置tcmallocReleaseRate的值,其取值范围为[1,10]。diagnosticDataCollectionVerboseTCMalloc 为 true 时,可直接暴力回收内存,执行方式,如下所示:db.adminCommand( { setParameter: 1, tcmallocReleaseRate: 5.0 } )db.runCommand( { setParameter: 1, diagnosticDataCollectionVerboseTCMalloc:true} )
tcmallocReleaseRate 适用于云数据库 MongoDB 4.2及其之上的版本,且数据库实例为副本集。diagnosticDataCollectionVerboseTCMalloc 适用于云数据库 MongoDB 4.4及其之上的版本,且数据库实例为副本集。use <database>;db.getCollectionNames().filter(function(c) { return !c.startsWith("system."); }).lengthdb.getCollectionNames().forEach(function(col) { print("Indexes for " + col + ": " + db.getCollection(col).getIndexes().length); })
mongos> db.getCollectionNames().filter(function(c) { return !c.startsWith("system."); }).length4
mongos> db.getCollectionNames().forEach(function(col) { print("Indexes for " + col + ": " + db.getCollection(col).getIndexes().length); })Indexes for nba: 3Indexes for t1: 1Indexes for test: 1Indexes for user: 1
buffer用于数据回放。在 MongoDB 4.2版本之前,主节点通过非后台方式创建索引时,后端回放创建索引是串行的,最多可能消耗500M内存。而在 MongoDB 4.2版本之后,默认废弃了 background 选项,允许从节点并行回放创建索引,导致消耗更多的内存。因此,如果在多个索引同时创建时,可能会导致实例内存溢出。另外,从节点在数据回放过程中也可能会消耗更多的内存,特别是在主节点完成索引创建后。


文档反馈