I'm testing running monbodb on the kubernetes platform where I can limit the resources used by the running container.

Say I set the memory limit to 256Mb. The problem is that for example while making backup memory consumption increases to the limit and container gets restarted by kubernetes.

So the question is is there a way to limit mongodb memory consumption for my case so that it would not cause the crush by exeeding memory limit set by platform.

I could of course increase the limit but I'm interested in a principal solution and would like to understand this process better because I don't really now how memory consumed by mongodb and container os. Is it possible to tune mongodb/underlying linux os to work inside existing limits.

1 Answer 1


In normal situation, mongodb uses always all available memory!!

However, you can limit mongo's memory using cgroup.

Here is presentation what may help too.

  • What is all available memory? In terms of docker container?
    Commented Jul 10, 2017 at 18:25
  • Means that that wiredTiger cache eats 50% of RAM minus 1 GB and all rest of free memory is used for filesystemCache. In normal situation mongodb expects that it is only application in the machine, that's why you don't run multiple mongod instances in one machine.. All of them try use all memory.
    – JJussi
    Commented Jul 10, 2017 at 18:39
  • Do you know what happens in case of running in docker container how does it determine available memory?
    Commented Jul 10, 2017 at 18:42
  • I forgot to say, that cache (minimum) size is 256 MB, so more than 1024MB memory should be available. What comes to your question.. I haven't install mongodb on docker, but.. I though that it is normal Linux?!? So, mongod asks from OS how much memory is available and start using it.. ;-)
    – JJussi
    Commented Jul 10, 2017 at 18:46
  • 1
    And because in docker, you have other applications too, you must use cgroup and --wiredTigerCacheSizeGB to limit resources what mongod uses. (including cpu)
    – JJussi
    Commented Jul 10, 2017 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.