What are the effective differences between child_process.fork and cluster.fork?

后端 未结 2 1816
自闭症患者
自闭症患者 2021-01-02 01:28

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

相关标签:
2条回答
  • 2021-01-02 02:19

    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.

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题