Erlang / Erlang Advanced Interview questions
What is rpc:call/4 and how does it work across distributed nodes?
rpc:call(Node, Module, Function, Args) lets one node synchronously invoke a function on
another connected node and get the result back, wrapping the underlying message-passing machinery so it looks
like an ordinary function call.
Result = rpc:call('nodeb@host', lists, sort, [[3,1,2]]). %% Result = [1,2,3], computed on nodeb and returned to the caller
Under the hood, the local rpc server sends a request to its counterpart on the remote node,
which spawns a process to execute Module:Function(Args) there and sends the result back; the
caller blocks (with an optional timeout) waiting for that reply, similar in spirit to
gen_server:call but targeting an arbitrary function rather than a specific process's callback.
Because it executes arbitrary code on the remote node, it inherits the same trust model as the rest of
distributed Erlang — any connected, cookie-authenticated node can run arbitrary functions on any other.
More Related questions...