Skip to content

Instantly share code, notes, and snippets.

@chapel
Forked from yornaath/hydraserver.js
Created February 10, 2012 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chapel/1791471 to your computer and use it in GitHub Desktop.
Save chapel/1791471 to your computer and use it in GitHub Desktop.
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