Remote Procedure Calls (RPC)
Distributed Operating System:: RPC (REMOTE PROCDURE CALL)
No message passing at all is visible to the programmer. This method is known as Remote Procedure Call, or often just RPC
The RPC mechanism is an extension of a normal procedure call mechanism.
The RPC model is used for transfer of control and data within a program
The caller (also known as the client process) sends a call (request) message to the callee (also known as the server process) and waits (blocks) for a reply message.
A major issue in the design of an RPC facility is its transparency property
Syntactic Transparency: A remote procedure call should have the same syntax as a local procedure call, which is not very difficult to achieve.
Semantic Transparency: Semantics of remote procedure calls are identical to those of local procedure calls.
Unlike local procedure calls, the called procedure is executed in an address space that is disjoint from the calling program’s address space.
– called procedure has no access to the local environment.
– Passing addresses (pointers) as arguments is meaningless.
– So, passing pointers as parameters is not attractive. An alternative may be to send a copy of the value pointed.
– Call by reference can be replaced by copy in/copy out but at the cost of slightly different semantics.
Remote procedure calls are more vulnerable to failure than local procedure calls
– Programs that make use of RPC must have the capability to handle this type of error.
– This makes it more difficult to make RPCs transparent.
RPCs consume much more time (100 to 1000 times) than local procedure calls due to the involvement of communication network.
So, achieving semantic transparency is not easy.
To achieve the goal of semantic transparency, the implementation of RPC is based on the concept of stubs
Stubs provide a perfectly normal local procedure call abstraction.
To hide the existence of functional details of the underlying network, an RPC communication package (called RPC runtime) is used in both the client and server sides.
implementation of an RPC mechanism involves the following five elements:
1. The Client
2. The Client stub
3. The RPC Runtime
4. The server stub, and
5. The server
Client: To invoke a remote procedure, a client makes a perfectly local call that invokes the corresponding procedure in the stub
Client Stub: The client stub is responsible for performing the following tasks:
· On receipt of a call request from the client, it packs the specification of the target procedure and the arguments into a message and asks the local runtime system to send it to the server stub.
· On receipt of the result of procedure execution, it unpacks the result and passes it to the client.
RPCRuntime: The RPC runtime handles the transmission of the messages across the network between client and server machines. It is responsible for retransmissions, acknowledgements, and encryption.
· On the client side, it receives the call request from the client stub and sends it to the server machine. It also receives reply message (result of procedure execution) from the server machine and passes it to the client stub.
· On the server side, it receives the results of the procedure execution from the server stub and sends it to the client machine. It also receives the request message from the client machine and passes it to the server stub.
Server Stub: The functions of server stub are similar to that of the client stub. It performs the following two tasks:
- The server stub unpacks the call receipt messages from local RPCRuntime and makes a perfect local call to invoke the appropriate procedure in the server.
- The server stub packs the results of the procedure execution received from server, and asks the local RPCRuntime to send it to the client stub.
Server: On receiving the call request from the server stub, the server executes the appropriate procedure and returns the result to the server stub.
Manual Stub Generation: RPC implementer provides a set of translation functions from which user can construct his own stubs. It is simple to implement and can handle complex parameters.
Automatic Stub Generation: This is the most commonly used technique for stub generation. It uses an Interface Definition Language (IDL), for defining the interface between the client and server.
An interface definition also contains information to indicate whether each argument is an input, output or both.
A server program that implements procedures in an interface is said to export the interface. A client program that calls the procedures is said to import the interface.
The interface definition is processed using an IDL compiler (the IDL compiler in Sun RPC is called rpcgen) to generate components that can be combined with both client and server programs, without making changes to the existing compilers.
The client stubs are compiled and linked with the client program and the server stubs are compiled and linked with server program.
Any remote procedure call involves a client process and a server process that are possibly located on different computers.
Call messages sent by the client to server for requesting execution of particular remote procedure.
Reply messages sent by the server to the client for returning the result.
The transfer of message data between two computers requires encoding and decoding of message data. In case of RPCs this operation is known as Marshalling
The marshalling process must reflect the structure of all types of program objects used in the concerned language.
Server Implementation: Based on the style of implementation used servers may be of two types: Stateful and Stateless.
A stateful server maintains client’s state information from one remote procedure call to the next.
Open (filename, mode): used to open filename in specified mode. When the server executes this operation, it creates an entry for this file in a file-table that is used for maintaining state information.
Read (fid, n, buffer): This operation returns n bytes of file data starting from the byte currently addressed by the read-write pointer and then increments the pointer by n.
Write (fid, n, buffer): The server takes n bytes of data from the buffer and writes to the file identified by the read-write pointer.
Seek (fid, position): causes to change the value of the read pointer.
Close (fid): causes the server to delete the file state information from the file-table.
Stateless Server: A stateless server does not maintain any client state information. So every request must accompany with all the necessary parameters.
Read (filename, position, n, buffer): Read n bytes from the file from position.
Write (filename, position, n, buffer): Write n bytes from buffer to file starting at position.
Merits of a stateful server: A stateful server provides an easier programming paradigm. It is typically more efficient than stateless servers.
Demerits of stateful server: If the server crashes and restarts, the state information it was holding may be lost and the client may produce inconsistent results. If the client process crashes and restarts, the server will have inconsistent information about the client.
Instance-per-call-servers: They exist only for the duration of a single call
Call-by-Value: All parameters are copied into a message that is transmitted.
This is possible only in a distributed shared memory system. it is also possible in object-based systems, because in this case client needs to pass the names of objects, which are like reference. In object-based systems it is called call-by-object-reference.
To avoid many remote references, another parameter-passing mode, called call-by-move was proposed
The Request Protocol: Also known as the R protocol. It is useful for RPCs in which the called procedure has nothing to return and the client does not require confirmation for the procedure having been executed. An RPC protocol that uses R protocol is also called asynchronous RPC.
Request/Reply Protocol (RR protocol): It is a basic idea to eliminate acknowledgements.
The Request/Reply/Acknowledge-Reply Protocol (RRA): It is useful for the design of systems involving simple RPCs. The server needs to keep a copy of the reply only until it receives the acknowledgement for reply from client
Broadcasting: A broadcast message is sent to locate the server. The first server responding to this message is used by the client. OK for small networks.
Binding Agent: A binding agent is basically a name server used to bind a client to a server by providing information about the desired server.
Binding at Link Time: A server exports its service by registering with the binding agent as part of the initialization process
Binding at Call Time: A client is bound to a server at the time when it calls the server for the first time during execution.
Indirect Call Method: When a client calls the server for the first time, it passes the server’s interface name and the arguments of the RPC call to the binding agent
The encryption techniques provide protection from eavesdropping and detect attempts at modifications, replay, or creation of calls.