This package has been deprecated

Author message:

Use the load-balancers package instead.

arrow-function-load-balancer
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Load Balancers for Node

Build Status Coverage Status Dependency Status Dev. Dependency Status NPM version

Installation

npm install --save arrow-function-load-balancer

Comparison of Load Balancers

  • The Random Balancer is a bit chaotic; it doesn't distribute requests as evenly as one would think because there's no such thing as perfect randomness.
  • The Power of Two Choices (P2c) Balancer comes very close to the ideal load balancer. Use the P2c balancer over the random balancer.

Comparison of load balancing algorithms

The chart above depicts 10,000 requests routed to five proxies (exactly like in the following code sample). Then the numer of requests are normalized to 100%. Since there are five proxies, each proxy should receive 20% of the traffic. But notice that's not the case with the random load balancing algorithm. That's why the power of two choices (P2c) load balancing algorithm is recommended over the random load balancing algorithm.

Usage

import {
    P2cBalancer,
    RandomBalancer,
} from 'arrow-function-load-balancer';

// TODO: Update this list with your proxies or virtual machines.
const proxies = [
    'http://proxy1.arrowfunction.com/',
    'http://proxy2.arrowfunction.com/',
    'http://proxy3.arrowfunction.com/',
    'http://proxy4.arrowfunction.com/',
    'http://proxy5.arrowfunction.com/',
];

// Initializes the power of 2 choices (P2c) balancer with five proxies.
const balancer = new P2cBalancer(proxies.length);

// P2c balancer is preferred over the random balancer.
// const balancer = new RandomBalancer(proxies.length);

for (let i = 0; i < 10000; i++) {
    const proxy = proxies[balancer.pick()];

    // TODO: Use the assigned proxy to scrape a website,
    // shift traffic to a virtual machine etc.
    console.log(proxy);
}

Contributing

Got a new load balancing algorithm you'd like to see implemented in this package? Please go ahead and create a work item for me; or better yet, send a pull request and I'll be sure to take a look at it within 24 hours. Thanks!

Package Sidebar

Install

npm i arrow-function-load-balancer

Weekly Downloads

1

Version

1.2.0

License

MIT

Last publish

Collaborators

  • paulborza