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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With