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

前端 未结 3 1975
北荒
北荒 2021-02-09 10:31

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 ma

相关标签:
3条回答
  • 2021-02-09 11:10

    Unless I am misunderstanding your use case, you can still use the exact scaling technique your node version of the application is. Simply deploy the Phoenix application to > 1 machines and use an Nginx load balancer configured to forward requests to one of the many application machines.

    The built in node communications etc of Erlang are used for applications that scale in a different way than a web app. For instance, distributed databases or queues.

    0 讨论(0)
  • 2021-02-09 11:23

    Look at Phoenix.PubSub It's where Phoenix internally has the Channel communication bits.

    It currently has two adapters:

    • Phoenix.PubSub.PG2 - uses Distributed Elixir, directly exchanging notifications between servers. (This requires that you deploy your application in a elixir/erlang distributed cluster way.)
    • Phoenix.PubSub.Redis - uses Redis to exchange data between servers. (This should be similar to solutions found in socket.io and others)
    0 讨论(0)
  • 2021-02-09 11:25

    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.

    0 讨论(0)
提交回复
热议问题