【发布时间】:2017-12-04 17:46:14
【问题描述】:
我有以下配置:
- 运行三个 docker 容器的主机:
- MongoDB
- Redis
- 使用前两个容器存储数据的程序
Redis 和 Mongodb 都用于存储大量数据。我知道 Redis 需要将其所有数据保存在 RAM 中,我对此很好。不幸的是,Mongo 开始占用大量 RAM,一旦主机 RAM 已满(我们在这里讨论的是 32GB),Mongo 或 Redis 就会崩溃。
我已阅读以下有关此问题的先前问题:
- Limit MongoDB RAM Usage: 显然大部分 RAM 都被 WiredTiger 缓存用完了
- MongoDB limit memory: 显然问题出在日志数据上
- Limit the RAM memory usage in MongoDB:这里他们建议限制 mongo 的内存,使其缓存/日志/数据使用较少的内存
-
MongoDB using too much memory:这里他们说它是 WiredTiger 缓存系统,它倾向于使用尽可能多的 RAM 来提供更快的访问。他们还声明
it's completely okay to limit the WiredTiger cache size, since it handles I/O operations pretty efficiently -
Is there any option to limit mongodb memory usage?:再次缓存,他们还添加了
MongoDB uses the LRU (Least Recently Used) cache algorithm to determine which "pages" to release, you will find some more information in these two questions -
MongoDB index/RAM relationship:引用:
MongoDB keeps what it can of the indexes in RAM. They'll be swaped out on an LRU basis. You'll often see documentation that suggests you should keep your "working set" in memory: if the portions of index you're actually accessing fit in memory, you'll be fine. - how to release the caching which is used by Mongodb?: 答案与 5 相同。
现在我似乎从所有这些答案中理解的是:
- 为了更快地访问,Mongo 最好将所有索引都放入 RAM 中。但是,在我的情况下,我可以使用部分驻留在磁盘上的索引,因为我有一个非常快的 SSD。
- RAM 主要用于 Mongo 的缓存。
考虑到这一点,我期待 Mongo 尝试使用尽可能多的 RAM 空间,但也能够在很少的 RAM 空间下运行并从磁盘获取大部分内容。但是,我通过使用 --memory 和 --memory-swap 限制了 Mongo Docker 容器的内存(例如 8GB),但是 Mongo 没有从磁盘中获取内容,而是在内存不足时立即崩溃。
如何强制 Mongo 仅使用可用内存并从磁盘中获取不适合内存的所有内容?
【问题讨论】:
-
这确实更适合DBA site 或Server Fault,因为它是关于数据库服务器软件,而不是应用程序代码。
-
好的,管理员可以移动它。我应该对此做些什么吗?
-
(虽然我链接的大多数问题都来自 StackOverflow)
-
其中一些问题早于这两个网站。关于这两个与 MongoDB 相关的每个问题都有约 1500 多个问题。如果是关于设置,我会说服务器故障站点。如果是调优,DBA。
-
很好的研究工作,但问题本身很模糊。存储配置和实际错误消息是关键缺失位。理想情况下,如果您可以共享 Dockerfile 和最简单的 mgenerate 来重现问题。 docs.mongodb.com/manual/reference/configuration-options/… 中有一个特别说明,mongodb 在无法访问整个内存的容器中运行。