Skip to content

Instantly share code, notes, and snippets.

@s3u
Created March 23, 2012 17:21
Show Gist options
  • Save s3u/2172946 to your computer and use it in GitHub Desktop.
Save s3u/2172946 to your computer and use it in GitHub Desktop.
IPC Test
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
var numReqs = 0;
if(cluster.isMaster) {
// Fork workers.
for(var i = 0; i < numCPUs; i++) {
var worker = cluster.fork();
worker.on('message', function (msg) {
if(msg.cmd && msg.cmd == 'notifyRequest') {
numReqs++;
}
});
}
}
else {
// Worker processes have a http server.
http.Server(
function (req, res) {
res.writeHead(200);
res.end("hello world\n");
process.send({ cmd: 'notifyRequest' });
}).listen(3030);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment