RPC - jellyfish-tom/TIL GitHub Wiki

[SOURCES]

RPC APIs

Remote Procedure Call (RPC) is a methodology used for constructing distributed, client-server-based applications. It is also called a subroutine call or a function call. It is based on conventional local procedure calling so that the called procedure need not exist in the very same address space as the calling procedure executes. RPC is very well suited for a client-server interaction in which the flow of control lingers between the two. The client and server do not both execute at the same time instead the thread of execution jumps from one to another.

The RPC protocol is built on top of the eXternal Data Representation (XDR) protocol, which standardizes the representation of data in remote communications. XDR converts the parameters and results of each RPC service provided.

When making a Remote Procedure Call:

  1. The calling environment is suspended, procedure parameters are transferred across the network to the environment where the procedure is to execute, and the procedure is executed there.

  2. When the procedure finishes and produces its results, its results are transferred back to the calling environment, where execution resumes as if returning from a regular procedure call.

NOTE: RPC is especially well suited for client-server (e.g. query-response) interaction in which the flow of control alternates between the caller and callee. Conceptually, the client and server do not both execute at the same time. Instead, the thread of execution jumps from the caller to the callee and then back again.

The following steps take place during a RPC :

A client invokes a client stub procedure, passing parameters in the usual way. The client stub resides within the client’s own address space. The client stub marshalls(pack) the parameters into a message. Marshalling includes converting the representation of the parameters into a standard format, and copying each parameter into the message. The client stub passes the message to the transport layer, which sends it to the remote server machine. On the server, the transport layer passes the message to a server stub, which demarshalls(unpack) the parameters and calls the desired server routine using the regular procedure call mechanism. When the server procedure completes, it returns to the server stub (e.g., via a normal procedure call return), which marshalls the return values into a message. The server stub then hands the message to the transport layer. The transport layer sends the result message back to the client transport layer, which hands the message back to the client stub. The client stub demarshalls the return parameters and execution returns to the caller.

Advantages of RPC APIs

They provide usage op applications in both local and distributed environments. It provides ABSTRACTION. They have lightweight payloads, therefore, provides high performance. They are easy to understand and work as the action is part of the URL.

Disadvantages of RPC APIs

It can be implemented in many ways as it is not well standardized.

It has no flexibility for hardware architecture.

REST vs RPC