FAQ
In your case if you are just publishing strings/numbers, creating some
network of channels by name could be useful. If you are publishing a
stringified json object, its probably not necessary to also use
different subscription channels because that data can be part of what
you send but you could still make use of them.


Thomas Blobaum
https://github.com/tblobaum

On Fri, Jul 13, 2012 at 12:29 AM, hd nguyen wrote:
Thanks Tim for your suggestion about subscriber part.

Any suggestions for publisher part(one publisher for each ACTION or one
publisher for ALL ACTION)? I want to hear about it.

Thanks.

On Fri, Jul 13, 2012 at 12:07 PM, Tim Smart wrote:

Hello,

I would definitely recommend just adding one listener and doing all your
routing
from there. Something like:

redis.subscribe('channel1')
redis.subscribe('channel2')

redis.on('message', function (channel, message) {
// emitter.emit(channel, message)
//
// -or
//
// if (methods[channel]) methods[channel](message)
//
// -or
//
// switch (channel) {
// case 'channel1':
// break
// case 'channel2':
// break
// }
})

The main reason being no matter how many clients you have, they will all
receive the same messages as each other; which means your clients will be
doubling up on emit operations.

Tim
On Fri, Jul 13, 2012 at 11:43:25AM +0700, hd nguyen wrote:
Hi all,

I have a concern when using pubsub mechanism of redis in my real
application.

I built a MMO game with 5 servers (NodeJs) and use pubsub of Redis to
broadcast game state between servers.

But I concern which is the best practice to utilize this mechanism
efficiently with a lot of users connect and interact simultaneously?

I would love to hear your ideas about following problems:

1/ Should I create NEW channel for each action or just ONE channel for
ALL
actions?
Ex: user1 connect to server1, user2-server2,...userN-serverN
When user1 move/fight and lost his health, those action should be
broadcast
to other servers, so each time want to broadcast I should use:
pub1.publish("pub1", "action data sent from pub1"); //just one channel
for
ALL actions
OR
pub1.publish("pub1_actionID", "action data sent from pub1"); // each
channel for EACH action

2/ And in each servers we create a client to listen:
//subscribe ALL channels from ALL OTHER servers
client = redis.createClient(port, host);
client.subscribe("pub1");
client.subscribe("pub2");
....
client.subscribe("pubN");

client.on("message", function(channel, message){
console.log(host + ":" + channel + ": " + message);
});

As above snippet code, each server should be a client to listen ALL
CHANNELS published by ALL other servers.

But I concern whether I should use just ONE client to listen ALL
channels
or ONE client for EACH channel?
//each subscribe for each channel
client1 = redis.createClient(port, host);
client2 = redis.createClient(port, host);
client1.subscribe("pub1");
client2.subscribe("pub2");
....
client1.on("message", function(channel, message){
console.log(host + ":" + channel + ": " + message);
});
client2.on("message", function(channel, message){
console.log(host + ":" + channel + ": " + message);
});
...
3/ Could you tell me how many connections redis can handle maximum in a
second? (each time we createClient() we should create a connection to
Redis
server, right? Does it take a lot of time and overhead?)

4/ Any tool to evaluate performance of pubsub mechanism for a MMO game
with
multiple requests at the same time?

Thanks for your time.

--
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en



--
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 9 | next ›
Discussion Overview
groupnodejs @
categoriesnodejs
postedJul 13, '12 at 4:43a
activeJul 30, '12 at 5:51a
posts9
users5
websitenodejs.org
irc#node.js

People

Translate

site design / logo © 2022 Grokbase