[erlang-questions] Why RPC in Erlang? [was: How RPC works in erlang?]
Fri Oct 6 04:37:02 CEST 2017
On 2017年10月06日 金曜日 04:18:22 Heinz N. Gies wrote:
> RPC is used for tests (when you want to control another node) and
> CLI wrappers, (when you want to execute commands on a remote node
> from a script). In both cases it makes sense and isn’t at odds with
> the erlang principles.
I didn't say it was at odds with Erlang principles. I said the rpc
module is essentially useless.
Thinking that the rpc module is specially useful for tests, CLI
wrappers, or when you want to execute commands on a remote node (from
a script or otherwise) is a bit of an odd conclusion to draw, given
the way that the even-arity spawn_* functions work.
If you mean "the IO redirect thing" then sure, the group leader is
switched if you pass the call through rex so calls to an IO function
on the remote node will turn up on the local shell.
But that prompts the question:
Why aren't you returning a value in the first place?
Asking for a remote note to cause a side effect on the local node
violates the concept of RPC, actually. Which leads me to think that
this module is inappropriately named.
When people want to offload an expensive procedure (that is, actually
remotely call a procedure) they either send it over some protocol
unrelated to disterl or use spawn_monitor/2,4 directly -- they don't
tend pass it through rex. When people want a special IO side effect so
that remote calls to IO functions magically redirect themselves to the
calling node they use the rpc module -- which is not at all what the
term RPC means. The semantics surrounding this trips up quite a few
beginners I've noticed (noticed a lot more this month as a new school
session has really gotten in gear).
More information about the erlang-questions