Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js supports multiple load balance across servers?

Im curious about horizontal scalling in node.js is possible to load balance acrross multiple virtual servers like rackspace cloud servers? I read about cluster plugin but I think it is only for a single server with a multi core cpu.

like image 667
Christian Avatar asked Jul 05 '11 17:07

Christian


People also ask

How does node js handle load balancing?

To configure load balancing, you first create a named “upstream group,” which lists the backend servers. You then set up NGINX Open Source or NGINX Plus as a reverse proxy and load balancer by referring to the upstream group in one or more proxy_pass directives. Configure an upstream group called nodejs with two Node.

Can a single node use multiple servers?

While the single application server node is only allowed to influence the working resources of a single host. The cluster is allowed to work with multiple hosts and distributes the application across the servers.

Can we do load balancing with one server?

It's pointless to load balance a single server. What load balancing does is decide which server to use based on some criteria (typically load). You could have a load balance installed, but it wouldn't be serving any purpose. Another major reason for multiple servers isn't load balancing, but redundancy.

How does multiple load balancer work?

Multiple Load Balancers for Redundancy and Scalability This allows you to have multiple incoming connections each serving up the same content, providing a redundant load balancing layer as well as a redundant application layer.


1 Answers

Try roundrobin.js for node-http-proxy:

var httpProxy = require('http-proxy');
//
// A simple round-robin load balancing strategy.
//
// First, list the servers you want to use in your rotation.
//
var addresses = [
  {
    host: 'ws1.0.0.0',
    port: 80
  },
  {
    host: 'ws2.0.0.0',
    port: 80
  }
];

httpProxy.createServer(function (req, res, proxy) {
  //
  // On each request, get the first location from the list...
  //
  var target = addresses.shift();

  //
  // ...then proxy to the server whose 'turn' it is...
  //
  proxy.proxyRequest(req, res, target);

  //
  // ...and then the server you just used becomes the last item in the list.
  //
  addresses.push(target);
});

// Rinse; repeat; enjoy.
like image 122
psema4 Avatar answered Oct 05 '22 08:10

psema4