Created
November 14, 2011 20:09
-
-
Save AndreasMadsen/1364993 to your computer and use it in GitHub Desktop.
Debug file
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'); | |
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