Hi all,
My program will be hosted in different machine, so in each worker I use redis pubsub to broadcast to other servers.
The code should be like following snippet:
if(cluster.isMaster) {
// create workers
for (var i = 0; i < numCPUs; i++) {
global.cluster.fork();
}
global.cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
});
}
else {
// do worker's task
pub = redis.createClient(port, host);
sub = redis.createClient(port, host);
..... use pub/sub to broadcast to other servers when needed
}
What I concern here is that if I do not use cluster, just use single thread, everything is ok, pubsub works properly between servers.
But when applying cluster, pubsub does not work?? Data cannot be sent to other servers, but in the same machine everything is still ok although different users belong to different workers.
I'm not sure about role of MASTER process and WORKER process here, anything wrong in my code, I should listen message event from pubsub in MASTER process, then send to WORKER?
Welcome your comments all.
Thanks in advance.
--
Nguyen Hai Duy
Mobile : 0914 72 1900
Yahoo: nguyenhd_lucky