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.
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.