Instantly share code, notes, and snippets.

@alber999 /index.js
Last active Jan 27, 2016

Embed
What would you like to do?
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