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

原创文章,转载请注明: 转载自勤奋的小青蛙
本文链接地址: 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该配置项为:

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.

 

这样显然很不合理,对于大部分的个人开发,内存是宝贵的。所以,我们需要配置为MB。

配置项参考此处配置:WiredTiger cache size is only configurable in whole gigabytes.

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

?

1

2

3

4

5

6

7

8

9

10

11

12

# 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

其实重点就是下面一项,配置之后,重启mongodb生效:

?

1

2

3

wiredTiger:

    engineConfig:

      configString : cache_size=512M

原创文章,转载请注明: 转载自勤奋的小青蛙
本文链接地址: mongodb 3.2配置内存缓存大小为MB/MongoDB 3.x内存限制配置

文章的脚注信息由WordPress的wp-posturl插件自动生成


 

|2|left

转载于:https://my.oschina.net/airship/blog/2251305

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值