Open In App

Remote Procedure Call (RPC) in Operating System

Last Updated : 16 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Remote Procedure Call (RPC) is a powerful technique for constructing distributed, client-server based applications. It is based on extending the conventional local procedure calling so that the called procedure does not exist in the same address space as the calling procedure. The two processes may be on the same system, or they may be on different systems with a network connecting them. 

What is Remote Procedure Call (RPC)?

Remote Procedure Call (RPC) is a type of technology used in computing to enable a program to request a service from software located on another computer in a network without needing to understand the network's details. RPC abstracts the complexities of the network by allowing the developer to think in terms of function calls rather than network details, facilitating the process of making a piece of software distributed across different systems.

RPC works by allowing one program (a client) to directly call procedures (functions) on another machine (the server). The client makes a procedure call that appears to be local but is run on a remote machine. When an RPC is made, the calling arguments are packaged and transmitted across the network to the server. The server unpacks the arguments, performs the desired procedure, and sends the results back to the client. 

Working of a RPC

RPC working

1. A client invokes a client stub procedure, passing parameters in the usual way. The client stub resides within the client's own address space. 

2. 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. 

3. 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. 

4. 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.

5. 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. 

6. The client stub demarshalls the return parameters and execution returns to the caller.

How to Make a Remote Procedure Call?

Working of RPC

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. 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.

Types of RPC

  • Callback RPC: Callback RPC allows processes to act as both clients and servers. It helps with remote processing of interactive applications. The server gets a handle to the client, and the client waits during the callback. This type of RPC manages callback deadlocks and enables peer-to-peer communication between processes.
  • Broadcast RPC: In Broadcast RPC, a client's request is sent to all servers on the network that can handle it. This type of RPC lets you specify that a client's message should be broadcast. You can set up special broadcast ports. Broadcast RPC helps reduce the load on the network.
  • Batch-mode RPC: Batch-mode RPC collects multiple RPC requests on the client side and sends them to the server in one batch. This reduces the overhead of sending many separate requests. Batch-mode RPC works best for applications that don't need to make calls very often. It requires a reliable way to send data.

What Does RPC do?

RPC stands for Remote Procedure Call. It lets a program on one computer use code on another computer as if it were on the same computer. When a program with RPC is made ready to run, it includes a helper part called a stub. This stub acts like the remote code. When the program runs and tries to use the remote code, the stub gets this request. It then sends it to another helper program on the same computer. The first time this happens, the helper program asks a special computer where to find the remote code.

The helper program then sends a message over the internet to the other computer, asking it to run the remote code. The other computer also has helper programs that work with the remote code. When the remote code is done, it sends the results back the same way. This whole process makes it seem like the remote code is running on the local computer, even though it's actually running somewhere else.

Issues of the RPC

RPC Runtime: RPC run-time system is a library of routines and a set of services that handle the network communications that underlie the RPC mechanism. In the course of an RPC call, client-side and server-side run-time systems' code handle binding, establish communications over an appropriate protocol, pass call data between the client and server, and handle communications errors. 

Stub: The function of the stub is to provide transparency to the programmer-written application code. On the client side, the stub handles the interface between the client's local procedure call and the run-time system, marshalling and unmarshalling data, invoking the RPC run-time protocol, and if requested, carrying out some of the binding steps. 

On the server side, the stub provides a similar interface between the run-time system and the local manager procedures that are executed by the server.

Binding: The most flexible solution is to use dynamic binding and find the server at run time when the RPC is first made. The first time the client stub is invoked, it contacts a name server to determine the transport address at which the server resides. Binding consists of two parts

  • Naming: A Server having a service to offer exports an interface for it. Exporting an interface registers it with the system so that clients can use it.
  • Locating: A Client must import an (exported) interface before communication can begin.

The call semantics associated with RPC

  • Retry Request Message: Whether to retry sending a request message when a server has failed or the receiver didn't receive the message.
  • Duplicate Filtering: Remove the duplicate server requests.
  • Retransmission of Results: To resend lost messages without re-executing the operations at the server side.

Advantages

  • Easy Communication: RPC lets clients talk to servers using normal procedure calls in high-level programming languages. This makes it simple for programmers to work with.
  • Hidden Complexity: RPC hides the details of how messages are sent between computers. This means programmers don't need to worry about the underlying network communication.
  • Flexibility: RPC can be used in both local and distributed environments. This makes it versatile for different types of applications.

Disadvantages

  • Limited Parameter Passing: RPC can only pass parameters by value. It can't pass pointers, which limits what can be sent between computers.
  • Slower Than Local Calls: Remote procedure calls take longer than local procedure calls because they involve network communication.
  • Vulnerable to Failures: RPC depends on network connections, other machines, and separate processes. This makes it more likely to fail than local procedure calls.

RPC vs REST

RPC and REST are two ways to make computer programs talk to each other over the internet. They're different, but both are useful. RPC is good for some things, and REST is good for others. Some companies need RPC, while others prefer REST. Sometimes, developers use both RPC and REST in the same project, but not in the same part of the program. RPC is an old idea, but new versions like gRPC and DRPC are making it popular again. Developers are still using and improving these new types of RPC.

It's hard to say which one is better - RPC or REST. They're both good when used the right way. The best choice depends on what you're trying to do with your program.

Conclusion

Remote Procedure Call (RPC) in operating systems allows programs to run functions on other computers as if they were on the same machine. It simplifies building distributed programs by hiding the complexities of network communication. RPC works by having the operating system handle the details of sending requests and receiving responses between computers.

While it makes programming easier and enables better use of multiple computers, RPC can be slower than local function calls and depends on network reliability. Despite these challenges, RPC remains a useful tool for creating systems that work across multiple computers, making it an important concept in modern operating systems.


Next Article
Article Tags :
Practice Tags :

Similar Reads