Created
November 17, 2011 21:24
-
-
Save joemccann/1374584 to your computer and use it in GitHub Desktop.
cluster setup
This file contains hidden or 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 app = require('./app'); | |
// Comment this out: | |
// var server = cluster(app) | |
// .use(cluster.pidfiles()) | |
// .use(cluster.cli()) | |
// .use(cluster.stats()) | |
// .use(cluster.repl('/var/run/colab-rest-api.sock')); | |
// | |
// if(app.set('cluster workers')) { | |
// server.set('workers', app.set('cluster workers')); | |
// } | |
// Grab the number of CPUs | |
var numCPUs = require('os').cpus().length | |
if (cluster.isMaster){ | |
// Fork workers. | |
for (var i = 0; i < numCPUs; i++) { | |
cluster.fork() | |
} | |
cluster.on('death', function(worker) { | |
// We need to spin back up on death. | |
cluster.fork() | |
console.log('worker ' + worker.pid + ' died'); // optional | |
}) | |
} | |
else{ | |
app.listen(app.set('web port') || 3000) | |
} | |
// comment this out: | |
// server.listen(app.set('web port') || 3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment