Nebulex.Distributed.RPC (Nebulex.Distributed v3.0.0-rc.1)

View Source

RPC 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.

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

mfa_call()

@type mfa_call() :: {module(), atom(), [any()]}

Task callback

node_mfa_call()

@type node_mfa_call() :: {node(), mfa_call()}

Group entry: node -> NFA call

node_mfa_map()

@type node_mfa_map() :: %{optional(node()) => mfa_call()} | [node_mfa_call()]

Node group

reducer_acc()

@type reducer_acc() :: any()

Reducer accumulator

reducer_fun()

@type reducer_fun() :: (result :: any(), node_mfa_call() | node(), reducer_acc() ->
                    any())

Reducer function spec

Functions

call(node, mod, fun, args, timeout \\ 5000)

@spec call(node(), module(), atom(), [any()], timeout()) :: any()

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, [[]])
%{}

multi_mfa_call(node_group, timeout \\ 5000, reducer_acc \\ {[], []}, reducer_fun \\ default_reducer())

@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}}], []}

multicall(nodes, mod, fun, args, timeout \\ 5000, reducer_acc \\ {[], []}, reducer_fun \\ default_reducer())

@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}}], []}