Mongod "out of memory" on startup

A few good piece of advice in here:

I think you are fine with a swappiness at 50 when mongod is starting. But then your linux might be more tempted to use the swap if you are starting some more RAM intensive activities. I guess what you could do is reduce the swappiness once mongod is started so the system is less tempted to use the swap once the startup is done.

Also, make sure to monitor your swap usage at this point. If your mongod starts using the swap after the startup - I guess you definitely need more RAM then.

What I’m about to say is really not accurate and should not be taking for an absolute truth, but usually I would recommend to have about 10-20% of the node size in RAM.

So for example if you have a 200GB replica set (200GB per node). I would have around 20 to 40GB of RAM. Unless there is really something out of the ordinary going on, this should leave you plenty of RAM for the indexes which should represent about 10-20% of the RAM and the rest is for mongod to keep frequently queried documents in RAM and resolve queries.

This ratio didn’t fall completely from the sky though. It’s my feeling, but it’s also more or less the ratio you get by default when you take a cluster on MongoDB Atlas.

I hope this helps.

Cheers,
Maxime.

1 Like