4

I recently started with node and I have been reading a lot about its limitation of it being single threaded and how it does not utilise your cores and then I read this

http://bit.ly/1n2YW68 (which talk about the new cluster module of nodejs for loadbalancing)

Now I'm not sure I completely agree to it :) because the first thing that I thought of before starting with node on how to make it utilise cores with proper load balancing is via web-server some like upstream module like nginx

like doing something like this

 upstream domain1 {
   server http://nodeapp1;
   server http://nodeapp2;
   server http://nodeapp3;
 }

So my question is there an advantage to use such cluster module for load balancing to utilise the cores does it has any significant advantage over web server load balancing or is blog post too far from real use.

Note: I'm ain't concerned about load balancing handle by various app server like passenger(passenger has nodejs support as well but something that I'm not looking for answer :)) which I already know since I'm mostly a ruby programmer

mcfedr
  • 7,845
  • 3
  • 31
  • 27
Ratatouille
  • 1,372
  • 5
  • 23
  • 50

2 Answers2

2

One other option you can use to cluster NodeJs applications is to deploy the app using PM2.

Clustering is just easy as this, You don't need to implement clustering by hand

pm2 start app.js -i max

PM2 is an expert to auto detect the number of available CPUs and run as many processes as possible

Read about PM2 cluster mode here http://pm2.keymetrics.io/docs/usage/cluster-mode/

For controlling the load of IO operations, I wrote a library called QueueP using the memoization concept. You can even customize the memoization logic and gain speedup values of more than 10, sometimes

https://www.npmjs.com/package/queuep

Pubudu Dodangoda
  • 2,742
  • 2
  • 22
  • 38
0

As far as I know, the built in node cluster is not a good solution yet (load is not evenly distributed across cores). Until v0.12: http://strongloop.com/strongblog/whats-new-in-node-js-v0-12-cluster-round-robin-load-balancing/

So you should use nginx until then. After that we will see some benchmarks comparing both options and see if the built in cluster module is a good choice.

Salvatorelab
  • 11,614
  • 6
  • 53
  • 80
  • 1
    I did read that even with round robin what benefit does it offer since I believe nginx upstream too use round robin scheduling policy in event of load (i.e for load balancing) – Ratatouille Jul 08 '14 at 09:39
  • there is a difference: with clustering you can send information from workers to the parent and viceversa (example: count number of requests served by all workers). but regarding performance, I don't know if there is any advantage on using clustering or nginx sorry, that's an interesting question. – Salvatorelab Jul 08 '14 at 11:08