我有以下配置:
Redis和Mongodb都用于存储大量数据。我知道Redis需要将所有数据保存在RAM中,我对此很好。不幸的是,发生的事情是Mongo开始占用大量RAM并且一旦主机RAM满了(我们在这里谈论32GB),Mongo或Redis都会崩溃。
我之前已经阅读了以下有关此问题:
it's completely okay to limit the WiredTiger cache size, since it handles I/O operations pretty efficiently
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 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.
现在我似乎从所有这些答案中理解的是:
考虑到这一点,我希望Mongo尝试尽可能多地使用RAM空间,但是能够在没有RAM空间的情况下运行并从磁盘中获取大部分内容。但是,我通过使用--memory
和--memory-swap
来限制Mongo Docker容器的内存(例如8GB),但不是从磁盘中取出东西,Mongo只是在它耗尽时就崩溃了记忆。
如何强制Mongo仅使用可用内存并从磁盘中获取不适合内存的所有内容?
答案 0 :(得分:4)
感谢@ AlexBlex的评论,我解决了我的问题。显然问题在于Docker将容器的RAM限制为8GB
,但是有线网络存储引擎仍在尝试用尽其总系统RAM的50% - 1GB
缓存(其中)在我的情况下会是15 GB
)。
使用this configuration option使用低于Docker分配的值解决问题,限制了wireTiger的缓存大小。