Last active
August 20, 2016 16:08
-
-
Save alaahaytham/be297fb0021a239327832f0e5cfac31e to your computer and use it in GitHub Desktop.
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 express = require('express'); | |
var cluster = require('cluster'); | |
if (cluster.isMaster) { | |
var _cpus = require('os').cpus().length; | |
// create a worker for each CPU | |
for (var i = 0; i < _cpus; i += 1) { | |
cluster.fork(); | |
} | |
// When a worker dies create another one | |
cluster.on('exit', function(worker) { | |
console.log('worker ' + worker.id + ' died'); | |
cluster.fork(); | |
}); | |
} else { | |
// create a new Express application | |
var app = express(); | |
app.get('/', function (req, res) { | |
res.send('Hello World'); | |
}); | |
// bind to a port | |
app.listen(3000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment