rafaeliga
Hello there,
I have a Liveview that subscribes to a Pubsub topic and starts a Genserver when I click in a button.
The Genserver sends a message back to the Liveview using the Pubsub, those messages seems to only be processed after the map ends:
If I increase the data, from 1000 to 10000000, I see that some of messages being received before:
Is there a way to receive those message before?
I have created a repository to reproduce: GitHub - rafaeliga/liveview_pubsub_update: Sample project to test Liveview + Pubsub · GitHub.
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Latest Phoenix Threads
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming












Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Nicd
The processes are running concurrently and there isn’t really a way to force the subscriber to process a message before the publisher can continue in a PubSub, I think. Looks like the sending is faster than receiving in this case (or the messages go slower through the PubSub system).
Anyway, why do you want the receiving to occur before? Is it leading to a time delay?
I think something like GenStage/Flow could provide backpressure, leading to blocking of the producer before consumers have had time to consume the items.
cevado
it’s not that sending it’s faster. what happens is that publishing the message won’t stop a process of running its reductions.
on your solution, what you want to be synchronous and what you want to be asynchronous?
The idea is to design the system to solve the thing the way you need. PubSub is a asynchronous solution.
rafaeliga
My use case is showing a CSV import / insert data in database in real time.
cmo
What your example shows is that a) it is extremely quick to map through a list when you do no work in the map function and b) pubsub works. You can probably move on to the next stage.
You could delay processing the next chunk until after the message is received by
calling the liveview instead of broadcasting, but I don’t imagine you want to do that in practice.rafaeliga
Sorry if my initial post isnt clear enough, let me try with more data:
There is a time difference between the Pubsub send message and Liveview receiving.
That time increases if I send more messages(more data):
dev
100: ~16ms
1000: ~50ms
100000: starts at: ~700ms, ends at: ~3000ms
1000000: starts at: ~7000ms, ends at: 38000ms
prod(fly.io)
1000: ~180ms
1000000: crashed
Why do we have this difference if I have more data? Its related to the Pubsub or the Liveview on receiving these messages?
cevado
Because message passing between process is not a synchronous procedure.
PubSub publishing message is a non-blocking operation, just like doing a cast with a GenServer.
Since publishing is non-blocking, the process A will keep doing whatever his doing until the scheduler stop it from running(in your case, keep publishing messages until it finishes starting).
The delays you’re experiencing in your test is not particular to any implementation of the PubSub or Liveview but instead of how you choosed to implement your synthetic load.
thiagomajesk
Hi @cevado! I think there’s some misunderstanding between what @rafaeliga wants and what you are explaining. I don’t think he is expecting to process anything synchronously.
If I understand correctly, what @rafaeliga meant is that there’s some considerable delay from sending to receiving the message; this is nothing to do with the concurrency model per se.
You mentioned reductions and this made me think that perhaps, the LiveView process’s mailbox is getting too many messages and the delay he’s experiencing is the delta between processing the messages.
However, based on the data he provided, it seems that there’s a considerable delay between sending the message and receiving it, even with a low amount of messages to process.
Curiously enough, from what I’ve heard about Elixir/Phoenix in the past, I’d expect that broadcasting messages would be a little bit more performant than that. But perhaps, this is a question on how to better structure the message passing between the processes (perhaps batching it or something).
cevado
please look at the code provide…
code that starts the “background processing”:
the “background processing”:
when
LiveviewPubsubUpdate.Import.start()is called it is a synchronous process, sostart()will release the live view only when the init callback finishes running.the init callback in the GenServer is that part that publishes.
thiagomajesk
@cevado could you elaborate what you meant by this statement? Bear in mind that even though
LiveviewPubsubUpdate.Import.start()is synchronous code, thePhoenix.PubSub.broadcastcall is not. That is, messages arrive in the LiveView before the synchronous code finishes processing, which does not seem to be the problem IMHO.The main question seems to be that after a message is dispatched to the LiveView, there’s some delay before it actually gets processed.
I think that if LiveView was receiving and processing its events fast enough, this perceived delay would not exist. I might be missing something here, but it doesn’t seem to be a problem about concurrency.
benwilson512
Yes, but
startis blockinghandle_event, which blockshandle_info.startdoes not return untilinitreturns. This means thathandle_eventdoesn’t return untilinitreturns, which means that the live view is unable to do anyhandle_infocalls untilinithas published all of the messages.EDIT: To elaborate further: A live view is a genserver, and a genserver is a single process. A single process can only run code linearly, and that means that a given callback from a genserver can only run one at a time. As long as
handle_eventis blocked, the genserver loop of the whole liveview process is blocked, which prevents anyhandle_infoclause from running. If you change your broadcaster to do:You should see more of what you expect.