BCM1982

BCM1982

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.

Showing Posts 1 to 4

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:

joefractal

joefractal

Several factors which make a definitive answer impossible.

  1. How much processing is happening inside the GenServer. If it’s substantial then all other optimizations are moot
  2. Is the processing acting on GenServer state? (meaning it’s needs to sequential)
  3. How are Node A & B connected
  4. How large is payload etc

If you are worried about the context switch & overhead of many genserver calls, you can send chunks or even the whole payload.

NobbZ

NobbZ

Well, in general, I do understand this as “how much overhead does GenServer.call/3 add?”, and I tend to say, usually it adds less overhead than implementing something from scratch to push data from one node to the other.

Available Bandwith to send the data, CPU time to process the data and sending the reply needs to happen anyway, regardless of a GenServer is used or something else.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews