Websocket multiple Channels vs. One Channel + Server Side handling [GroupChat]
Asked Answered
S

0

7

Let's say we want to create private chat rooms, where user can chat in small groups. A user can join multiple / x groups. In each case, I need to create a unique group on the server and subscribe user to these. Which approach is the recommended / more performant way:


[1] On the server side, I create a Room class and add new room channels for each group chat, e.g. "chats/room-asdhqk1", "chats/room-fwuefhw1", "chats/room-awsdhqwd2". Now, some specified users can join this channel and are added to the group client list. On the Client side, the users are subscribed to the group channels they were added to.

Problem: When a user is in x channels, I need to subscribe him into these x channels after side load. Good: Broadcasting to a specific group can be done through the group channel name and all users subscribed to that channel will automatically receive the message, because they have subscribed to the channel within the js part.


[2] Each user gets his own channel, e.g. "notifications/user-1", "notifications/user-2"... . On the server side, I create groups in a Rooms Class (no channels). A user can be added to a specific room by adding him to a sublist of the rooms list. When they chat with each other, the server iterates over the subscribed users of a group chat and sends to each user notification channel the message - no group channel here at all - only per user channels.

Problem: I cannot broadcast a message easily, I need to iterate over each subscribed user and send the message to his notification-channel. In addition, I cannot use the "publish" method in the frontend to easily publish messages to a channel, because users are separated in different channels.

Good: In the end, the broadcasting method would do the same: iterating over a subscriber list. For sending Messages, I could easily implement an RPC Method that does the same as the "publish" method - looking up subscribed users of a group and send the message to them. With this approach, the user does not need to connect to x channels on the client side, he just has one channels that handles all.

(I know that for the second approach, a pusher is required (e.g zmq)).


What are your opinions ? I think that the second one is better, because I don't have to subscribe the user on the client side to x - channels. This would not be performant, if a user needs to first connect to e.g. 500 Channels.

Regards.

Setting answered 5/10, 2015 at 7:29 Comment(3)
The recommended way is the way that you are willing and able to develop and maintain. The most performant way is too specific to your particular architecture, and you are the only person who could even attempt to start forming a meaningful answer.Brevet
If you're really looking at 500 channels per user, then the subscription overhead may become an issue. Otherwise, if that is a theoretical number, and your real numbers are much lower, then my gut feeling would be to go with the existing PubSub mechanisms instead of re-inventing the wheel.Coffeepot
Yes let's say: (1) the user is chatting with 100 different people, this would mean 100 different channels. (2) The user is subscribed to some events, like "tomorrowland 2015..." and he should receive notifications to this event - I would need for each event one new channel the users subscribs to (3) The user gets other notifications to other topics, not event but something else --> Concerning these cases, you will come quickly to a lot of different channels - and connecting the user to each channel would cost much time. If the user just has one private channel, you wouldn't need extra onesSetting

© 2022 - 2024 — McMap. All rights reserved.