WestKeys

WestKeys

Serialization of GenServer/:rpc requests to remote Nodes - clarification sought

Could someone clarify what is meant here by serialize your requests on a single server?

I’m assuming the receiving GenServer would also be running asynchronously on the remote node, so what is the difference with Tasks?

Taken from the docs

Both :rpc and using a GenServer would serialize your requests on a single server, while tasks are effectively running asynchronously on the remote node, with the only serialization point being the spawning done by the supervisor.

Marked As Solved

al2o3cr

al2o3cr

All the approaches run code on the remote machine, but which process they do it in is different:

  • a named GenServer will handle the message in its single process
  • :rpc will perform the specified apply in the RPC server process. There’s one of these per node
  • a remote Task.Supervisor will handle the “start a task” request in its single process, which starts a separate process where the Task does its work

The difference is easier to think about if you imagine the “actual work” part of each of these takes a while - imagine Process.sleep(2000) as a stand-in. If three requests in close succession are sent to the three approaches, here’s what happens:

  • the GenServer and :rpc approach both take slightly more than 3x the time of one “actual work” step, because they handle messages one-at-a-time
  • the Task.Supervisor approach will take slightly more than 1x the time of an “actual work” step, as it handles messages by starting a process for each

Also Liked

al2o3cr

al2o3cr

Both call and cast send messages to the GenServer, but they differ on what they do next.

  • cast returns immediately; it cannot fail, even if the recipient PID has exited or never existed in the first place.

  • call waits for a reply, blocking the process until the GenServer sends a reply

In the three-requests example, the three casts will all return immediately to their callers but the GenServer will process their messages one at a time

Where Next?

Popular in Questions Top

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
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
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
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
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
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
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
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
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
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
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