I understand that cluster.fork will allow for multiple processes to listen on the same port(s), what I also want to know is how much additional overhead is there in supporti
cluser.fork
is implemented on top of child_process.fork
. The extra stuff that cluster.fork
brings is that, it will enable you to listen on a shared port. If you don't want it, just use child_process.fork
. So yeah, use cluster for web servers and child_process for workers.
Cluster is a module of Node.js that contains sets of functions and properties that helps the developers for forking processes through which they can take advantage of the multi-core system. With the cluster module, the creation and sharing of child processes and several parts become easy. In a single thread, the individual instance of node.js runs specifically and to take advantage of various ecosystems, a cluster of node.js is launched, to distribute the load.
A developer can access Operating System functionalities by the child_process module, this happens by running any system command inside a child process. The child process input streams can be controlled and the developer can also listen to the output stream. A child process can be easily spun using Node’s child_process module and these child processes can easily communicate with each other with the help of a messaging system