This repository was archived by the owner on Apr 22, 2023. It is now read-only.
Description with the demo code from the cluster docs:
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('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
});
} else {
// Worker processes have a http server.
http.Server(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
}
chi:petrol christoph$ node minicluster.js &
[1] 14330
chi:petrol christoph$ Worker 14332 online
Worker 14333 online
Worker 14331 online
Worker 14334 online
chi:petrol christoph$ kill 14330
$ ps | grep node
14331 ttys000 0:00.10 /Users/christoph/.nvm/v0.6.0/bin/node /Users/christoph/Projects/collmedia/petrol/minicluster.js
14332 ttys000 0:00.10 /Users/christoph/.nvm/v0.6.0/bin/node /Users/christoph/Projects/collmedia/petrol/minicluster.js
14333 ttys000 0:00.10 /Users/christoph/.nvm/v0.6.0/bin/node /Users/christoph/Projects/collmedia/petrol/minicluster.js
14334 ttys000 0:00.10 /Users/christoph/.nvm/v0.6.0/bin/node /Users/christoph/Projects/collmedia/petrol/minicluster.js
$ curl http://127.0.0.1:8000/
hello world
$ node -v
v0.6.0
Reactions are currently unavailable
with the demo code from the cluster docs: