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.
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.
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.
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.
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.
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.
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