Skip to content

Instantly share code, notes, and snippets.

@alber999
Last active January 27, 2016 05:52
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 alber999/d8889e92b284b555ead9 to your computer and use it in GitHub Desktop.
Save alber999/d8889e92b284b555ead9 to your computer and use it in GitHub Desktop.
Sample of NodeJS as a cluster
/*
* 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