Goose97

Goose97

I’m having a hard time debugging this issue related to Phoenix.PubSub on our production system. We have serveral Elixir instances but one is experiencing messages overloaded in the PubSub server. Sometimes the gen server cannot handle incoming messages fast enough so they got piled up in the messages queue. I’m checking the message_queue_len in 3 seconds interval.

Here’s what i know so far:

  • We are using Phoenix.PubSub with PG2 as adapter
  • The aforementioned instance is working under normal workload. Connected sockets got spread pretty evenly between all the instances.
  • During the time when message queue got piled up, we do have a slight increase in incoming messages rate.
  • AFAIK, the Phoenix.PubSub server is doing nothing but receiving messages from remote process, query from ETS and delegate to local socket processes. There are no heavy tasks involved.

So my question is:

  • Is there any flaw in my measurement method? I feel like since message_queue_len does not directly reflect message latency, my assumption could be incorrect.
  • What is the production safe way to debug this issue?

Thanks

Showing Posts 1 to 10

hubertlepicki

hubertlepicki

if you are using Phoenix Live Dashboard you can go there and see the list of processes, memory usage and message queues of processes. This could help you pin point the issue.

My hunch is that the message queue that is piling up is on your GenServer, that it’s single process doing the work and not distributing it to a pool of workers?

Goose97

Goose97 OP

Unfortunately we do not use Phoenix Dashboard at the moment.
Well, the gen server is implemented by Phoenix, Phoenix.PubSub.PG2Server to be precise. There’s only one instance of this gen server running on each Elixir node.

hubertlepicki

hubertlepicki

Alright, but what is listening to these events? There’s some sort of process that receives and processes them that you control, right?

chrismccord

chrismccord

Creator of Phoenix

We also need to know if other parts of the system are causing contention with the schedulers. Do you have any unbounded message queues in the app (such as those subscribed to the incoming pubsub messages)? Any other large message queues that appear alongside the pg2 server’s inbox staring to grow? Once you start get unbounded msgque buildup, other processes can start falling behind or calls start timing out even tho they are not the real cause as the scheduler tries to keep up. I’m not completely ruling out pg2server being your bottleneck, but we need to know a lot more to say what’s going on or to place the blame there. Our synthetic benchmarks of pubsub have handled 500k msg/sec on my macbook. What kind of broadcast rate are you pushing thru the cluster when you see this?

Exadra37

Exadra37

Are you filtering messages, thus not consuming all the incoming ones?

If so, then the mailbox will start to grow and for each received message the mailbox will be parsed from the oldest to the newest, until it matches a message you want to consume, thus creating unnecessary work that will affect the throughput.

To solve this issue you need to have a catch all in order to consume the message, otherwise the runtime will not have it removed from the mailbox, and at some point in time you can even run out of memory and bring the entire system down.

Goose97

Goose97 OP

Thanks for your replies. Regarding your question:

Do you have any unbounded message queues in the app (such as those subscribed to the incoming pubsub messages)?

AFAIK, there are no other unbounded message queues in our system, at least for the part which we written. Not sure if that’s the case for our external libraries.

Any other large message queues that appear alongside the pg2 server’s inbox staring to grow?

I will look into this next time it happens again.

What kind of broadcast rate are you pushing thru the cluster when you see this?

Just broadcast to a given topic with Phoenix.Endpoint.broadcast

Goose97

Goose97 OP

Yep the processes which subscribe to those event are in our control but they are doing nothing beyond pushing message down to clients through web sockets. And since they only receive messages from PG2 server without any blocking (the server just send and forget), I highly doubt that they are the problem.

chrismccord

chrismccord

Creator of Phoenix

I’m asking specifically any idea of the rate of broadcasts? Even an estimate would help get an idea of something beyond pubsub is more likely the cause.

Goose97

Goose97 OP

Currently i’m measuring the message in rate of the Phoenix.PubSub server with :sys.statistics. The rate is around 1400-1600 messages/s even in times when the message queue starts to piles up, it barely increase. Most of them (i can say 95%) are broadcast messages, the rest are messages from Phoenix.Presence.

Please noted that i’m pooling with 3 seconds interval and the :sys module only measure time in second so the result might be a bit off.

tcoopman

tcoopman

Do you have access to the Erlang observer? Maybe that can help you getting some better measurements

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
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
velrest
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
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
mnkhod
So i have been using ash framework for a while and i love it. However currently the issue im having with ash framework is the error handl...
New

Other Trending Topics Top

GenericJam
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
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
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews