Created
December 22, 2013 16:34
-
-
Save parshap/8085068 to your computer and use it in GitHub Desktop.
Node.js zero-downtime reload with cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cluster = require("cluster"); | |
function master() { | |
var worker = cluster.fork(); | |
process.on("SIGUSR2", function() { | |
var newWorker = cluster.fork(); | |
newWorker.on("listening", function() { | |
worker.disconnect(); | |
worker = newWorker; | |
}); | |
}); | |
} | |
function worker() { | |
require("http").createServer(function(req, res) { | |
res.end("Hello"); | |
}).listen(); | |
} | |
if (cluster.isMaster) { | |
master(); | |
} | |
else { | |
worker(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Care to elaborate? Some potential issues I've thought of: