Hi all,

I'm using cluster module to utilize multi-core machine (
http://nodejs.org/api/cluster.html#cluster_class_worker).

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

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to