Nebulex.Distributed.RPC (Nebulex.Distributed v3.0.0-rc.1)
View SourceRPC utilities.
Summary
Types
Task callback
Group entry: node -> NFA call
Node group
Reducer accumulator
Reducer function spec
Functions
Evaluates apply(mod, fun, args)
on node node
and returns the corresponding
evaluation result.
Similar to multicall/7
, but it allows specifying the MFA per node.
In contrast to a regular single-node RPC, a multicall is an RPC that is sent
concurrently from one client to multiple servers. The function evaluates
apply(module, fun, args)
on the specified nodes and collects the answers.
Then, evaluates the reducer_fun
function on each answer.
Types
Task callback
Group entry: node -> NFA call
@type node_mfa_map() :: %{optional(node()) => mfa_call()} | [node_mfa_call()]
Node group
@type reducer_acc() :: any()
Reducer accumulator
@type reducer_fun() :: (result :: any(), node_mfa_call() | node(), reducer_acc() -> any())
Reducer function spec
Functions
Evaluates apply(mod, fun, args)
on node node
and returns the corresponding
evaluation result.
A timeout, in milliseconds or :infinity
, can be given with a default value
of 5000
.
Example
iex> Nebulex.Distributed.RPC.call(node(), Map, :new, [[]])
%{}
@spec multi_mfa_call(node_mfa_map(), timeout(), reducer_acc(), reducer_fun()) :: any()
Similar to multicall/7
, but it allows specifying the MFA per node.
Example
iex> node = node()
iex> alias Nebulex.Distributed.RPC
iex> RPC.multi_mfa_call(%{node => {Map, :new, [[foo: :bar]]}})
{[{{:"primary@127.0.0.1", {Map, :new, [[foo: :bar]]}}, %{foo: :bar}}], []}
iex> RPC.multi_mfa_call(%{node => {Map, :new, [[foo: :bar]]}}, 1000)
{[{{:"primary@127.0.0.1", {Map, :new, [[foo: :bar]]}}, %{foo: :bar}}], []}
iex> RPC.multi_mfa_call(
...> %{node => {Map, :new, [[foo: :bar]]}},
...> 1000,
...> {[], []}
...> )
{[{{:"primary@127.0.0.1", {Map, :new, [[foo: :bar]]}}, %{foo: :bar}}], []}
@spec multicall( [node()], module(), atom(), [any()], timeout(), reducer_acc(), reducer_fun() ) :: any()
In contrast to a regular single-node RPC, a multicall is an RPC that is sent
concurrently from one client to multiple servers. The function evaluates
apply(module, fun, args)
on the specified nodes and collects the answers.
Then, evaluates the reducer_fun
function on each answer.
Example
iex> alias Nebulex.Distributed.RPC
iex> RPC.multicall([node()], Map, :new, [[foo: :bar]])
{[{:"primary@127.0.0.1", %{foo: :bar}}], []}
iex> RPC.multicall([node()], Map, :new, [[foo: :bar]], 1000)
{[{:"primary@127.0.0.1", %{foo: :bar}}], []}
iex> RPC.multicall([node()], Map, :new, [[foo: :bar]], 1000, {[], []})
{[{:"primary@127.0.0.1", %{foo: :bar}}], []}