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
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex












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.