Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

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.

like image 324
Tracker1 Avatar asked Nov 13 '12 19:11

Tracker1


People also ask

What is the difference between node js child process and clusters?

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. With the help of a cluster module, child processes can be created very easily sharing the server ports.

What is the main benefit of worker threads above Clusterization and spawning children processes?

Worker threads can be used to solve the above-mentioned caveats with child processes because worker threads share memory and communication between threads is possible. Essentially the difference between worker threads and child processes is same as the difference between a thread and a process.

What is cluster fork?

3.3. Cluster-Fork. Cluster-Fork runs a command on compute nodes of your cluster. Often we want to execute parallel jobs consisting of standard UNIX commands. By "parallel" we mean the same command runs on multiple nodes of the cluster.


1 Answers

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.

like image 82
Farid Nouri Neshat Avatar answered Oct 20 '22 10:10

Farid Nouri Neshat