Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js Cluster vs Multiple Node.js instance

Tags:

node.js

I want to know the difference between:

 cluster.setupMaster({exec:'app.js'});
 for(let i=0;i<3;i++) {cluster.fork();}

and typing command 3 times:

 node app.js

It seems that for the internal library net, there are some Round-Robin fashioned load balancing mechanism available only in the first way, but not the second one as it is only separated node processes and there can be no synergy between them -- unless we add inter-process communication code. I'd like to know that other than this, are there any other profit we can get from only the first way?

-----------------------------Update------------------------------

Listing the items where one should take care of when modeling the 'cluster' vs plain multi-process is appreciated, but it would be better to describe the hidden IPC channels which is shipped with 'cluster' library.

like image 845
pu.guan Avatar asked Nov 30 '16 06:11

pu.guan


Video Answer


1 Answers

The main difference is that the three workers are accessed by outside apps as if they were one. So if you're running a web application, you could expose all three over the same HTTP port, as an example. If you tried just running the node app three times, you'd have to assign a different port to each and do your load balancing somewhere else.

like image 184
Paul Avatar answered Sep 27 '22 22:09

Paul