Vote count:
0
I've been looking at the Node cluster API as a way of making use of all available CPUs on my server. Apparently the cluster can share connections so that each node child process can listen on a server port and the requests are spread between them.
This all sounds great except that I can't get it to work on my Win8.1 machine :S
Using the code from How many child processes can a node.js cluster spawn on a 64bit Wintel PC?
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
cluster.fork();
});
} else {
// Worker processes have a http server.
http.Server(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
}
This code runs perfectly and I can verify that the child processes are being started as expected.
The problem is that if I load http://localhost:8000 in the browser the request is never served. The connection is started ('Waiting for localhost...') but it appears that the child process never handles it.
For example this will not print anything in the console:
http.Server(function(req, res) {
console.log('Got the connection.. sending some info!');
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
Strangley enough, if i use the sample code provided in the Node cluster documentation (http://ift.tt/Ou7RPo) which handles to some degree dead child processes, when I first load the webpage in the browser I see a console log about a worker dying.
worker 33372 died
As far as I can tell nobody else is reporting this issue so I am guessing it might be something specific to my setup but I can't see what.
I have updated to the latest version of node (v0.10.33) but that did not help.
Any ideas?
NodeJS cluster not sharing sockets on Windows?
Aucun commentaire:
Enregistrer un commentaire