I’d like to execute some procedure on a remote node. And I’m not sure which is the best way to do this. I can write a rpc:call to do this. Or send a message by Remote ! {call, some_procedure} to the node to start the procedure and use receive waiting for the response. So which way is better in erlang? Or they actually are for different usage?
I’d like to execute some procedure on a remote node. And I’m not sure
Share
It’s better to use module
rpc, because if you don’t: you’ll have to manage monitoring of remote node, have to provide unique id of the call, handle timeouts, also you’re have to provide wrapper to send-back response with result of function.But all of these manipulations are generic, and implemented in
rpcmodule.By the way, there are different variations of remote calls, which implemented in
rpc: synchronous and asynchronous calls, cast (send message which doesn’t need response), even parallel map function (pmap).P.S.
Compare – simply using rpc:call vs. implement that from scratch (also, this is simple implementation, which doesn’t handle some important cases):