Permalink
Browse files

Proof-of-concept: Cluster with one node per CPU core.

  • Loading branch information...
allanmc committed Aug 1, 2013
1 parent e8f6c8c commit 2df89036608bd07688e403632d72a2884e7ce026
Showing with 21 additions and 0 deletions.
  1. +21 −0 server.js
View
@@ -0,0 +1,21 @@
var cluster = require('cluster');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
console.log('spawning worker #' + (i+1) + '...');
cluster.fork();
}
cluster.on('online', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' is running!');
});
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died. Restarting!');
cluster.fork();
});
} else {
// Load up application as a worker
require('./app.js');
}

0 comments on commit 2df8903

Please sign in to comment.