Created
October 12, 2016 16:29
-
-
Save benfoxall/7bc97589b97300ef4d001b4a3a8e84f3 to your computer and use it in GitHub Desktop.
Cluster wrapper thing
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'); | |
var http = require('http'); | |
var numCPUs = require('os').cpus().length; | |
if (cluster.isMaster) { | |
// Fork workers. | |
for (var i = 0; i < numCPUs; i++) { | |
cluster.fork(); | |
} | |
cluster.on('exit', function(worker, code, signal) { | |
console.log('worker ' + worker.process.pid + ' died'); | |
}); | |
} else { | |
// Workers can share any TCP connection | |
// In this case its a HTTP server | |
require('./server') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment