Skip to content

gbk/load-balancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

load-balancer

npm version


Introduction

Load-balancer is a task manager for nodejs tasks.

If you have lots of independent tasks, and wish them to be done as soon as possible, you can try this tool!

Load-balancer will take full usage of CPUs.

  • Create workers.
  • Master send tasks to every worker.
  • When a worker finishes it's task, will receive a new one from master.
  • If no more tasks remain, workers will be killed.

Installation

npm i load-balancer --save

Usage

master.js

var Balancer = require('load-balancer');
...
// create a master
var master = new Balancer.Master('Master A');
// master send jobs to workers
master.send('worker.js', context, jobDetails, function(results) {
    // all jobs done here
});

worker.js

var Balancer = require('load-balancer');
...
// create a worker
var worker = new Balancer.Worker('Worker A');
// worker receive job from master
worker.receive(function(master, context, jobDetail, callback) {
    // deal with jobDetail
    callback(result);
});

Examples

You can find more examples here.

Benchmarking

npm test

See minify assets case:

Case Duration(ms)
1 Process(Normal) 21947
Multi-Processes(Auto) 12840

Intel® Core™ i5-6200U CPU @ 2.30GHz × 4
Ubuntu 16.04 64bit

About

Load balancer for nodejs worker

Resources

License

Stars

Watchers

Forks

Packages

No packages published