5

I am using MongoDB-2.6.1. Is there any way to limit the RAM memory usage?

For example: Out of 4 GB RAM, let MongoDB use till 3 GB (<= 3 GB).

migrated from stackoverflow.com Dec 13 '14 at 16:55

This question came from our site for professional and enthusiast programmers.

  • You can play with ulimits might achieve a workaround but i am curious why you want to do that? – Antonios Dec 14 '14 at 12:20
2

IIRC MongoDB doesn't directly use memory for data, it uses memory mapped files and lets the OS manage how much is loaded via the normal VFS behaviour. Changing per-process limits is unlikely to affect this.

You don't state what platform you are using at all, but if you are already using virtualisation could you could run Mongo in its own VM with a RAM allocation set to the memory you want Mongo to use plus some extra for the guest OS. You could also start using virtualisation for this reason but be aware there is likely to be an efficiency hit switching from a physical box to a VM.

2

If you are running on Linux, you can use control groups to limit MongoDB memory as shown in the following article:

Easy Steps to Limit Mongodb Memory Usage by Ramakanta Sahoo

On Windows, a similar technique using the Windows System Resource Manager is described in:

Limit MongoDB memory use on Windows without Virtualization by Simon Green

0

Working only with MongoDB, the answer to your question is no.

What operating system are you using? Why do you want to limit Mongo's RAM usage?

Scott

0

Answer from user1472187 will work, but unfortunately these settings won’t last a reboot. You need to add some init scripts: http://frank2.net/cgroups-ubuntu-14-04/

Shell script is available for Ubuntu 14.04: http://brainsuckerna.blogspot.com.by/2016/05/limiting-mongodb-memory-usage-with.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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