Hi everyone
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 -
FUNCTION MAIN_MONGOD
FUNCTION MAIN():
IF "--fork" in ARGV:
pid = fork()
IF pid == 0:
MAIN_MONGOD(ARGV)
ELSE:
CHECK_MONGOD_CONNECTION_REDINESS_AND_EXIT(pid)
ELSE:
MAIN_MONGOD(ARGV)
END
-
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 tomain_mongod()
.
Any response is appreciated. Thanks in advance