# How much memory needed by MongoDB?

**URL:** <https://forums.percona.com/t/how-much-memory-needed-by-mongodb/38358>\
**Category:** Percona Server for MongoDB\
**Tags:** community, percona, mongodb\
**Created:** [June 17, 2025, 1:03pm UTC](https://forums.percona.com/t/how-much-memory-needed-by-mongodb/38358 "2025-06-17T13:03:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gianni](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@gianni](https://forums.percona.com/u/gianni)\
**Post date:** [June 17, 2025, 1:03pm UTC](https://forums.percona.com/t/how-much-memory-needed-by-mongodb/38358/1 "2025-06-17T13:03:02Z")

</div>

Hi there,  
I need to correctly size MongoDB dedicated memory in my architecture.

I have a 3 node Replica Set running on Docker Swarm with other services.

I started with no memory limits (containers see the total amount of RAM of the host) and I’ve found that MongoDB is eating up memory day by day (even more than 10GB in my case) because he usually use 50% of RAM for wiredTiger cache and seems not to release it (or release very slow). The 50% rule can probably be good if the machine is MongoDB dedicated but if you have other services (like me) this leads the machine to swap a lot in the long term (solved with reboots in last months).

Now I’m digging into it and I’ve found I can limit the memory on container via Docker and/or via `--wiredTigerCacheSizeGB` option directly from `mongod`.

I’m trying with 6GB limit on containers letting MongoDB managing the wiredTiger cache size (`db.serverStatus().wiredTiger.cache['maximum bytes configured']` reports 2.5 GB).

Actual usage (from `docker stats`):

Percona MongoDB 8.0

```auto
Primary node mem usage 5.417GiB / 6GiB
Secondary node mem usage 2.595GiB / 6GiB
Secondary node mem usage 2.711GiB / 6GiB

```

Primary (`db.serverStatus().wiredTiger.cache` formatted)

```auto
{
  'maximum bytes configured': '2.50 GB',
  'bytes currently in the cache': '2.00 GB',
  'tracked dirty bytes in the cache': '0.01 GB'
}

```

Secondary (`db.serverStatus().wiredTiger.cache` formatted)

```auto
{
  'maximum bytes configured': '2.50 GB',
  'bytes currently in the cache': '2.00 GB',
  'tracked dirty bytes in the cache': '0.01 GB'
}

```

Secondary (`db.serverStatus().wiredTiger.cache` formatted)

```auto
{
  'maximum bytes configured': '2.50 GB',
  'bytes currently in the cache': '1.68 GB',
  'tracked dirty bytes in the cache': '0.01 GB'
}

```

Primary container is on 90% usage and the memory warning is often triggered.

Is this primary/secondary difference ok?

This means that the primary is using 3.417GiB (5.417GiB - 2.00 GB) of RAM that is not wiredTiger cache?

Do you know approximately how much RAM MongoDB needs, net of cache?  
Is this proportional to the number/size of dbs to be managed?

I’m still studying so corrections and suggestions are appreciated 😉

Thanks in advance for the patience 🙂

---

<div class="post-metadata">

**Author:** ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)\
**Post date:** [June 19, 2025, 12:08pm UTC](https://forums.percona.com/t/how-much-memory-needed-by-mongodb/38358/2 "2025-06-19T12:08:14Z")

</div>

Hi, memory difference between primary and secondaries is expected, as most of the time the usage patterns are different.  
MongoDB leverages both OS caches and its own cache (WTcache) so typically you dedicate half your system memory to each.

---

<div class="post-metadata">

**Author:** ![gianni](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@gianni](https://forums.percona.com/u/gianni)\
**Post date:** [June 19, 2025, 3:53pm UTC](https://forums.percona.com/t/how-much-memory-needed-by-mongodb/38358/3 "2025-06-19T15:53:14Z")

</div>

Hi Ivan, thanks for your reply.

Still don’t get if I can predict someway how much RAM MongoDB primary needs.

I’m trying to increase it 1GB at a time but seems that after a couple of days it always reach 90% and our monitoring system trigger a memory warning marking the service as unhealthy.

Is this a false-positive?  
Can I still consider the service as healthy?  
In this case how can I recognise an unhealthy service if I cannot relay to mem usage?

Thanks in advance for the patience 🙂

---

<div class="post-metadata">

**Author:** ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)\
**Post date:** [June 19, 2025, 4:43pm UTC](https://forums.percona.com/t/how-much-memory-needed-by-mongodb/38358/4 "2025-06-19T16:43:55Z")

</div>

It is not straight forward to predict. Memory usage will be impacted by the size of your data but also number of client connections.  
I would suggest using a different criteria for checking unhealthy service, for example you can have a script running a query and measure the response time/check for timeout.

---

<div class="post-metadata">

**Author:** ![gianni](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@gianni](https://forums.percona.com/u/gianni)\
**Post date:** [June 20, 2025, 8:58am UTC](https://forums.percona.com/t/how-much-memory-needed-by-mongodb/38358/5 "2025-06-20T08:58:49Z")

</div>

Thanks for the hint 👍
