I am using the core cluster module in node v0.6.5. I have the following code:
var cluster = require('cluster');
var http = require('http');
var numWorkers = 3;
var count = 0;
if (cluster.isMaster) {
for (var i = 0; i < numWorkers; i++) {
cluster.fork();
}
} else {
console.log('createServer called');
http.createServer(function (req, res) {
count++;
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Count is: ' + count.toString());
}).listen(1337, "127.0.0.1");
}
Everytime I hit the page, the count is incremented twice, e.g. 1,3,5,7… Why does it increment twice?
This is probably another case where the browser is silently requesting
/favicon.ico, thus making there 2 requests per page.