tfischbach

tfischbach

Hi,

currently I am testing running a Phoenix application on a system with multiple connected nodes. There are some observations I’d like to confirm/questions I’d like to ask that I could not find documented anywhere.

Consider the case where requests are load balanced between multiple phoenix applications on different (BEAM) nodes (via an external load balancer i.e. Docker Swarm ingress load balancing or HAProxy):

  1. When using websocket transport, channel communication is performed via one persistent HTTP connection which the load balancer routes to one of the Phoenix instances. The life span of a “channel session” (which begins with join and ends with terminate) is identical to the life span of that connection. Correct? Does Phoenix persist any channel related state that spans multiple such connections?

  2. When using long polling, the channel communication is divided into many requests. If the load balancer routes these to different Phoenix instances, I see errors in my JS client. Once Phoenix instances run on connected nodes, I so far was no longer able to reproduce these problems. Does Phoenix delegate channel traffic to the correct process across node boundaries? So far it looks like it does, but I could not find this documented anywhere.

  3. Assuming 2. is the case, what happens when one of the nodes disconnects because it is stopped (e.g. during a rolling update deploy)? Is there anything my application needs to do to ensure connections terminate gracefully (particularly in the long polling case) so that the client can establish a new connection?

Any insights on these topics or links to resources covering these questions would be greatly appreciated.

Showing Posts 1 to 1

idi527

idi527

:waving_hand:

Please take these answers with a grain of salt since it’s been some time since I used phoenix. But I thought I’d write them down before someone more knowledgable comes around.


http connection?

Just to be clear, websocket connections are initiated with the help of an http upgrade request, but they operate over a tcp connection (just like http, though).

The channel process lifespan (channel session) is shorter than (or equal to) the lifespan of a Phoenix.Socket which supposedly corresponds to that of a cowboy process handling the tcp connection. I’m not aware of any persistence logic in phoenix channels which would’ve worked by default. You can persist the channels/socket states yourself though.


When using long polling, the channel communication is divided into many requests. If the load balancer routes these to different Phoenix instances, I see errors in my JS client. Once Phoenix instances run on connected nodes, I so far was no longer able to reproduce these problems. Does Phoenix delegate channel traffic to the correct process across node boundaries? So far it looks like it does, but I could not find this documented anywhere.

If the tcp connection is kept open (which is true by default in http/1.1), then there is no additional routing required from the load balancer and all your http long-polling requests go to the same node. It works just like websockets. If the connection is closed (if there is connection: close http header), then yes, the next request might be routed to another node in the cluster by the load balancer. Phoenix PubSub can route the messages within the cluster with the help of pg2, though, which is what probably happens in

Once Phoenix instances run on connected nodes, I so far was no longer able to reproduce these problems.


Assuming 2. is the case, what happens when one of the nodes disconnects because it is stopped (e.g. during a rolling update deploy)? Is there anything my application needs to do to ensure connections terminate gracefully (particularly in the long polling case) so that the client can establish a new connection?

The client would establish a new connection after a disconnect automatically (at least in phoenix.js). Whether the node to which the new connection is established has the previous channel state is mostly up to you, I think.


via an external load balancer i.e. Docker Swarm ingress load balancing or HAProxy

I like haproxy :+1:

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews