Created
March 23, 2012 17:21
-
-
Save s3u/2172946 to your computer and use it in GitHub Desktop.
IPC Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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