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

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 supporting this when some of your workers are not listeners/handlers for the tcp service?


I have a service that I also want to launch a couple of workers.. ex: 2 web service listener processes, and 3 worker instances. Is it best to use cluster for them all, or would cluster for the 2 web services, and child_process for the workers be better?


I don't know the internals in node, but think it would be nice for myself and others to have a better understanding of which route to take given different needs. For now, I'm using cluster for all the processes.


1 个解决方案



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.

cluser.fork是在child_process.fork之上实现的。 cluster.fork带来的额外功能是,它可以让你在共享端口上侦听。如果你不想要它,只需使用child_process.fork。所以,是的,使用集群用于Web服务器,使用child_process用于工作者。



© 2014-2019 粤ICP备14056181号