Mongo in primary takes 128gb ram and shutdown

Hello everyone, greetings to all.

We have been facing an issue for some time where our primary node crashes after running for a while.

What we have observed is that memory usage gradually increases until it reaches the maximum available, which is currently 128GB. A significant portion of swap is also used, but not entirely.

From our perspective, it seems necessary to find a way to limit MongoDB’s RAM consumption, but so far, we haven’t found a proper solution for this.

Here are some details about our setup:

  • Total database size on disk: ~360GB

  • Operating system: Ubuntu 18.04

  • Machine specs: 16 vCPUs, 128GB RAM

  • Storage: 1TB SSD
    *MongoDB version: 6.0.19
    Some MongoDB configurations:

  • maxSessions: 2,000,000

  • defaultWriteConcern: 1

If anyone has insights or recommendations on how to handle this issue, we would greatly appreciate your help.

Thank you in advance!

Hi @Eder_Neves, welcome to the Community Forums.

Let’s go, by default MongoDB uses 50% + 1 GB of the RAM available on the server, so if the settings have not been changed, it may not actually be MongoDB’s direct consumption.

To limit RAM usage, you can edit the mongod.conf file and set a value in GB, remembering that it is not recommended that this value be greater than 80% of the total memory. Use the storage > wiredTiger > engineConfig > cacheSizeGB section to do this:

storage:
  wiredTiger:
    engineConfig:
         cacheSizeGB: <number>

https://www.mongodb.com/docs/manual/reference/configuration-options/#mongodb-setting-storage.wiredTiger.engineConfig.cacheSizeGB

Also remember that each connection will consume 1 MB of RAM, and pool management is also important.

Let me know if you have any more relevant information, or if this has been resolved.

Best,

Leandro Domingues

1 Like

Hi Leandro, it’s a pleasure to see you again!

We’ve tried several different values for the cache limit to control Mongo’s memory usage, but the issue still persists.

As our DBA said to me, our cacheSizeGB in primary is not defined, so it’s using 64GB.
Checking process we get mongod using 88.5%(111.46GB) of total memory (128GB)

Hello again,

We’ve reviewed the connections on our end, and the average is around 300. The memory usage of Mongo on the machine still appears rather unusual to me