8

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).

0
6

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
3

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.

1

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

1

If you are running MongoDB 3.2 or later version, you can limit the wiredTiger cache as shown below.

In /etc/mongod.conf add the wiredTiger part

...
# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
  wiredTiger:
    engineConfig:
        cacheSizeGB: 3 # You can set any integer
...

Don't forget to restart mongo after editing the config.

-1

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

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.