Last active
January 27, 2016 05:52
-
-
Save alber999/d8889e92b284b555ead9 to your computer and use it in GitHub Desktop.
Sample of NodeJS as a cluster
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
/* | |
* Cluster NodeJS | |
*/ | |
var cluster = require('cluster'); | |
if (cluster.isMaster) { | |
var cpuCount = require('os').cpus().length; | |
for (var i = 0; i < cpuCount; i += 1) { | |
cluster.fork(); | |
} | |
} else { | |
var http = require('http'); | |
http.createServer(function (req, res) { | |
res.end('Hello world!'); | |
}).listen(9615); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment