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).
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
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:
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.
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
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
... # 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.