I am facing an issue where our primary instance of mongodb shows high memory consumption every night. & i was going through the metrics and could see the cache size being reduced and used memory going up. I looked at the logs in mongodb but couldn't really figure the reason why memory kept on increasing in the first place.

I'm attaching a memory consumption screenshot for your reference.

enter image description here

enter image description here

Any approaches/clarifications are welcome.


  • If this happens on a nightly basis I would try to correlate the increase in memory usage with other activity. For example, an increase in application requests or scheduled jobs/backups that may need to load more data & indexes. However, per JJussi's answer it is expected that available memory will be used if needed so this isn't necessarily a problem. It would be helpful to have more context on your question: is there a performance impact or are you just curious about what is consuming memory?
    – Stennie
    Jul 23 at 10:02

This situation is just normal. MongoD process will eventually use all free memory, if active data size (including indexes) is larger than free memory (what is free without mongoD).

This is because mongoD process tries to keep all (active) data (and indexes) in the memory. Just for faster access.

This is why, it is recommended that you don't try to run any other services on that same node where mongoD process is running.

If your base system is unix/linux, you can use cgroup to limit memory what mongoD process see.

  • thanks for the reply @jjussi . No other process is being run on the mongo node. If you can clarify a couple of things, it'll be really helpful. 1. What exactly lies in the used & cached memory ? 2. How do I calculate active data size ? db.stats() ? 3. Assuming, if the data size is actually way bigger, what's the way forward ?sharding ? Also, what could be the implications of using cgroups to restrict memory in terms of performance or server stability ? Jun 29 at 8:28
  • 1
    As long as that mongoD process is only service on that node, you don't need to be worry about how much memory that process uses. You can follow "page fault" value and if that starts rising, then you start thinking is there enough memory on the node or "should I start sharding". Page fault tells you how many times mongod needs to swap data between memory and disk (client ask some data what is not in the memory, system needs to write something from memory to disk, before it can read new data to the memory from the disk)
    – JJussi
    Jul 8 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.