gbk / load-balancer Goto Github PK
View Code? Open in Web Editor NEWLoad balancer for nodejs worker
License: MIT License
Load balancer for nodejs worker
License: MIT License
Thread Pool Size: 0
The workers are not waiting and giving the callback. What am i doing wrong? Even tried explicit Promise
//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', null , [ "./File1", "./file2"], function(results) {
// all jobs done here
console.log(results);
});
//WORKER.JS
var Balancer = require('load-balancer');
var fs = require('fs');
var Promise = require("bluebird");
// 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
console.log(master,context,jobDetail);
get_line_count(jobDetail).then(function(count){
callback(count);
});
});
function get_line_count(file) {
return new Promise(function(resolve, reject) {
var count = 0;
fs.createReadStream(config.path + "/" + file)
.on('data', function(chunk) {
for (var i = 0; i < chunk.length; i++)
if (chunk[i] == 10) count++;
})
.on('end', function() {
resolve(count);
})
.once('error', function() {
reject("Error While Getting Line Count!");
});
});
}
Output:
Thread Pool Size: 2
Master A null ./File1
Master A null ./File2
4136724
[ , 4136724 ]
4905930
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.