5
votes

I need some advice about elixir/phoenix channels. I have an application that is related to venue changes and in order to reduce the amount of data sent to each client I only want each client to subscribe to the venues it cares about.

With this in mind I was thinking of going down the route of having a channel for "VenueChanges/*" and having each client subscribe to the channel several times with each venue id it cares about i.e. "VenueChanges/1", "VenueChanges/2" etc.

The venues that the client care about will change frequently which will mean a lot of joining and leaving channels.

My question is, what's the overhead of having a client join a channel lots of times. Am I correct in assuming that there would still only be one socket open and not a new socket for each of the channels joined?

Also any advice on managing the constant joining and leaving of channels from the client? Any other advice in general? If this is a bad idea what are better alternatives?

1
Great question, but unfortunately it's not the best type of question for StackOverflow. General advice questions are considered off topic. Have you tried it yourself to see what will happen?CoderDennis
I disagree, only the last part of this was general advise there is also a specific question about performanceOwen
Had you meant "a lot of joining and leaving channel topics/rooms"? I got that impression from VenueChanges:1, VenueChanges:2 etc.David Kuhta

1 Answers

1
votes

With respect to the socket question, you are correct in that you will still only have one socket per client (multiple channels are multiplexed over that one socket).

While not directly answering your consistent join/leave question, Chris McCord's post on Phoenix Channels vs Rails Action Cable has some really good data on performance best summarized by:

With Phoenix, we've shown that channels performance remains consistent as notification demand increases, which is essential for handling traffic spikes and avoiding overload

That said, your server hardware and deployment distribution strategy would also play a significant role in answering that concern.

Lastly, on the basis that you meant join/leaving channel topics (or "rooms" as it's termed in some places) as seen in the Chris's test with 55,000 connections:

It's important to note that Phoenix maintains the same responsiveness when broadcasting for both the 50 and 200 users per room tests.