Skip to content

Commit

Permalink
Make heartbeat liveness configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
julbra committed Aug 19, 2018
1 parent 45ac0a9 commit 5ed93b4
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/Broker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ var putils = require('./utils');

var BaseController = require('./BrokerController');

var HEARTBEAT_LIVENESS = 3;

function Broker(endpoint, conf) {
this.services = {};
this.workers = new Map();
this.rmap = new Map();

this.conf = {
heartbeat: 2500,
heartbeatLiveness: 3,
dmode: 'load',
name: 'B' + uuid.v4(),
intch: 'tcp://127.0.0.1:55550'
Expand Down Expand Up @@ -244,7 +243,7 @@ Broker.prototype.onClient = function(msg) {
} else if (type === 'worker') {
var worker = this.workers.get(msg[4]);
if (worker) {
worker.liveness = HEARTBEAT_LIVENESS;
worker.liveness = this.conf.heartbeatLiveness;
}
}
} else {
Expand Down Expand Up @@ -285,7 +284,7 @@ Broker.prototype.onWorker = function(msg) {
return;
}

worker.liveness = HEARTBEAT_LIVENESS;
worker.liveness = this.conf.heartbeatLiveness;

if (type == MDP.W_REPLY || type == MDP.W_REPLY_PARTIAL || type == MDP.W_REPLY_REJECT) {
var rid = msg[5];
Expand Down Expand Up @@ -416,7 +415,7 @@ Broker.prototype.workerRequire = function(workerId) {

var worker = {
workerId: workerId,
liveness: HEARTBEAT_LIVENESS,
liveness: this.conf.heartbeatLiveness,
rids: new Map(),
opts: {
concurrency: 100
Expand Down Expand Up @@ -516,7 +515,7 @@ Broker.prototype.workersCheck = function() {
return;
}

if (worker.liveness < HEARTBEAT_LIVENESS) {
if (worker.liveness < self.conf.heartbeatLiveness) {
self.send([workerId, MDP.WORKER, MDP.W_HEARTBEAT]);
}
});
Expand Down

0 comments on commit 5ed93b4

Please sign in to comment.