mongodb 3.2配置内存缓存大小为MB/MongoDB 3.x内存限制配wiredTigerCacheSizeGB

mongodb 3.2配置内存缓存大小为MB/MongoDB 3.x内存限制配置

mongodb占用内存非常高,这是因为官方为了提升存储的效率,设计就这么设计的。

但是大部分的个人开发者所购买的服务器内存并没有那么大,所以,我们需要配置下MongoDB的内存缓存大小,不然mongodb会占用非常多。

WiredTiger Options

- -wiredTigerCacheSizeGB number
New in version 3.0.

Defines the maximum size of the internal cache that WiredTiger will use for all data.

With WiredTiger, MongoDB utilizes both the WiredTiger internal cache and the filesystem cache.

Changed in version 3.2: Starting in MongoDB 3.2, the WiredTiger internal cache, by default, will use the larger of either:

  • 60% of RAM minus 1 GB, or
  • 1 GB.

mongodb会尽可能的把所有的数据都缓存,以便提高效率。

以mongodb 3.2为例,WiredTiger内部缓存,默认会用掉

  • 60% * 内存 - 1GB
  • 1GB

当你的内存大于1GB,mongodb会用掉 内存的60% - 1GB 的内存作为缓存;

当你的内存小于1GB,mongodb会直接用掉1GB。

另外,MongoDB 3.4与3.2也是有区别的

MongoDB 3.4该配置项为:
参考官方demo
https://docs.mongodb.com/v3.4/reference/configuration-options/#storage-options

storage.wiredTiger.engineConfig.cacheSizeGB

Type: float

The maximum size of the internal cache that WiredTiger will use for all data.

Changed in version 3.4: Values can range from 256MB to 10TB and can be a float. In addition, the default value has also changed.

Starting in 3.4, the WiredTiger internal cache, by default, will use the larger of either:

  • 50% of RAM minus 1 GB, or
  • 256 MB.

参考配置:
https://jira.mongodb.org/browse/SERVER-22274

下面是修改后的配置:/etc/mongod.conf

Where and how to store data.

storage:
   dbPath: /var/lib/mongo
   #dbPath: /mongodata
   journal:
     enabled: true
#  engine:
   mmapv1:
     smallFiles: true
   wiredTiger:
     engineConfig:
       configString : cache_size=512M

在docker-compose.yml中配置

可参考
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值