Remote Procedure Call
Remote Procedure Call
Call
Chapter Outline
• Discussion on most primitive service, request-reply
communication, which represents relatively minor
enhancements to the underlying interprocess communication
primitives
• Discussion on the two most prominent remote invocation
techniques for communication in distributed systems
• The remote procedure call (RPC) approach extends the common
programming abstraction of the procedure call to distributed
environments, allowing a calling process to call a procedure in a
remote node as if it is local
• Remote method invocation (RMI) is similar to RPC but for
distributed objects.
Introduction
by Kumudha Raimond
Middleware
⚫ Middleware consists of a layer of services added between those of a regular
network OS and the actual applications
⚫ It offers an infrastructure that enables application processes to
communicate with each other
⚫ It facilitates the implementation of distributed applications and attempt to
hide the heterogeneity of the underlying system architectures (both
hardware and software) and provide location transparency
⚫ Middleware is usually based on a particular model, for describing
distribution and communication (procedure call model, object model, event
based model)
⚫ Model automatically provides an abstraction for programmers to follow,
and provides direction for how to design and set up the distributed
applications
by Kumudha Raimond
Middleware Hides Heterogeneity
Applications
Middleware
Request reply protocol layers
Operating System
by Kumudha Raimond
Why Middleware?
Distributed computing environments are heterogeneous:
⚫ Networks
◦ ATM, Ethernet, etc. have different protocols
⚫ Computer hardware
◦ data types (integers) can be represented differently
⚫ Operating systems
◦ the API to IP differs from one OS to another
⚫ Programming languages
◦ e.g., different paradigms (functional, OO, etc.)
◦ e.g., data structures (arrays, records) can be represented
differently
⚫ Applications implemented by different developers
◦ Use different standards
by Kumudha Raimond
Middleware Characteristics
⚫ Location transparency
◦ client/server need not know their location (transparency provided by RPC,
RMI, Event based)
⚫ Sits on top of OS, independent of
◦ Communication protocols:
use abstract request-reply protocols over UDP, TCP
◦ Computer hardware:
use external data representation e.g. CORBA CDR
◦ Operating system:
The higher level abstractions provided by the middleware layer are
independent of the underlying OS
◦ Programming language:
e.g. CORBA supports Java, C++
CORBA:
⚫ provides remote object invocation between
◦ a client program written in one language and
by Kumudha Raimond
Introduction
Issue : Design of RPC with transparency property
A transparency mechanism : Local and remote procedures are
indistinguishable to programmers
This requires the following two types of transparencies:
Syntactic Transparency : RPC should have exactly the same syntax as a local
procedure call
Semantic Transparency : Semantics of a RPC are identical to those of a local
procedure call
Introduction
Definition :
The programmer write the same code whether the procedure is local or
remote.
Implementing RPC Mechanism
Requirement : To achieve semantic transparency and network transparency
Solution :
Based on the concept of stubs – which provide a perfectly local procedure call
abstraction by concealing from programs the interface to the underlying RPC
system
Based on RPCRuntime : An RPC communication package is used on both the
client and server sides to hide the details of underlying network
Implementation :
It involves the following 5 elements:
1.Client
2.Client stub
3.RPCRuntime
4.Server stub
5.Server
Implementing RPC Mechanism
Client Server
Execute
Return Call Call Return
RPCRuntime RPCRuntime
Wait
Receive Send Receive Send
Call Packet
Receive Packet
Implementing RPC Mechanism
Client
•It is a user process that initiates a RPC
•To make a RPC, it makes a perfect local call that invokes a corresponding
procedure in the client stub
Client Stub
Responsible for carrying out the following 2 tasks:
•On receipt of a call request from the client, it packs a specification of the
target procedure and the arguments into a message (Parameter Marshalling)
and then asks the local Runtime to send it to server stub
•On receipt of the result of procedure execution, it unpacks the result and
passes it to the client
Implementing RPC Mechanism
Client Stub
Instead of the code to provide the service, the client machine has a stub
procedure
In general,
•Puts the arguments in a message
•Sends the message to the server
•Waits for the reply message
•Unpacks the results
•Return to the application call
Implementing RPC Mechanism
Server
•On receiving a call request from the server stub, it executes the
procedure and returns to the stub
Steps of RPC
Steps of RPC
Step 7: add executes and returns answer to server stub
•Interface definition languages (IDLs) are designed to allow procedures implemented in different
languages to invoke one another. An IDL provides a notation for defining interfaces in which each of the
parameters of an operation may be described as for input or output in addition to having its type
specified.
Stub Generation
When writing a Distributed application :
• A programmer first writes an interface definition using IDL
Example
Identified by
#include <header.h>
unique ID
Specification of file_server, version 3.1 :
long read (in char name[Max_Path], out char buf[Buf_Size], in long bytes, in long position);
long write (in char name[Max_Path], out char buf[Buf_Size], in long bytes, in long position);
int create (in char [Max_Path], in int mode);
int delete (in char [Max_Path]);
The specification is an input to the stub generator, which produces both the client and server stub
Both are put into the appropriate libraries
When a client program calls any of the procedures defined by this spec, the corresponding client
stub procedure is linked into its binary
Stub Generation
Two ways to generate stubs:
•Manually : RPC implementer provides a set of translation functions from which a user can construct
his/her own stubs – simple
Used to define a service interface for Sun RPC by specifying a set of procedure definitions
Reply
client stub server stub
procedure procedure
client service
program Communication Communication procedure
module module dispatcher
Reply
client stub server stub
procedure procedure
client service
program Communication Communication procedure
module module dispatcher
Client :
Includes one stub procedure for each procedure in the service interface
Stub :
Similar to proxy – behaves –local procedure – marshals pid, arguments – unmarshals
RPC Client and Server
client process server process
Request
Reply
client stub server stub
procedure procedure
client service
program Communication Communication procedure
module module dispatcher
Dispatcher:
Selects one of stub procedure according to pid
Stub :
Similar to skeleton –unmarshals pid, arguments – marshals results
Case Study : DCE Only these 3 files are
manually written and
edited by an application
programmer
http://www.dcerpc.org/
RPC Messages
Two types of messages involved in the implementation of an RPC system:
• Call Message
• Reply Message
RPC protocol defines the format and interpretation of these messages
Independent of transport protocols
• Call: Sent by the client to the server for requesting execution of a particular
remote procedure
• Reply : Sent by the server to the client for returning the result of remote
procedure execution
RPC Messages
Call Message
Necessary basic components are :
• The identification information of the remote procedure to be executed
• The arguments necessary for the execution
• Sent by the server to the client for returning the result of remote procedure
execution
• Message Type : Call/Reply
Server Implementation
Servers may be of two types
• Stateful : It maintains clients’ state information from one RPC to the next
• Stateless : Does not maintain an y client state information.
Server Management
Stateful Server:
Client Server
Stateful server as it maintains the current state information for a file that has
been opened for use by a client
•Provide an easier programming paradigm – relieves the client from maintaining
state information
•More efficient
Server Management
Stateless Server:
Client Server
• In this case, the client has to keep track of the file state information
• Every request from a client must be accompanied with all the necessary
parameters to successfully carry out the desired operation
Server Management
Why Stateless Server ?
• Stateless servers have a distinct advantage over stateful servers in the event
of a failure
• In case of Failure in Stateful
• Stateful server may crash – lost the state information – client is unaware
– result in inconsistent results for the client
• Client crash – server will be holding invalid state information
• The system should be properly designed to detect the crashes
• In case of Failure in Stateless
• Client crash – has to retry a request until the server responds
Call by Reference
How are pointers or references passed ?
Generally, it is avoided since client and server exist in different address spaces
One solution : If the client stub knows that a parameters points to an array of
characters and also knows its size,
Client Stub : Copy the array into the message and send it to the server
Server Stub : Stub will call the server with a pointer to this array, even though
the pointer has a different numerical value than the original one
Server : Changes made by server will affect the buffer in server stub