Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.