mongodb - mongo 不遵守 Docker 内存限制

标签 mongodb unix docker memory memory-management

我遇到的问题是 mongodb 不遵守强加的容器内存限制并溢出到交换区并减慢爬行速度 - 问题似乎是 mongo 认为所有主机内存都可用。参见 https://github.com/dockerfile/mongodb/issues/34

我的问题是 - docker 如何实现内存限制?对于在 unix 中像这样限制资源访问的可用选项是什么,我真的没有一个全面的了解——有人可以快速概述一下吗?

谢谢

最佳答案

这里有几点。

首先,在你的容器中运行的任何进程都会相信它可以访问与你的主机一样多的内存(docker 不会虚拟化内存)

您可以通过设置参数--memory 来限制您的容器被授权使用的内存。您可以通过将 --memory-swap 设置为与 --memory 完全相同的值来禁用交换:

If --memory and --memory-swap are set to the same value, this prevents containers from using any swap. This is because --memory-swap is the amount of combined memory and swap that can be used, while --memory is only the amount of physical memory that can be used.

现在,请记住,即使您设置了 --memory 和 --memory-swap,您的应用程序 (mongoDB) 也会认为它可以访问主机系统的总内存。在 mongoDb 3.2 中,它将使用总内存的 60%,减去 1G。如果要限制这个,需要配置storage.wiredTiger.engineConfig.cacheSizeGB

storage.wiredTiger.engineConfig.cacheSizeGB: The maximum size of the internal cache that WiredTiger will use for all data.

在此处查看 mongoDB 文档:https://docs.mongodb.com/v3.2/reference/configuration-options/#storage.wiredTiger.engineConfig.cacheSizeGB

以及 docker 文档: https://docs.docker.com/config/containers/resource_constraints/#memory

关于mongodb - mongo 不遵守 Docker 内存限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49213117/

相关文章:

mongodb - 确保 MongoDB 以动态时间间隔使数据过期并且调用是幂等的

unix - 两个进程如何共享同一个共享库?

linux - 当 NFS 安装停止时,bash 检查目录是否存在挂起

php - 为 PHP docker 镜像安装/配置 SQL Server PDO 驱动程序

mysql - 无法将 MySQL 容器连接到 docker 中的 Tomcat 容器

mongodb - Mongodb 排序异常 - 没有索引的 sort() 数据太多

javascript - React Meteor、reactive prop 和内部状态

linux - MongoDB - 套接字 : 127. 0.0.1:27025 的权限被拒绝

c - SSL_CTX_new 中的段错误

azure - Azure Hortonworks CloudBreak主机文件不正确