var cluster = requre('custer');
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, singal){
console.log('worker'+worker.process.pid+''died');
});
} else {
// worker can share any tcp connection
http.createServer(function(req, res){
rs.writeHead(200);
rs.end('hello');
}).listen(200);
}
cluster.isWorker =('NODE_UNIQUE_ID' in process.env)
cluster.isMaster = (cluster.isWorker === false);