.TH rpc 3erl "kernel 8.5.4.2" "Ericsson AB" "Erlang Module Definition" .SH NAME rpc \- Remote Procedure Call services. .SH DESCRIPTION .LP This module contains services similar to Remote Procedure Calls\&. It also contains broadcast facilities and parallel evaluators\&. A remote procedure call is a method to call a function on a remote node and collect the answer\&. It is used for collecting information on a remote node, or for running a function with some specific side effects on the remote node\&. .LP .RS -4 .B Note: .RE \fIrpc:call()\fR\& and friends makes it quite hard to distinguish between successful results, raised exceptions, and other errors\&. This cannot be changed due to compatibility reasons\&. As of OTP 23, a new module \fIerpc\fR\& was introduced in order to provide an API that makes it possible to distinguish between the different results\&. The \fIerpc\fR\& module provides a subset (however, the central subset) of the functionality available in the \fIrpc\fR\& module\&. The \fIerpc\fR\& implementation also provides a more scalable implementation with better performance than the original \fIrpc\fR\& implementation\&. However, since the introduction of \fIerpc\fR\&, the \fIrpc\fR\& module implements large parts of its central functionality using \fIerpc\fR\&, so the \fIrpc\fR\& module won\&'t not suffer scalability wise and performance wise compared to \fIerpc\fR\&\&. .SH DATA TYPES .nf \fBkey()\fR\& .br .fi .RS .LP Opaque value returned by \fIasync_call/4\fR\&\&. .RE .SH EXPORTS .LP .nf .B abcast(Name, Msg) -> abcast .br .fi .br .RS .LP Types: .RS 3 Name = atom() .br Msg = term() .br .RE .RE .RS .LP Equivalent to \fIabcast([node()|nodes()], Name, Msg)\fR\&\&. .RE .LP .nf .B abcast(Nodes, Name, Msg) -> abcast .br .fi .br .RS .LP Types: .RS 3 Nodes = [node()] .br Name = atom() .br Msg = term() .br .RE .RE .RS .LP Broadcasts the message \fIMsg\fR\& asynchronously to the registered process \fIName\fR\& on the specified nodes\&. .RE .LP .nf .B async_call(Node, Module, Function, Args) -> Key .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br Key = key() .br .RE .RE .RS .LP Implements \fIcall streams with promises\fR\&, a type of RPC that does not suspend the caller until the result is finished\&. Instead, a key is returned, which can be used later to collect the value\&. The key can be viewed as a promise to deliver the answer\&. .LP In this case, the key \fIKey\fR\& is returned, which can be used in a subsequent call to \fIyield/1\fR\& or \fInb_yield/1,2\fR\& to retrieve the value of evaluating \fIapply(Module, Function, Args)\fR\& on node \fINode\fR\&\&. .LP .RS -4 .B Note: .RE If you want the ability to distinguish between results, you may want to consider using the \fIerpc:send_request()\fR\& function from the \fIerpc\fR\& module instead\&. This also gives you the ability retrieve the results in other useful ways\&. .LP .RS -4 .B Note: .RE \fIyield/1\fR\& and \fInb_yield/1,2\fR\& must be called by the same process from which this function was made otherwise they will never yield correctly\&. .LP .RS -4 .B Note: .RE You cannot make \fIany\fR\& assumptions about the process that will perform the \fIapply()\fR\&\&. It may be an \fIrpc\fR\& server, another server, or a freshly spawned process\&. .RE .LP .nf .B block_call(Node, Module, Function, Args) -> Res | {badrpc, Reason} .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br Res = Reason = term() .br .RE .RE .RS .LP The same as calling \fIrpc:block_call(Node, Module, Function, Args, infinity)\fR\&\&. .RE .LP .nf .B block_call(Node, Module, Function, Args, Timeout) -> .B Res | {badrpc, Reason} .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br Res = Reason = term() .br Timeout = 0\&.\&.4294967295 | infinity .br .RE .RE .RS .LP The same as calling \fIrpc:call(Node, Module, Function, Args, Timeout)\fR\& with the exception that it also blocks other \fIrpc:block_call()\fR\& operations from executing concurrently on the node \fINode\fR\&\&. .LP .RS -4 .B Warning: .RE Note that it also blocks other operations than just \fIrpc:block_call()\fR\& operations, so use it with care\&. .RE .LP .nf .B call(Node, Module, Function, Args) -> Res | {badrpc, Reason} .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br Res = Reason = term() .br .RE .RE .RS .LP Evaluates \fIapply(Module, Function, Args)\fR\& on node \fINode\fR\& and returns the corresponding value \fIRes\fR\&, or \fI{badrpc, Reason}\fR\& if the call fails\&. The same as calling \fIrpc:call(Node, Module, Function, Args, infinity)\fR\&\&. .RE .LP .nf .B call(Node, Module, Function, Args, Timeout) -> .B Res | {badrpc, Reason} .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br Res = Reason = term() .br Timeout = 0\&.\&.4294967295 | infinity .br .RE .RE .RS .LP Evaluates \fIapply(Module, Function, Args)\fR\& on node \fINode\fR\& and returns the corresponding value \fIRes\fR\&, or \fI{badrpc, Reason}\fR\& if the call fails\&. \fITimeout\fR\& is a time-out value in milliseconds\&. If the call times out, \fIReason\fR\& is \fItimeout\fR\&\&. .LP If the reply arrives after the call times out, no message contaminates the caller\&'s message queue\&. .LP .RS -4 .B Note: .RE If you want the ability to distinguish between results, you may want to consider using the \fIerpc:call()\fR\& function from the \fIerpc\fR\& module instead\&. .LP .RS -4 .B Note: .RE Here follows the details of what exactly is returned\&. .LP \fI{badrpc, Reason}\fR\& will be returned in the following circumstances: .RS 2 .TP 2 * The called function fails with an \fIexit\fR\& exception\&. .LP .TP 2 * The called function fails with an \fIerror\fR\& exception\&. .LP .TP 2 * The called function returns a term that matches \fI{\&'EXIT\&', _}\fR\&\&. .LP .TP 2 * The called function \fIthrows\fR\& a term that matches \fI{\&'EXIT\&', _}\fR\&\&. .LP .RE .LP \fIRes\fR\& is returned in the following circumstances: .RS 2 .TP 2 * The called function returns normally with a term that does \fBnot\fR\& match \fI{\&'EXIT\&',_}\fR\&\&. .LP .TP 2 * The called function \fIthrow\fR\&s a term that does \fBnot\fR\& match \fI{\&'EXIT\&',_}\fR\&\&. .LP .RE .LP .RS -4 .B Note: .RE You cannot make \fIany\fR\& assumptions about the process that will perform the \fIapply()\fR\&\&. It may be the calling process itself, an \fIrpc\fR\& server, another server, or a freshly spawned process\&. .RE .LP .nf .B cast(Node, Module, Function, Args) -> true .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br .RE .RE .RS .LP Evaluates \fIapply(Module, Function, Args)\fR\& on node \fINode\fR\&\&. No response is delivered and the calling process is not suspended until the evaluation is complete, as is the case with \fIcall/4,5\fR\&\&. .LP .RS -4 .B Note: .RE You cannot make \fIany\fR\& assumptions about the process that will perform the \fIapply()\fR\&\&. It may be an \fIrpc\fR\& server, another server, or a freshly spawned process\&. .RE .LP .nf .B eval_everywhere(Module, Function, Args) -> abcast .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Args = [term()] .br .RE .RE .RS .LP Equivalent to \fIeval_everywhere([node()|nodes()], Module, Function, Args)\fR\&\&. .RE .LP .nf .B eval_everywhere(Nodes, Module, Function, Args) -> abcast .br .fi .br .RS .LP Types: .RS 3 Nodes = [node()] .br Module = module() .br Function = atom() .br Args = [term()] .br .RE .RE .RS .LP Evaluates \fIapply(Module, Function, Args)\fR\& on the specified nodes\&. No answers are collected\&. .RE .LP .nf .B multi_server_call(Name, Msg) -> {Replies, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Name = atom() .br Msg = term() .br Replies = [Reply :: term()] .br BadNodes = [node()] .br .RE .RE .RS .LP Equivalent to \fImulti_server_call([node()|nodes()], Name, Msg)\fR\&\&. .RE .LP .nf .B multi_server_call(Nodes, Name, Msg) -> {Replies, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Nodes = [node()] .br Name = atom() .br Msg = term() .br Replies = [Reply :: term()] .br BadNodes = [node()] .br .RE .RE .RS .LP Can be used when interacting with servers called \fIName\fR\& on the specified nodes\&. It is assumed that the servers receive messages in the format \fI{From, Msg}\fR\& and reply using \fIFrom ! {Name, Node, Reply}\fR\&, where \fINode\fR\& is the name of the node where the server is located\&. The function returns \fI{Replies, BadNodes}\fR\&, where \fIReplies\fR\& is a list of all \fIReply\fR\& values, and \fIBadNodes\fR\& is one of the following: .RS 2 .TP 2 * A list of the nodes that do not exist .LP .TP 2 * A list of the nodes where the server does not exist .LP .TP 2 * A list of the nodes where the server terminated before sending any reply\&. .LP .RE .RE .LP .nf .B multicall(Module, Function, Args) -> {ResL, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Args = [term()] .br ResL = [Res :: term() | {badrpc, Reason :: term()}] .br BadNodes = [node()] .br .RE .RE .RS .LP Equivalent to \fImulticall([node()|nodes()], Module, Function, Args, infinity)\fR\&\&. .RE .LP .nf .B multicall(Nodes, Module, Function, Args) -> {ResL, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Nodes = [node()] .br Module = module() .br Function = atom() .br Args = [term()] .br ResL = [Res :: term() | {badrpc, Reason :: term()}] .br BadNodes = [node()] .br .RE .RE .RS .LP Equivalent to \fImulticall(Nodes, Module, Function, Args, infinity)\fR\&\&. .RE .LP .nf .B multicall(Module, Function, Args, Timeout) -> {ResL, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Args = [term()] .br Timeout = 0\&.\&.4294967295 | infinity .br ResL = [Res :: term() | {badrpc, Reason :: term()}] .br BadNodes = [node()] .br .RE .RE .RS .LP Equivalent to \fImulticall([node()|nodes()], Module, Function, Args, Timeout)\fR\&\&. .RE .LP .nf .B multicall(Nodes, Module, Function, Args, Timeout) -> .B {ResL, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Nodes = [node()] .br Module = module() .br Function = atom() .br Args = [term()] .br Timeout = 0\&.\&.4294967295 | infinity .br ResL = [Res :: term() | {badrpc, Reason :: term()}] .br BadNodes = [node()] .br .RE .RE .RS .LP In contrast to an RPC, a multicall is an RPC that is sent concurrently from one client to multiple servers\&. This is useful for collecting information from a set of nodes, or for calling a function on a set of nodes to achieve some side effects\&. It is semantically the same as iteratively making a series of RPCs on all the nodes, but the multicall is faster, as all the requests are sent at the same time and are collected one by one as they come back\&. .LP The function evaluates \fIapply(Module, Function, Args)\fR\& on the specified nodes and collects the answers\&. It returns \fI{ResL, BadNodes}\fR\&, where \fIBadNodes\fR\& is a list of the nodes that do not exist, and \fIResL\fR\& is a list of the return values, or \fI{badrpc, Reason}\fR\& for failing calls\&. \fITimeout\fR\& is a time (integer) in milliseconds, or \fIinfinity\fR\&\&. .LP The following example is useful when new object code is to be loaded on all nodes in the network, and indicates some side effects that RPCs can produce: .LP .nf %% Find object code for module Mod {Mod, Bin, File} = code:get_object_code(Mod), %% and load it on all nodes including this one {ResL, _} = rpc:multicall(code, load_binary, [Mod, File, Bin]), %% and then maybe check the ResL list. .fi .LP .RS -4 .B Note: .RE If you want the ability to distinguish between results, you may want to consider using the \fIerpc:multicall()\fR\& function from the \fIerpc\fR\& module instead\&. .LP .RS -4 .B Note: .RE You cannot make \fIany\fR\& assumptions about the process that will perform the \fIapply()\fR\&\&. It may be the calling process itself, an \fIrpc\fR\& server, another server, or a freshly spawned process\&. .RE .LP .nf .B nb_yield(Key) -> {value, Val} | timeout .br .fi .br .RS .LP Types: .RS 3 Key = key() .br Val = (Res :: term()) | {badrpc, Reason :: term()} .br .RE .RE .RS .LP Equivalent to \fInb_yield(Key, 0)\fR\&\&. .RE .LP .nf .B nb_yield(Key, Timeout) -> {value, Val} | timeout .br .fi .br .RS .LP Types: .RS 3 Key = key() .br Timeout = 0\&.\&.4294967295 | infinity .br Val = (Res :: term()) | {badrpc, Reason :: term()} .br .RE .RE .RS .LP Non-blocking version of \fIyield/1\fR\&\&. It returns the tuple \fI{value, Val}\fR\& when the computation is finished, or \fItimeout\fR\& when \fITimeout\fR\& milliseconds has elapsed\&. .LP See the note in \fIcall/4\fR\& for more details of Val\&. .LP .RS -4 .B Note: .RE This function must be called by the same process from which \fIasync_call/4\fR\& was made otherwise it will only return \fItimeout\fR\&\&. .RE .LP .nf .B parallel_eval(FuncCalls) -> ResL .br .fi .br .RS .LP Types: .RS 3 FuncCalls = [{Module, Function, Args}] .br Module = module() .br Function = atom() .br Args = ResL = [term()] .br .RE .RE .RS .LP Evaluates, for every tuple in \fIFuncCalls\fR\&, \fIapply(Module, Function, Args)\fR\& on some node in the network\&. Returns the list of return values, in the same order as in \fIFuncCalls\fR\&\&. .RE .LP .nf .B pinfo(Pid) -> [{Item, Info}] | undefined .br .fi .br .RS .LP Types: .RS 3 Pid = pid() .br Item = atom() .br Info = term() .br .RE .RE .RS .LP Location transparent version of the BIF \fIerlang:process_info/1\fR\& in ERTS\&. .RE .LP .nf .B pinfo(Pid, Item) -> {Item, Info} | undefined | [] .br .fi .br .nf .B pinfo(Pid, ItemList) -> [{Item, Info}] | undefined | [] .br .fi .br .RS .LP Types: .RS 3 Pid = pid() .br Item = atom() .br ItemList = [Item] .br Info = term() .br .RE .RE .RS .LP Location transparent version of the BIF \fIerlang:process_info/2\fR\& in ERTS\&. .RE .LP .nf .B pmap(FuncSpec, ExtraArgs, List1) -> List2 .br .fi .br .RS .LP Types: .RS 3 FuncSpec = {Module, Function} .br Module = module() .br Function = atom() .br ExtraArgs = [term()] .br List1 = [Elem :: term()] .br List2 = [term()] .br .RE .RE .RS .LP Evaluates \fIapply(Module, Function, [Elem|ExtraArgs])\fR\& for every element \fIElem\fR\& in \fIList1\fR\&, in parallel\&. Returns the list of return values, in the same order as in \fIList1\fR\&\&. .RE .LP .nf .B sbcast(Name, Msg) -> {GoodNodes, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Name = atom() .br Msg = term() .br GoodNodes = BadNodes = [node()] .br .RE .RE .RS .LP Equivalent to \fIsbcast([node()|nodes()], Name, Msg)\fR\&\&. .RE .LP .nf .B sbcast(Nodes, Name, Msg) -> {GoodNodes, BadNodes} .br .fi .br .RS .LP Types: .RS 3 Name = atom() .br Msg = term() .br Nodes = GoodNodes = BadNodes = [node()] .br .RE .RE .RS .LP Broadcasts the message \fIMsg\fR\& synchronously to the registered process \fIName\fR\& on the specified nodes\&. .LP Returns \fI{GoodNodes, BadNodes}\fR\&, where \fIGoodNodes\fR\& is the list of nodes that have \fIName\fR\& as a registered process\&. .LP The function is synchronous in the sense that it is known that all servers have received the message when the call returns\&. It is not possible to know that the servers have processed the message\&. .LP Any further messages sent to the servers, after this function has returned, are received by all servers after this message\&. .RE .LP .nf .B server_call(Node, Name, ReplyWrapper, Msg) -> .B Reply | {error, Reason} .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Name = atom() .br ReplyWrapper = Msg = Reply = term() .br Reason = nodedown .br .RE .RE .RS .LP Can be used when interacting with a server called \fIName\fR\& on node \fINode\fR\&\&. It is assumed that the server receives messages in the format \fI{From, Msg}\fR\& and replies using \fIFrom ! {ReplyWrapper, Node, Reply}\fR\&\&. This function makes such a server call and ensures that the entire call is packed into an atomic transaction, which either succeeds or fails\&. It never hangs, unless the server itself hangs\&. .LP The function returns the answer \fIReply\fR\& as produced by the server \fIName\fR\&, or \fI{error, Reason}\fR\&\&. .RE .LP .nf .B yield(Key) -> Res | {badrpc, Reason} .br .fi .br .RS .LP Types: .RS 3 Key = key() .br Res = Reason = term() .br .RE .RE .RS .LP Returns the promised answer from a previous \fIasync_call/4\fR\&\&. If the answer is available, it is returned immediately\&. Otherwise, the calling process is suspended until the answer arrives from \fINode\fR\&\&. .LP .RS -4 .B Note: .RE This function must be called by the same process from which \fIasync_call/4\fR\& was made otherwise it will never return\&. .LP See the note in \fIcall/4\fR\& for more details of the return value\&. .RE