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

Colin 't Hart
9,51015 gold badges37 silver badges44 bronze badges
asked Dec 13, 2014 at 10:28
0

5 Answers 5

5

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

Paul White
95.3k30 gold badges439 silver badges689 bronze badges
answered Apr 11, 2016 at 23:45
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.

answered Aug 28, 2015 at 14:48
2

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.

mustaccio
28.6k24 gold badges60 silver badges77 bronze badges
answered Jun 18, 2021 at 13:30
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

answered May 3, 2016 at 22:57
-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

answered Dec 13, 2014 at 18:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.