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

前端 未结 3 1977
北荒
北荒 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: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.

提交回复
热议问题