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中配置

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

猜你喜欢

转载自blog.csdn.net/weixin_43944305/article/details/113572854