Skip to content

Instantly share code, notes, and snippets.

@ry
Created November 4, 2011 22:15
Show Gist options
  • Save ry/1340628 to your computer and use it in GitHub Desktop.
Save ry/1340628 to your computer and use it in GitHub Desktop.
var cluster = require('cluster');
var http = require('http');
if (cluster.isMaster) {
// Fork workers.
var ncpus = require('os').cpus().length;
for (var i = 0; i < ncpus; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
});
} 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