mongodb 6、mongodb内存使用优化

本文分析了当MongoDB中的记录数达到千万级别时,内存使用达到几十G导致的问题。通过检查数据库状态,了解到MongoDB的索引可能导致内存占用增大。在3.4版本中,可以通过调整wiredTiger内部缓存大小限制到10GB来缓解,但文件系统缓存不受控制。MongoDB的缓存淘汰策略包括多个参数,用于控制内存使用。解决方法包括调整wiredTiger.cacheSizeGB和在Kubernetes环境中限制资源使用。
摘要由CSDN通过智能技术生成

1 问题


mongodb中某collection的记录数达到几千万级别的时候,mongodb占据的内存达到几十G,
节点内存耗尽,宕机

2 分析


2.1 问题定位


登陆mongodb,查看mongodb的服务状态
db.stats()
结果如下:
collections: 10
objects: 22591647
avgObjSize: 1204左右
dataSize: 27205964928
storageSize: 5663232000
indexes: 39
indexSize: 14344634368
ok: 1

2.2 mongodb索引


mongodb会将最近常用的值保存在RAM中,就有可能导致占用的内存变大。
官网描述如下:
Indexes that Hold Only Recent Values in RAM
Indexes do not have to fit entirely into RAM in all cases. If the value of the indexed field increments with every insert, and most queries select recently added documents; then MongoDB only needs to keep the parts of the index that hold the most recent or “right-most” values in RAM. This allows for efficient index use for read and write operations and minimize the amount of RAM required to support the index.

参考:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值