Skip to content

Instantly share code, notes, and snippets.

@yanmhlv
Created August 12, 2015 10:05
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 yanmhlv/c7af6cfcb004c5dddfc3 to your computer and use it in GitHub Desktop.
Save yanmhlv/c7af6cfcb004c5dddfc3 to your computer and use it in GitHub Desktop.
var numCPUs = require('os').cpus().length;
var cluster = require('cluster');
var count=0;
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
});
} else {
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('');
}).listen(1337, '127.0.0.1');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment