Skip to content
Browse files

Added rotationTimeout to allow longer wait before rotating processes.

  • Loading branch information...
1 parent 9e87037 commit 207147963a16b593adab4962fa5145567d2ec9ed @mde mde committed Jan 30, 2012
Showing with 26 additions and 14 deletions.
  1. +3 −1 lib/base_config.js
  2. +5 −3 lib/cluster/master.js
  3. +18 −10 lib/cluster/worker.js
View
4 lib/base_config.js
@@ -11,6 +11,8 @@
, rotateWorkers: true
// How long for a full rotation
, rotationWindow: 2 * 60 * 60 * 1000
+// How long to wait for in-flight requests before rotating
+, rotationTimeout: 5 * 60 * 1000
// Default logfile location
, logDir: process.cwd() + '/log'
// How long to wait for in-flight requests before killing
@@ -19,7 +21,7 @@
// the worker to the master
, heartbeatInterval: 5000
// Number of milliseconds old a heartbeat-timestamp can be
-// before killing the worker process
+// before assuming a worker is hung, and needs to be killed
, heartbeatWindow: 20000
// Place to look for static content to serve in dev-mode
, staticFilePath: process.cwd() + '/public'
View
8 lib/cluster/master.js
@@ -85,11 +85,13 @@ Master.prototype = new (function () {
// Grab the next logger-type, if any
if (type) {
// Rename the log file, ex.: mv logs/access.log logs/access.<TIMESTAMP>.log
- cmd = 'mv ' + dir + '/' + type + '.log ' + dir + '/' + type + '.' + now + '.log';
+ cmd = 'mv ' + dir + '/' + type + '.log ' + dir + '/' +
+ type + '.' + now + '.log';
// After the file is renmaed, create the new logger with the original filename
// e.g., access.log
nextLog = function () {
- self[type + 'Log'] = new Log(levelsByType[type], fs.createWriteStream(dir +
+ self[type + 'Log'] = new Log(levelsByType[type],
+ fs.createWriteStream(dir +
'/' + type + '.log'), true, loggly);
self[type + 'Log'].type = type;
// Go on to the next logger type until none are left
@@ -158,7 +160,7 @@ Master.prototype = new (function () {
if (!data.killed) {
self.stderrLog.warning("Process " +
worker.pid + " took too long to retire, killing process.");
- if (now > (data.retireAt + self.config.gracefulShutdownTimeout)){
+ if (now > (data.retireAt + self.config.rotationTimeout + 5000)){
killWorker = true;
}
}
View
28 lib/cluster/worker.js
@@ -64,25 +64,36 @@ Worker.prototype = new (function () {
};
this.retire = function (msg) {
- this.shutDownCleanly('Retirement');
+ var self = this;
+ this.shutDownCleanly(this.rotationTimeout, function () {
+ self.sendMessage({
+ workerId: process.pid
+ , method: 'readyForRetirement'
+ });
+ });
};
this.shutdown = function (msg) {
- this.shutDownCleanly('Shutdown');
+ var self = this;
+ this.shutDownCleanly(this.gracefulShutdownTimeout, function () {
+ self.sendMessage({
+ workerId: process.pid
+ , method: 'readyForShutdown'
+ });
+ });
};
- this.shutDownCleanly = function (type) {
+ this.shutDownCleanly = function (timeout, callback) {
var self = this
, startTime = (new Date()).getTime()
, ready = false;
this.server.addListener('close', function () {
// Poll to see until all in-flight requests complete or
- // we pass the graceful-shutdown timeout window
+ // we pass the timeout window
setInterval(function () {
var count = geddy.inFlight.getCount();
if (count) {
- ready = (new Date()).getTime() - startTime >
- self.config.gracefulShutdownTimeout;
+ ready = (new Date()).getTime() - startTime > timeout;
if (ready) {
// Unceremoniously end responses in the in-flight registry
geddy.inFlight.each(function (entry) {
@@ -100,10 +111,7 @@ Worker.prototype = new (function () {
ready = true;
}
if (ready) {
- self.sendMessage({
- workerId: process.pid
- , method: 'readyFor' + type
- });
+ callback();
}
}, 2000);
});

0 comments on commit 2071479

Please sign in to comment.
Something went wrong with that request. Please try again.