Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

arrow-function-load-balancer

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arrow-function-load-balancer

Load balancers for Node, including "The power of two choices" algorithm

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

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!

Keywords

FAQs

Package last updated on 07 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc