Cluster and redis pubsub

195 views
Skip to first unread message

hd nguyen

unread,
Aug 23, 2012, 5:01:55 AM8/23/12
to nod...@googlegroups.com
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

hd nguyen

unread,
Aug 23, 2012, 10:51:08 PM8/23/12
to nod...@googlegroups.com
Seem that problem is the conflict between cluster module and socket.iohttps://github.com/LearnBoost/socket.io/issues/798#issuecomment-7965366 

Anybody figure out the way to resolve it?

Thanks.
Reply all
Reply to author
Forward
0 new messages