Skip to content

Instantly share code, notes, and snippets.

@AndreasMadsen
Created November 14, 2011 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreasMadsen/1364993 to your computer and use it in GitHub Desktop.
Save AndreasMadsen/1364993 to your computer and use it in GitHub Desktop.
Debug file
var cluster = require('cluster');
var http = require('http');
console.log(cluster.isMaster ? "master" : "worker" + " :: " + process.pid);
if (cluster.isMaster) {
// Fork workers.
cluster.setupMaster({workers: 1});
cluster.on('fork', function (worker) {
console.log('worker ' + worker.process.pid + ' fork');
});
cluster.on('death', function(worker) {
console.log('worker ' + worker.process.pid + ' died | state: ' + worker.state + (worker.suicide ? " # it was suicide" : ""));
});
cluster.autoFork();
} else {
// Worker processes have a http server.
http.Server(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment