Created
September 2, 2015 14:17
-
-
Save krosti/1e7baf0cc72c663da2ea to your computer and use it in GitHub Desktop.
ExpressJS Cluster test
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'); | |
if(cluster.isMaster) { | |
var numWorkers = require('os').cpus().length; | |
console.log('Master cluster setting up ' + numWorkers + ' workers...'); | |
for(var i = 0; i < numWorkers; i++) { | |
cluster.fork(); | |
} | |
cluster.on('online', function(worker) { | |
console.log('Worker ' + worker.process.pid + ' is online'); | |
}); | |
cluster.on('exit', function(worker, code, signal) { | |
console.log('Worker ' + worker.process.pid + ' died with code: ' + code + ', and signal: ' + signal); | |
console.log('Starting a new worker'); | |
cluster.fork(); | |
}); | |
} else { | |
//one instance here | |
// app.use(... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment