Skip to content

Instantly share code, notes, and snippets.

@omolina
Created March 12, 2012 13:43
Show Gist options
  • Save omolina/2021988 to your computer and use it in GitHub Desktop.
Save omolina/2021988 to your computer and use it in GitHub Desktop.
Cluster on nodeJS implementation with expressJS
//implementación multi-core
var cluster = require('cluster');
var numCPUs = require('os').cpus().length;
//Inicia la escucha en el puerto 3000 y cluster para el balanceo de cargas entre
//los núcleos.
if(cluster.isMaster) {
//for Workers
for(var i=0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
console.log('worker '+worker.pid+' died');
});
}else {
app.listen(3000);
console.log('Servidor escuchando por el puerto 3000' .yellow);
console.log('Número de CPUS: ' .yellow +numCPUs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment