sarat1669

sarat1669

Load balancing processes with queues

I have spawned two processes A, B from a GenServer

Process A waits for three distinct messages and upon arrival of them, it runs a computation and sends the response to B

Consider the two messages as a part of a request and each request has an id
I wanted multiple requests to be queued/executed at the same time, so I changed the state to store the messages per request in a map.

Ex:

%{
  "request-1": % { message1: 123 },
  "request-4": % { message1: 145, message3: 45 },
  "request-6": % { message2: 56, message1: 345 },
}

Once the third message arrives, the entry from the Map is removed and the computation is run.
Lets assume that the requests are HTTP request and the computation is async. I don’t want the requests to wait for the execution of the previous one.

I want to have a pool of GenServers which keep processing these requests. The load balancing should be based on the queue of the processes inside the GenServer.

I’m not sure how to achieve this. Please let me know your thoughts.

Most Liked

tty

tty

From what I understand the messages have the following format:

{message_id :: ref(), parts :: part_1 | part_2 | part_3}

Once you accumulate all 3 parts the request is handled.

I would suggest using GenStateMachine instead. The GenServer receiving the request would spawn a GenStateMachine then track {message_id, pid()}. Each time it receives another part it sends it to the proper GenStateMachine. When all 3 parts are received the GenStateMachine would fulfill the request.

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
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
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
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

Other popular topics Top

openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
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
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
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

We're in Beta

About us Mission Statement