I have been experimenting clustering in NodeJS (https://nodejs.org/api/cluster.html) and was able to cluster my server.
I have a mongodb connection which gets established when server starts
Earlier this was not a problem since it gets established once (without cluster).
I think, with clustering it establishes once for every cluster (I am unclear about this).
So, should the connection be done once for the entire server (or) once for every worker (or) only for master process?
Which is the recommended way and how can it be achieved?
Thanks in advance.
Connection should be done once for every process. The important thing is however not to mix sessions. I would recommend connect-mongo for sessions and once client establishes session on one of the workers, it should not use any other instance for operations related to this client. This way you can also keep cache for clients on their respectable server instances.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With