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

Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
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
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
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
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
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
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
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
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
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
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
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
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
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
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
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
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New

We're in Beta

About us Mission Statement