Created
June 29, 2013 00:57
-
-
Save jamlfy/5889188 to your computer and use it in GitHub Desktop.
Using all machine or pc
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'); | |
var free = 250000000; | |
var sizeWoker = 157286400; | |
var NumberWorkers = Math.round( ( os.freemem() - free ) / sizeWoker ); | |
if (cluster.isMaster) { | |
for (var i = 0; i < NumberWorkers; i++) { | |
cluster.fork(); | |
} | |
cluster.on('exit', function(worker, code, signal) { | |
console.log('worker ' + worker.process.pid + ' died'); | |
cluster.fork(); | |
}); | |
} else { | |
http.createServer(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