mcgingras

mcgingras

Liveview constantly refreshes page on poor connection

Hello,

My app is running in production with a few liveview pages. Customers in regions known to have poor connection have reported that the liveview pages constantly refresh on a 10 second or so interval. I was not able to reproduce the issue myself, but I was able to force the app into the refresh cycle by including :timer.sleep(10000) in the mount/3 callback. My thinking was this would simulate a shaky connection, and indeed it forced me into the same sort of refresh loop.

I have a few questions

  • Is there anything I can do about this? I am going to have users in regions of poor connection. Is there a way to gracefully degrade the liveview page for users who are not able to get a strong connection? If not, I may have to completely sunset use of liveview in my application, which is not something I want to do.
  • What is liveview’s failsafe mode? After 10 refreshes the debugger mentioned that it was putting itself in failsafe mode, which didn’t actually seem to change the behavior. I was still getting put into a refresh loop.

Any help would be appreciated! After exploring liveview for 6 months or so in a production environment, the biggest barrier to full adoption is the fact that it does not seem to gracefully degrade. Putting a page into a refresh loop every 10 seconds is not a useable experience.

Most Liked

chrismccord

chrismccord

Creator of Phoenix

A sleep does not really simulate a poor connection. We are reloading the page because the default timeout for a channel join (thus a LV mount) is 10s. This value can be bumped higher via the live socket constructor

new LiveSocket("/...", {timeout: 15000})

However, it seems less likely that your users are frequently taking a 10s round trip to the server. Are you doing any potentially longer blocking work on mount? You can accurately simulate poor network links with latency and packet loss to test a truly poor connection. OS X as a network link condition app, and I’m sure other systems do as well. You can also run these commands on osx:

# enable myapp.local 100ms latency 30% pkt loss
$ sudo -i
$ dnctl pipe 1 config bw 10Mbit/s delay 100 plr 0.3
$ echo "dummynet out proto tcp from any to myapp.local pipe 1" | pfctl -f -
$ pfctl -e

# disable
$ pfctl -f /etc/pf.conf && pfctl -d && dnctl -q flush

How edge are your users? If they consistently see 10s RTT then that will be a barely usable experience no matter what technology choices you make. Simulating 30% packet loss on LiveView applications yields a surprisingly solid experience for me, so we’d need to know more about their conditions and if your own mount is adding to the round trip latency.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

One thing that can lead to spotty experience when there is frequent connects / disconnects are live view pages that aren’t coded to recover their state very well. Good examples are modals or other major UI elements that are present / absent on the basis of an assign that isn’t backed by a URL param or form element. If the user disconnects / reconnects, the liveview state is lost and the UI will “glitch” back to the base state.

I’d make sure that any user facing UI states are backed by something client side so that your live view can recovery cleanly.

Where Next?

Popular in Questions Top

_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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
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
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48475 226
New
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
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
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

We're in Beta

About us Mission Statement