Limit MongoDB RAM Usage

2019-09-19 07:46发布

问题:

How can I limit MongoDB RAM usage?

I have a server with 1GB RAM.

When I insert 10000 rows 13 times, MongoDB uses almost 95%, and I have to have RAM for other tasks like CRONS.

I tried the "Easy Steps ... page" to do this, but it says that need mongod_pid, and I don't know what is that and where is, I only know that I don't use mongod, I've installed mongodb-server.

Everything was perfect until I saw that MongoDB uses almost all my RAM.

回答1:

It's most likely you have no reason to worry. The majority of the RAM used by mongodb is simply filesystem cache and the operating system has full control over this cache, i.e. it can free up memory if required by another process.

By default, with MongoDB 3.4, the larger of either "256 MB, or 50% minus 1 GB of total RAM" are reserved for the WiredTiger cache, and this is the only part that can't be freed up by the OS.

So you are unlikely to see any issues when running any cron jobs or such. As long as none of your processes are killed by the "out of memory (OOM) killer", you are not running out of RAM.