Resource footprint of mongod if run in daemon mode

Hi everyone :wave:

I was curious about whether running mongo in daemon mode increases initial resource usage or not. If it does, how much?

I have not looked into the source code yet, this is just an educated guess - I don’t think it matters much. There would be a slight increase after the initial launch due to the parent process lingering, but that’s negligible.

Here’s why -

  • I assume if --fork is used, mongod would create a new process and everything, i.e. memory allocation, data initialization, etc, is going to be performed in this child process. The parent is left with nothing but detecting when the child is ready for connections and finally exiting, which I assume uses nothing but a simple loop.

A pseudo-code version of this would look something like -

  IF "--fork" in ARGV:
    pid = fork()
    IF pid == 0:
  • Since the child is created at a very early stage, the memory pages copied to the child, is far far far less than an actual fully functional mongod process. Therefore, the theoretical resulting increase in resource usage is non-perceivable.

  • With CoW, duplicate pages are not copied unless something’s modified by the child. This reduces the memory usage even further, assuming there’s more to main() than being just a path to main_mongod().

Any response is appreciated. Thanks in advance :slightly_smiling_face:

Forked or not the resources used will be more or less the same. RAM will be reserved by the storage engine the same.

I am curious to know why you care?

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