Poised - HTTP Load Balancer in Node
Why not HAProxy?
Poise at its core, aims to have most of the featureset that HAPRoxy has. If you can get away with using HAProxy, you should! If you need more... read on.
More Flexibility
With poised, you can script load balancing logic as opposed to declaritively configure it. You can also define when to add and evict servers.
Node Integration
Poised can run standalone (see examples), but it can also be integrated into node. If you are running node in your stack, this means you can resolve your servers within your actual process instead of going through another proxy.
Quick Start
Here is an example script load balancing 2 http servers:
var poised = ;var http = poised; var front = http;front; var back = front;back;back;
Just save this in a file and run "node ".
Documentation
http
This defines the protocol (only http for now) scope.
var poised = ;var http = poised;
front
This defines the front end of the proxy. You should have one front for each incomming port you are listening to.
var www = http;www;
back
This defines backends to route to. Here, you can define which cluster of servers you want to route to.
var staticBack = www;var wwwBack = www;wwwBack;staticBack;
You can also define backups to backs:
var backup = back;backup;
This creates a backup to the back. Backup's abide by the same api as backs.
server
This introduces a server if to a back cluster.
var server1 = wwwBack;server1; var server2 = wwwBack;var server3 = wwwBack;
Load balancing algorithms
Load balancing is set on the "back" object and defines how it chooses a server to hand the request to. By default, load balancing is done using the roundrobin algorithm, but can use several different algorithms.
back.balance({ algorithm: 'weighted', interval: 10000 });
Standard options:
- algorithm: algorithm to use for balancing
- interval: the amount of time (in milliseconds) between each "shuffle" or rebalance. For instance, the above code will recheck and rebalance the ratios on how to distrubute the payload every 10 seconds.
roundrobin
This is the default way poise balances if none is defined. The "interval" option is not applicable.
back;
weighted
Takes the average response times for each server and redistrubutes load accordingly. For instance, if a server was twice as fast as another, it would get twice as much traffic.
back;
resource
Makes requests "stick" to specific servers depending on which attribute to hash by.
back;
Advanced Usage
back;
{ var server = back; ;}
Author
Jeff Su