1
Remote Procedure
Call (RPC) Concept
Chuan-Ming Liu
CSIE,NTUT
Spring ’04,TAIWAN
2
Introduction
Continues the discussion of middleware
(i.e.,tools and libraries programmers used
to construct client-server software)
Introduces the remote procedure call (RPC)
concept,and describes a particular
implementation of an RPC that uses XDR
standard for data representation
Shows how the approach simplifies the
design of client-server software and makes
the resulting program easier to understand
3
RPC Model
When programmers build a client-server
application,they must consider how the
entire system will function and how the two
components will interact
To help programmers design and understand
client-server interaction,researchers have
devised a conceptual framework (RPC model)
for building distributed programs
The RPC model uses familiar concepts from
conventional programs as the basis for the
design of distributed applications
4
Two Paradigms for Building
Distributed Programs
Two approaches when designing a
distributed applications
Communication-oriented Design
Application-oriented Design
5
Two Paradigms for Building
Distributed Programs (cont.)
Communication-oriented Design
Begin with the communication protocol
Design a message format and syntax
Design the client and server components by
specifying how each reacts to incoming
messages and how each generates outgoing
messages
6
Two Paradigms for Building
Distributed Programs (cont.)
Application-oriented Design
Begin with applications
Design a conventional application program to
solve the problem
Build and test a working version of the
conventional program that operates on a single
machine
Divide the program into two or more pieces,
and add communication protocols that allows
each piece to execute on a separate computer
7
Two Paradigms for Building
Distributed Programs (cont.)
Problems for communication-oriented design
By focusing on the communication protocol,the
programmer may miss important subtleties in the
application
Because few programmers have experience and
expertise with the protocol design,they often produce
awkward,incorrect,inefficient protocols
Because the programmer concentrates on
communication,it usually becomes the centerpiece of
the resulting programs,making them difficult to
understand or modify
8
Two Paradigms for Building
Distributed Programs (cont.)
The RPC model follows the application-
oriented design approach,which
emphasizes the problem to be solved
instead of the communication needed
The programmer can follow good design
principles that make the code modular and
maintainable
RPC separates the solution of a problem
from the task of making the solution
operate in a distributed environment
9
Two Paradigms for Building
Distributed Programs (cont.)
The RPC paradigm for programming
focuses on the application
It allows a programmer to concentrate on
devising a conventional program that
solves the problem before attempting to
divide the program into pieces that operate
on multiple computers
10
Conventional Procedure Calls
Fig,21.1 illustrates the procedure concept
Procedures offer a power abstraction that
allows programmers to divide programs
into small,manageable,easily-understood
pieces
12
Extension of Procedural Model
Fig,21.2 shows how the program from Fig,
21.1 can be extended to use an RPC to
become a distributed program
Before a program can use RPCs,it must be
augmented with protocol software that
allows it to communicate with remote
procedures
14
Execution of Conventional
Procedure Call and Returns
Fig,21.3 shows a conceptual model of
execution that explains flow of control
during procedure call and return
A single thread of control (execution)
begins in the main program,passes through
procedure A and B,and eventually returns
to the main program
16
Procedure Model in
Distributed Systems
Fig,21.4 illustrates the model of execution
used with RPCs
A request sent from a client to a server
corresponds to a call of a remote procedure,
and a response sent from a server back to a
client corresponds to the execution of a
return instruction
18
Analogy Between Client-
Server and RPC
RPC transfers control to the called
procedure like a conventional procedure
call
The system suspends execution of the
calling procedure during the call and only
allows the called procedure to execute
As Fig,21.4 illustrates,nested RPCs
corresponds to a server that becomes a
client of another service.
19
Analogy Between Client-
Server and RPC (Cont.)
Conventional procedure remains completely
inactive until it is called; however,a server
process must exists in the remote system
Conventional procedures usually accept a
few arguments and return a few results
However,a server can accept or return
arbitrary amount of data (.i.e,,It can accept
or return an arbitrary stream over a TCP
connection).
20
Practical Constraints on RPC
Network delays can make an RPC several
orders of magnitude more expensive than a
conventional procedure call
An RPC cannot have pointers as arguments
because the remote procedure operates in a
completely different address space than the
caller
Because a remote procedure does not share
the caller’s environment,it does not have
direct access to the caller’s I/O descriptors
or OS functions
21
Distributed Computation
As a Program
Thinking of a distributed computation as a
single program in which control passes
across the network to a remote procedure
and back helps programmers specify client-
server interaction
It relates the interaction of distributed
computations to the familiar notions of
procedure call and return
22
Sun Microsystem’s RPC
Definition
Sun has defined a special form of RPC,
Sun RPC,Open Network Computing
(ONC) RPC,or simply RPC
Applications include the NFS.
ONC RPC defines the formats about
messages that the caller (client) sends to
invoke a remote procedure,
arguments,and
results that the called procedure returns
23
Sun Microsystem’s RPC
Definition (cont.)
It permits the calling program to use
either UDP or TCP to carry messages and
uses XDR to represent procedure
arguments as well as other items in an
RPC message header
In addition to the protocol specification,
ONC RPC includes a complier system
that helps programmers build distributed
programs automatically
24
Remote Programs,Procedures
ONC RPC extends the RPC model by
defining a remote execution environment
It defines a remote program as the basic
unit of software that executes on a remote
machine
As Fig,21.5 illustrates,all remote
procedures inside the remote program can
share access to the single database
25
Remote Programs,Procedures
As an example,one can implement a single
remote database by constructing a single
remote program that includes data
structures to hold shared information and
three remote procedures to manipulate it,
insert,delete,and lookup
27
Reducing the Number of
Arguments
Using a structure instead of multiple
arguments makes the program more
readable because the structure field names
serve as keywords that tell the readers how
each argument will be used
If all programs using RPC collect their
arguments into a structure,each remote
procedure will need only a single argument
28
Identifying Remote
Programs and Procedures
A specific remote procedure on a given
remote program can be identified by a pair,
(prog,proc)
prog,identifies the remote program,which is
a unique 32-bit integer
proc,identifies a remote procedure within the
remote program,which is an integer between 1
to N; 0 is reserved for an echo procedure for
testing reachability
29
Identifying Remote Programs
and Procedures (cont.)
To avoid conflicting,RPC has divided the
set of programs into 8 groups as Fig,21.6
shows
Of the 229 program numbers available in
the first group,Sun has only assigned a
handful of numbers as shown in Fig,21.7
(some of the assignments)
32
Accommodating Multiple
Versions of a Remote Program
ONC RPC includes an integer version
number for each remote program
(prog,vers,proc)
vers specifies the version of the program to
which the message has been sent
It is possible to
migrate from one version of a remote
procedure to another gracefully
test a new version of the server while an old
version continues to operate
33
Mutual Exclusion for Procedures
in a Remote Program
RPC provides automatic mutual exclusion
among procedures within a given remote
program by permitting at most one remote
procedure (e.g.,either insert or delete) to
execute at a given time
34
Communication Semantics
When choosing the semantics for ONC
RPC,the designers have to choose between
two possibilities:
To make a remote procedure call behave as
much like a local procedure,RPC should use
a reliable transport like TCP and should
guarantee reliability to the programmer
To allow programmers to use efficient,
connectionless transport protocols,the RPC
should support communication through a
datagram protocol like UDP
35
Communication Semantics
(cont.)
ONC RPC allows each application to
choose TCP or UDP as a transport protocol
It does not enforce reliable semantics
36
At Least Once Semantics
The ONC RPC standard uses the at least
once semantics to describe RPC execution
when the caller receives a reply
It uses zero or more semantics to describe
the behavior of a remote procedure call
when the caller does not receive a reply
Programmers who choose to use UDP as
the transport protocol for an ONC
application must build the application to
tolerate zero-or-more execution semantics
37
At Least Once Semantics (cont.)
Zero-or-more semantics usually means
that a programmer makes each RPC
idempotent (An operation is said to be
idempotent if repeated applications of the
operation produce the same result)
As an example,a remote procedure that
appends data to a file is not idempotent,
however,a remote procedure that write
data to a specified position in a file is
idempotent
38
RPC Retransmission
The library software supplied with the
ONC RPC implementation includes a fixed
(nonadaptive) timeout and retransmission
strategy
Programmers can adjust the timeout and
retry limits for a given application
An application cannot interpret failure as a
guarantee that remote procedure was never
executed (in fact,it may have executed
several times)
39
Mapping a Remote Program
to a Protocol Port
UDP and TCP transport protocols use 16-
bit protocol numbers to identify
communication endpoints
To make it possible for clients and servers
to rendezvous,we assume that each service
is assigned a unique protocol port number
and that the assignments are well-known
ONC RPC introduces an interesting
problem,because it uses 32-bit numbers to
identify remote programs,RPC programs
can outnumber protocol ports
40
Mapping a Remote Program
to a Protocol Port (cont.)
If an RPC program does not use a reserved,
well-known protocol port,clients cannot
contact it directly
Because the RPC program (server) only
obtains a protocol port after it begins
execution,the client cannot know which
protocol port the server obtained
41
Dynamic Port Mapping
To allow clients to contact remote
programs,the ONC RPC mechanism
includes a dynamic mapping service
Fig,21.8 illustrates that the ONC PRC port
mapper operates as a separate server
process
42
Dynamic Port Mapping
(cont.)
Each RPC program registers its program
number,protocol port number,and version
number with the port mapper on the local
machine
A caller contacts the port mapper on a
machine to find the protocol port to use for
a given RPC program on that machine
44
RPC Port Mapper Algorithm
Algorithm 21.1 shows the ONC RPC port
mapper algorithm
The port mapper allows clients to reach
remote programs even though the remote
programs dynamically allocate protocol ports
Registration requests,The remote program
contacts the port mapper on its local machine
and adds a triple of integers to the database,
(RPC prog no.,protocol port no.,version no.)
45
RPC Port Mapper Algorithm
Look-up requests,Callers on other
machines (by knowing the address of the
machine on which the remote program
executes) specify a remote program
number and version number,and request
the protocol port number that can be used
to reach the remote program
Caller can always reach the port mapper
because the port mapper communicates
using the well-known protocol port,111
47
ONC RPC Message Format
A message type field in the RPC message
header distinguishes between messages that
a client uses to initiate an RPC and
messages that an RPC uses to reply
Constants used in the message type field
can be defined using XDR language,for
example,the declaration,as shown in Fig,
21.8a.
As an example,once values have been
declared for symbolic constants,the XDR
language can define the format of an RPC
message,as shown in Fig,21.8b
50
ONC RPC Message Format
(cont.)
The declarations for call_body and
rply_body must be given elsewhere
For example,RPC defines a call_body to
have the form,as shown in Fig,21.8c
52
Marshaling Arguments for a
Remote Procedure
RPC must represent all arguments in an
external form that allows them to be
transferred between computers
If any of the arguments passed to the
remote procedure consists of a complex
data structure like linked list,it must be
encoded into a compact representation that
can be sent across the network
The terms marshal,linearize,or serialize
to denote the tasking of encoding
arguments
53
Marshaling Arguments for a
Remote Procedure (cont.)
The client side of RPC marshals arguments
into the message and the server side
unmarshals them
Marshaling and unmarshaling large data
structures can require significant CPU time
and network bandwidth
Thus,most programmers avoid passing
linked structure as arguments
54
Authentication
RPC defines several possible forms of
authentication,including a simple scheme
that relies on functions available in the OS
and a more complex scheme that uses the
DES (Data Encryption Standard)
Authentication information can have one
of the 4 types shown in Fig,21.8d
56
Authentication (cont.)
The declaration of the authentication
structure in an RPC message uses the
keyword opaque to indicate that it
appears in the message without any
interpretation,as shown in Fig,21.8e
UNIX authentication defines the
structure of the authentication
information to contain several fields,as
shown in Fig,21.8f
59
An Example of RPC Message
Representation
Fig,21.9 illustrates an RPC CALL message
The size of each field is determined by its
RPC definition and the XDR specification
of sizes
61
An Example of the UNIX
Authentication Field
The size of the authentication field in an
RPC message depends on its contents
Fig,21.10 illustrates the representation for
a UNIX authentication field
63
Summary
Using the RPC model helps programmers
focus on the application instead of the
communication protocol
ONC RPC specifies a scheme for
identifying remote procedures as well as a
standard for the format of RPC messages
XDR is used to keep message
representations machine independent
64
Summary (cont.)
ONC RPC programs do not use well-known
protocol ports like conventional clients and
servers
They use a dynamic binding mechanism that
allows each RPC program to choose an
arbitrary,unused protocol port when it begins
Called RPC port mapper,the binding
mechanism requires each computer that
offers RPC programs registers with the port
mapper on its local machine after it obtains a
protocol port
65
Summary (cont.)
When an RPC client wants to contact an
RPC program,it first contacts the port
mapper on the target machine
The port mapper responds by telling the
client which port the target RPC program is
using
The client contacts the RPC program
directly using that port