代码改变世界

mongodb对内存的使用

2023-02-07 13:16  abce  阅读(100)  评论(0编辑  收藏  举报

1.默认的分配策略

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.

即(总内存×50%-1GB)和(256MB)两者中的较大值。

2.配置内存

storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
  mmapv1:
    smallFiles: true
  wiredTiger:
    engineConfig:
      configString : cache_size=160M

3.查看mongodb对内存的使用:

> db.serverStatus().mem
{ "bits" : 64, "resident" : 7316, "virtual" : 9530, "supported" : true }	

 

目前有4个可配置参数支持WiredTiger存储引擎的驱逐策略(一般情况下无需修改),即
参数
默认值
描述
eviction_target
80
当cache被使用量超过该阈值,后台驱逐线程开始将一些数据页从缓存中移除干净页
eviction_trigger
95
当cache被使用量超过该阈值,用户线程开始将一些数据页从缓存中移除干净页
eviction_dirty_target
5
当cache被使用量超过该阈值,后台驱逐线程开始将一些数据页从缓存中移除脏页
eviction_dirty_trigger
20
当cache被使用量超过该阈值,用户线程开始将一些数据页从缓存中移除脏页