Commit 5b63975c authored by Ppchelko's avatar Ppchelko Committed by Petr Pchelko
Browse files

Allow turning off worker heartbeat feature

Bug: T255278
parent 421d2f1b
......@@ -134,7 +134,7 @@ num_workers: ncpu
startup_concurrency: 2
# Number of milliseconds to wait for a heartbeat from worker before killing
# and restarting it
# and restarting a worker. 'false' means disabling the heartbeat feature.
worker_heartbeat_timeout: 7500
# Logger info
......
......@@ -11,6 +11,7 @@ const Logger = require('./logger');
const docker = require('./docker');
const NUM_CPU_REGEX = /^(?:(?:ncpu[\s)*+-/])|[\s()*+-/.\d])+(?:ncpu)?$/;
const DEFAULT_WORKER_HEARTBEAT_TIMEOUT = 7500;
/**
* Abstract base class for Master and Worker classes.
......@@ -288,7 +289,9 @@ class BaseService {
}
}
conf.startup_concurrency = conf.startup_concurrency || 1;
conf.worker_heartbeat_timeout = conf.worker_heartbeat_timeout || 7500;
if (!conf.worker_heartbeat_timeout && conf.worker_heartbeat_timeout !== false) {
conf.worker_heartbeat_timeout = DEFAULT_WORKER_HEARTBEAT_TIMEOUT;
}
return conf;
}
......
......@@ -75,6 +75,7 @@ class Master extends BaseService {
super.stop();
if (this.interval) {
clearInterval(this.interval);
this.interval = undefined;
}
this._shuttingDown = true;
this._logger.log('info/service-runner/master', 'master shutting down, killing workers');
......@@ -110,7 +111,7 @@ class Master extends BaseService {
.then(() => this._startWorkers(this.config.num_workers))
.tap(() => {
this._logger.log('warn/service-runner', 'startup finished');
this._checkHeartbeat();
this._setupHeartbeatCheck();
});
}
......@@ -292,7 +293,10 @@ class Master extends BaseService {
* killing workers that were inactive for too long
* @private
*/
_checkHeartbeat() {
_setupHeartbeatCheck() {
if (this.config.worker_heartbeat_timeout === false) {
return;
}
this.interval = setInterval(() => {
if (!this._shuttingDown && !this._inRollingRestart) {
const now = new Date();
......
......@@ -156,7 +156,7 @@ class Worker extends BaseService {
this._heapwatchHandle.setGCMonitor();
if (cluster.isWorker) {
this._workerHeartBeat();
this._setupWorkerHeartBeat();
}
// Rate limiting.
......@@ -220,7 +220,10 @@ class Worker extends BaseService {
});
}
_workerHeartBeat() {
_setupWorkerHeartBeat() {
if (this.config.worker_heartbeat_timeout === false) {
return;
}
// We send heart beat 3 times more frequently than check it
// to avoid possibility of wrong restarts
if (this._running) {
......
{
"name": "service-runner",
"version": "2.7.7",
"version": "2.7.8",
"description": "Generic nodejs service supervisor / cluster runner",
"main": "service-runner.js",
"bin": {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment