How does Phoenix broadcast hit customers on other sites?

I am trying to compare Phoenix Channels with the new Rails ActionCable when it comes to working with WebSockets.

In some cases, ActionCable uses Redis to handle PubSub when sending a message to all clients. Example scenario: 1 out of 3 rails processes on a separate node will be able to translate to clients connected on all web servers. This is done by clicking on Redis, which in turn publishes all the rails servers, which then click on all of their connected clients.

I recently read about 2 million network connections made by connections from the Phoenix website .

This stone is also found: Phoenix 1.0 release notes mention this regarding channels:

Even on a cluster of machines, your messages are automatically transmitted through the nodes

How can Phoenix broadcast clients through sites? Is a mailbox and / or some other interprocess communication used under the hood?

This is similar to question 2) in this post.

Thanks!

+7
elixir phoenix-framework actioncable
source share
1 answer

The Phoenix PubSub tier is implemented exclusively with the standard library. The Erlang VM concurrency model is distributed out of the box. So the mailbox / message model just works, you send a message locally send(some_local_pid, :a_message) or globally send(some_pid_on_another_machine, :a_message) . This is one of the amazing things about Elixir and Erlang that allows Phoenix to shed addictions such as Radish. If you're interested in how the Phoenix PubSub system uses these features in its implementation, see this blog post:

http://www.zohaib.me/guts-of-phoenix-channels/?utm_campaign=elixir_radar_28&utm_medium=email&utm_source=RD+Station

TL; DR; we use local ETS tables to store PubSub subscriptions for local processes in Node, and we pass them through the nodes using one group :pg2 , which includes each PubSub.Local server. When the PubSub.Local server receives broadcast, it forwards the message to all subscribers locally, looking at the local ETS subscriptions. Actual IPC data and node ↔ node communications are fully processed by the runtime.

+13
source share

All Articles