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

Tee
can someone please explain to me how Enum.reduce works with maps
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
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
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New

Other popular topics Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
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 27727 240
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement