diff --git a/README.md b/README.md index 5a3fb6a..5402200 100644 --- a/README.md +++ b/README.md @@ -88,4 +88,10 @@ The `exec`, `env`, `argv`, and `silent` configs are passed to the * `onMessage` - Method that gets called when workers send a message to the parent. Called in the context of the worker, so you can reply by looking at `this`. +* `stopTimeout` - Time in milliseconds to wait for worker to stop before + forcefully killing the process during restart or resize, default 5000 + (5 seconds) +* `skepticTimeout` - Time in milliseconds to wait for worker to live + before shutting previous worker down during restart, default 2000 + (2 seconds) diff --git a/cluster-master.js b/cluster-master.js index 555d18c..afe5dca 100644 --- a/cluster-master.js +++ b/cluster-master.js @@ -12,6 +12,8 @@ var cluster = require("cluster") , net = require('net') , fs = require('fs') , util = require('util') +, stopTimeout = 5000 // default time (ms) to wait for stop before kill +, skepticTimeout = 2000 // default time (ms) to live before stopping old exports = module.exports = clusterMaster exports.restart = restart @@ -56,6 +58,9 @@ function clusterMaster (config) { onmessage = config.onMessage || config.onmessage + if (config.stopTimeout) stopTimeout = config.stopTimeout + if (config.skepticTimeout) skepticTimeout = config.skepticTimeout + clusterSize = config.size || os.cpus().length env = config.env @@ -246,7 +251,7 @@ function forkListener () { disconnectTimer = setTimeout(function () { debug("Worker %j, forcefully killing", id) worker.process.kill("SIGKILL") - }, 5000) + }, stopTimeout) }) }) } @@ -312,7 +317,7 @@ function restart (cb) { worker.disconnect() } graceful() - }, 2000) + }, skepticTimeout) newbie.on('exit', skeptic) function skeptic () { debug('New worker died quickly. Aborting restart.')