Memory allocated per connection

How much memory is allocated by default per connection?

1 Like

Hi @Kim_Hakseon,

Each connection consumes at least1MB of RAM. I believe this mentioned in a few places in the documentation, but didn’t find the reference I was looking for on a quick search.

This blurb from the MongoDB Atlas Best Practices is relevant:

MongoDB drivers implement connection pooling to facilitate efficient use of resources. Each connection consumes 1MB of RAM, so be careful to monitor the total number of connections so they do not overwhelm RAM and reduce the available memory for the working set. This typically happens when client applications do not properly close their connections, or with Java in particular, that relies on garbage collection to close the connections.

Additional RAM may be allocated for in-memory processing such as aggregation or in-memory sorting. Typically there is a memory limit to prevent one connection from consuming all server resources. The Limits: Operations section of the MongoDB manual has more details.

Regards,
Stennie

I thought I could check it somewhere in the manual, but I couldn’t find it, so I asked.

Thank you very much.

1 Like

Hi @Kim_Hakseon,

It’s a great question – thanks for asking! I didn’t find the reference in a quick search, either, but I do know the default stack size per thread has been 1MB since MongoDB 2.0.

The documentation section I was thinking of still exists in the 4.0 and earlier manual versions: How do I calculate how much RAM I need for my application?.

There’s an open issue in the docs backlog which you can upvote & comment on: DOCS-12986: Add information about Connection Memory Consumption.

It looks like this section was removed when the documentation was being revised for the MongoDB 4.2 release. The docs concern appears to be that the existing description didn’t provide enough guidance for the FAQ topic of “How do I calculate how much RAM I need for my application?” (which is potentially a full standalone tutorial/course!).

I’ll bring this to the attention of the docs team, as we should have some mention of the connection-per-thread memory usage. Thanks again for asking the question!

Regards,
Stennie

1 Like

I am more grateful for your kind and quick reply.

Thank you :smiley:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.