Created
February 10, 2012 18:07
-
-
Save yornaath/1791343 to your computer and use it in GitHub Desktop.
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 http = require('http'), | |
cluster = require('cluster') | |
function hydraServer(requestListener, heads){ | |
var server, | |
i; | |
if(cluster.isMaster) { | |
for(i = 0; i < heads; i++) { | |
cluster.fork() | |
} | |
} else { | |
http.createServer(requestListener).listen(3000) | |
} | |
} | |
var counter = 0; | |
hydraServer(function(req, res) { | |
res.writeHead( | |
200, { | |
'Content-Type': 'text/plain' | |
}) | |
counter++; | |
res.end(''+counter) | |
}, 4) | |
/* | |
Each time i hit the server it increments two times, 1, 3, 5, 7 and so forth. | |
Why is the server firing the the requestListener two times? | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment