RPC Implementation Mechanism in Distributed System
In this article, we will go through the concept of the Remote Procedure Call (RPC) and its working mechanism.
RPC is an effective mechanism for building client-server systems that are distributed. RPC enhances the power and ease of programming of the client/server computing concept. It’s a protocol that allows one software to seek a service from another program on another computer in a network without having to know about the network. The software that makes the request is called a client, and the program that provides the service is called a server.
The calling parameters are sent to the remote process during a Remote Procedure Call, and the caller waits for a response from the remote procedure. The flow of activities during an RPC call between two networking systems is depicted in the diagram below.
- Syntactic transparency: This implies that there should be a similarity between the remote process and a local procedure.
- Semantic transparency: This implies that there should be similarity in the semantics i.e. meaning of a remote process and a local procedure.
Working of RPC:
There are 5 elements used in the working of RPC:
- Client Stub
- RPC Runtime
- Server Stub
- Client: The client process initiates RPC. The client makes a standard call, which triggers a correlated procedure in the client stub.
- Client Stub: Stubs are used by RPC to achieve semantic transparency. The client calls the client stub. Client stub does the following tasks:
- The first task performed by client stub is when it receives a request from a client, it packs(marshalls) the parameters and required specifications of remote/target procedure in a message.
- The second task performed by the client stub is upon receiving the result values after execution, it unpacks (unmarshalled) those results and sends them to the Client.
- RPC Runtime: The RPC runtime is in charge of message transmission between client and server via the network. Retransmission, acknowledgement, routing, and encryption are all tasks performed by it. On the client-side, it receives the result values in a message from the server-side, and then it further sends it to the client stub whereas, on the server-side, RPC Runtime got the same message from the server stub when then it forwards to the client machine. It also accepts and forwards client machine call request messages to the server stub.
- Server Stub: Server stub does the following tasks:
- The first task performed by server stub is that it unpacks(unmarshalled) the call request message which is received from the local RPC Runtime and makes a regular call to invoke the required procedure in the server.
- The second task performed by server stub is that when it receives the server’s procedure execution result, it packs it into a message and asks the local RPC Runtime to transmit it to the client stub where it is unpacked.
- Server: After receiving a call request from the client machine, the server stub passes it to the server. The execution of the required procedure is made by the server and finally, it returns the result to the server stub so that it can be passed to the client machine using the local RPC Runtime.
- The client, the client stub, and one instance of RPC Runtime are all running on the client machine.
- A client initiates a client stub process by giving parameters as normal. The client stub acquires storage in the address space of the client.
- At this point, the user can access RPC by using a normal Local Procedural Call. The RPC runtime is in charge of message transmission between client and server via the network. Retransmission, acknowledgment, routing, and encryption are all tasks performed by it.
- On the server-side, values are returned to the server stub, after the completion of server operation, which then packs (which is also known as marshaling) the return values into a message. The transport layer receives a message from the server stub.
- The resulting message is transmitted by the transport layer to the client transport layer, which then sends a message back to the client stub.
- The client stub unpacks (which is also known as unmarshalling) the return arguments in the resulting packet, and the execution process returns to the caller at this point.
When the client process requests by calling a local procedure then the procedure will pass the arguments/parameters in request format so that they can be sent in a message to the remote server. The remote server then will execute the local procedure call ( based on the request arrived from the client machine) and after execution finally returns a response to the client in the form of a message. Till this time the client is blocked but as soon as the response comes from the server side it will be able to find the result from the message. In some cases, RPCs can be executed asynchronously also in which the client will not be blocked in waiting for the response.
The parameters can be passed in two ways. The first is to pass by value, whereas the second is to pass by reference. The parameters receiving the address should be pointers when we provide it to a function. In Pass by reference, a function is called using pointers to pass the address of variables. Call by value refers to the method of sending variables’ actual values.
The language designers are usually the ones who decide which parameter passing method to utilize. It is sometimes dependent on the data type that is being provided. Integers and other scalar types are always passed by value in C, whereas arrays are always passed by reference.
Share your thoughts in the comments
Please Login to comment...