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