BBQPupper

BBQPupper

How fast is GenServer.call/3?

I am using GenServer.call/3 to send messages from one node (Node A) to another (Node B). The messages must be sent in order, sort of like this:
Enum.map payload, fn load ->
GenServer.call({Server,:somewhere@remote},load)
end
However, I want these calls to be very fast. I could create a Task for each call, and have Node A attach a timestamp (represented by ascending natural numbers) to each load so that Node B can sort the potentially out of order messages, like this.
Enum.map payload, fn load ->
Task.async(fn -> GenServer.call({Server,:somewhere@remote},{Counter.next(),load}) end)
end
|> Enum.map fn task ->
Task.await(task)
end
Sorry for any formatting or syntax errors. This should start a process for each call to Node B, and the networking time is overlapped instead of stretched out. The problem with this approach is that now Node A must generate timestamps for messages when Node B is supposed to do so (the system uses star topology with Node B at the center acting as a message broker). I want to keep the design clean. Basically, is synchronous GenServer.call/3 fast enough so that using Tasks for many calls is unnecessary? Also, unrelated to the main topic, is it okay for Node A to do the “timekeeping”? In this system Node A creates all new events through a rest api. Every other node (Node B included) processes these events.

Most Liked

tty

tty

  1. There is no guarantees on message arrival orders over the network. This is totally outside Elixir/Erlang/Scala/Go/C/Java/etc domain. A flaky router in the network can delay messages while another message which avoids this router arrive timely.

  2. The GenServer.call/3 is as fast as the GenServer.call/3. If the

GenServer.call, do: very_slow_function() end

it would be impossible for the GenServer.call/3 to be fast
All the GenServer.call/3 means is the callee and GenServer process would block until it receives a result.

  1. Given you expect some ordering there are 3 possible distinct ordering:
    a. Requests ordering
    b. Processing ordering
    c. Result ordering

These are independent, it is possible to require processing ordering but not request and result ordering. Are you certain you require this ordering to begin with.

  1. In general Node A can do the “timekeeping” because it is the entry point into your system. It is possible that Node B is the actual entry point but that is something you have to decide, partially by your answer to (3).
NobbZ

NobbZ

Messages between Node A process 1 and Node B process 2 arrive in order, but might be randomly interleaved by messages of any other process of Node A or Node C (which I suppose to exist, since only 2 nodes don’t make a “star topology”).

But even if order of messages between processes is guaranteed, try as best as you can to remove your dependency on the message.

Often we want ordering where its not actually necessary, and to be honest, the business people which required me to deliver messages in order, didn’t even realize, that I did not. And all I do is holding back cancel messages until I’ve seen the message that gets canceled :wink:

Where Next?

Popular in Questions Top

vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
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
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
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
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
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
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement