the-mikedavis

the-mikedavis

Slipstream - A slick Elixir websocket client for Phoenix Channels

We @ NFIBrokerage use websockets and Phoenix.Channels fairly extensively in production, serving well over 100k connections a week.

When we first started using websockets broadly between back-end services, we noticed an odd build-up of process memory in Phoenix.Channel server processes which we now presume to be a product of moving large amounts of data over-the-wire and a known issue in :websocket_client (see more in the Slipstream documentation). This and the at-the-time archival of the popular phoenix_gen_socket_client led us to write a new Phoenix.Channel client from scratch backed by :gun.

Enter Slipstream!

Slipstream touts

  • :gun under the hood
  • reconnect and rejoin mechanisms with back-off similar to phoenix.js
  • a rich set of :telemetry events
  • utilities for testing clients similar to Phoenix.ChannelTest
  • a GenServer-like callback interface for client modules with default implemementations for all callbacks
  • a synchronous interface for scripting
  • an ever-expanding examples directory with reference clients and tutorials

After cutting over the bulk of our socket clients to Slipstream, we’ve seen a marked decline in clients disconnecting from Phoenix.Channels as a result of the server disconnecting them (as opposed to the client gracefully disconnecting).

(That line at 02/02 13:20 marks the mass cutover. Note that the other disconnection reasons than “disconnected by remote server” are expected and are considered normal and desirable behavior. Remainders of “disconnection by remote server” denote deploys and restarts of services running Phoenix.Channels. Also note that this improvement is more likely an indirect result of switching to :gun: that the remote server has less memory pressure and is therefore more reliable, rather than a hypothetical bug in the :websocket_client implemementation which would force disconnects.)

We’ve been using slipstream widely in production for a little while now and want to share it with y’all! If you’re in the market for a new Phoenix.Channel client, look no further.

Most Liked

the-mikedavis

the-mikedavis

Slipstream v0.8.0 has been released!

v0.8.0 switches out :gun for Mint.WebSocket as the low-level WebSocket client.

Gun is great but its strict dependencies on cowlib often conflict with cowboy’s (and therefore Phoenix), making it hard to use gun in a Phoenix project without an override.

Check out the CHANGELOG for extended notes on the changes and how to upgrade.

10
Post #3
jamesvl

jamesvl

This looks really great! Thanks for open sourcing this; I hope to get some time soon to try it out locally in one of my projects that also relies quite heavily on websockets.

lawik

lawik

Nerves Core Team

Slipstream inplements Phoenix Channels which is a specific implementation on top of WebSockets.

For raw WebSockets you can check what Slipstream depends on over at hex.pm. There should be a websocket library in there.

Where Next?

Popular in Libraries Top

tmbb
I’ve decided to create this topic to discuss optimization possibilities for something like Phoenix LiveView. I’ve created this topic unde...
New
markmark206
simple_feature_flags is a tiny package that lets you turn features on or off based on which environment (e.g. localhost, staging, product...
New
Qqwy
TypeCheck: Fast and flexible runtime type-checking for your Elixir projects. Core ideas Type- and function specifications are const...
336 13801 100
New
dbern
I’m excited to announce that TaxJar has developed and open-sourced DateTimeParser. We developed it because we found a need to parse user ...
New
praveenperera
FastRSS Parse RSS feeds very quickly: This is rust NIF built using rustler Uses the RSS rust crate to do the actual RSS parsing Speed...
New
michalmuskala
Another small library today. PersistentEts Hex: persistent_ets | Hex GitHub: GitHub - michalmuskala/persistent_ets Ets table backed by...
New
benlime
LiveMotion enables high performance animations declared on the server and run on the client. As a follow up to my previous thread A libr...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
bryanjos
Hi, I wanted share a small library we at Revelry Labs made for rendering react components from the server side. There are instructions fo...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Sub Categories:

We're in Beta

About us Mission Statement