Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a Phoenix application tailored only to use channels scale on multiple machines? Using HAProxy? How to broadcast messages to all nodes?

I use the node application purely for socket.io channels with Redis PubSub, and at the moment I have it spread across 3 machines, backed by nginx load balancing on one of the machines.

I want to replace this node application with a Phoenix application, and I'm still all new to the erlang/Elixir world so I still haven't figured out how a single Phoenix application can span on more than one machine. Googling all possible scaling and load balancing terms yielded nothing.

The 1.0 release notes mention this regarding channels:

Even on a cluster of machines, your messages are broadcasted across the nodes automatically

1) So I basically deploy my application to N servers, starting the Cowboy servers in each one of them, similarly to how I do with node and them I tie them nginx/HAProxy?

2) If that is the case, how channel messages are broadcasted across all nodes as mentioned on the release notes?

EDIT 3: Taking Theston answer which clarifies that there is no such thing as Phoenix applications, but instead, Elixir/Erlang applications, I updated my search terms and found some interesting results regarding scaling and load balancing.

  • A free extensive book: Stuff Goes Bad: Erlang in Anger
  • Erlang pooling libraries recommendations

EDIT 2: Found this from Elixir's creator:

Elixir provides conveniences for process grouping and global processes (shared between nodes) but you can still use external libraries like Consul or Zookeeper for service discovery or rely on HAProxy for load balancing for the HTTP based frontends.

EDITED: Connecting Elixir nodes on the same LAN is the first one that mentions inter Elixir communication, but it isn't related to Phoenix itself, and is not clear on how it related with load balancing and each Phoenix node communicating with another.

like image 311
Willian Schneider Avatar asked Dec 01 '15 19:12

Willian Schneider


1 Answers

Phoenix isn't the application, when you generate a Phoenix project you create an Elixir application with Phoenix being just a dependency (effectively a bunch of things that make building a web part of your application easier).

Therefore any Node distribution you need to do can still happen within your Elixir application.

You could just use Phoenix for the web routing and then pass the data on to your underlying Elixir app to handle the distribution across nodes.

It's worth reading http://www.phoenixframework.org/v1.0.0/docs/channels (if you haven't already) where it explains how Phoenix channels are able to use PubSub to distribute (which can be configured to use different adapters).

Also, are you spinning up cowboy on your deployment servers by running mix phoenix.server ?

If so, then I'd recommend looking at EXRM https://github.com/bitwalker/exrm

This will bundle your Elixir application into a self contained file that you can simply deploy to your production servers (with Capistrano if you like) and then you start your application.

It also means you don't need any Erlang/Elixir dependencies installed on the production machines either.

In short, Phoenix is not like Rails, Phoenix is not the application, not the stack. It's just a dependency that provides useful functionality to your Elixir application.

like image 125
TheStoneFox Avatar answered Oct 20 '22 15:10

TheStoneFox