elixirnewbie

elixirnewbie

Message queue length of a GenServer

How can I get the message queue length of a GenServer? I have tried

def handle_call({:add,number},_from, state) do
  
  {_,num}=Process.info(self(), :message_queue_len)
 IO.inspect num
  {:reply,reply state}
end

but getting 0.

Most Liked

blatyo

blatyo

Conduit Core Team

How are you sending messages to that process?

I notice that you’re doing this in a handle_call which is synchronous. So, if you only have one process doing a GenServer.call to this process it’ll block until it gets a response. That means, you’ll never have a queue length, because this handle_call is consuming the only message that has been sent.

In short, what you’re doing is correct, but the way you’re testing it isn’t.

stefanchrobot

stefanchrobot

Sounds like you want to control the ingestion of data in your system. If that’s the case, rather than fiddling with the queue length, I’d suggest taking a look at GenStage.

peerreynders

peerreynders

That is irrelevant given that the process can only control removal of messages from the mailbox and nothing else - i.e. a process can’t stop accepting messages; it can only stop accepting work which would be tracked inside the process state.

something like {:error, :queue_full}

a response like that happens when a received message is requesting more work but your work backlog indicates that you already have enough - i.e. the response should have nothing to do with messages remaining in the process mailbox but everything with information you currently have in the process state.

Where Next?

Popular in Questions Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
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
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
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
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

We're in Beta

About us Mission Statement