43
RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY

RPC Remote Procedure Call

  • Upload
    emma

  • View
    40

  • Download
    0

Embed Size (px)

DESCRIPTION

RPC Remote Procedure Call. Dave Hollinger Rensselaer Polytechnic Institute Troy, NY. Distributed Program Design. Typical Sockets Approach. Communication-Oriented Design Design protocol first. Build programs that adhere to the protocol. Application-Oriented Design - PowerPoint PPT Presentation

Citation preview

Page 1: RPC Remote Procedure  Call

RPCRemote Procedure Call

Dave HollingerRensselaer Polytechnic InstituteTroy, NY

Page 2: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview2

Distributed Program Design

Communication-Oriented Design• Design protocol first. • Build programs that adhere to the protocol.

Application-Oriented Design• Build application(s).• Divide programs up and add communication

protocols.

Typical

Sockets

Approach

RPC

Page 3: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview3

RPCRemote Procedure Call

Call a procedure (subroutine) that is running on another machine.

Issues:• identifying and accessing the remote procedure• parameters• return value

Page 4: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview4

blah, blah, blah

bar = foo(a,b);

blah, blah, blah

int foo(int x, int y ) { if (x>100)

return(y-2); else if (x>10)

return(y-x); else

return(x+y);}

ClientServer

protocol

Remote Subroutine

Page 5: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview5

Sun RPC

There are a number of popular RPC specifications. Sun RPC (ONC RPC) is widely used. NFS (Network File System) is RPC based. Rich set of support tools.

Page 6: RPC Remote Procedure  Call

Y Kermarrec

Classic Procedure Call

Call Stack Parameter Passing Error and exception Semantics

Page 7: RPC Remote Procedure  Call

Y Kermarrec

Implementing RPC

Seems to be complex as we need to go through the network

The trick:• Create stub functions to make it appear to the user that the call is local•Stub function contains the function’s interface

Page 8: RPC Remote Procedure  Call

Y Kermarrec

client server

Stub functions

network routines

server functions

server stub(skeleton)

network routines

1. Client calls stub (params on stack)

client functions

client stub

Page 9: RPC Remote Procedure  Call

Y Kermarrec

client server

Stub functions

server functions

server stub(skeleton)

network routines

2. Stub marshals params to net message

client functions

client stub

network routines

Page 10: RPC Remote Procedure  Call

Y Kermarrec

client server

Stub functions3. Network message sent to server

client functions

client stub

network routines

server functions

server stub(skeleton)

network routines

Page 11: RPC Remote Procedure  Call

Y Kermarrec

client server

Stub functions4. Receive message: send to stub

client functions

client stub

network routines

server functions

server stub(skeleton)

network routines

Page 12: RPC Remote Procedure  Call

Y Kermarrec

client server

Stub functions5. Unmarshal parameters, call server func

client functions

client stub

network routines

server functions

server stub(skeleton)

network routines

Page 13: RPC Remote Procedure  Call

Y Kermarrec

client server

Stub functions6. Return from server function

client functions

client stub

network routines

server functions

server stub(skeleton)

network routines

Page 14: RPC Remote Procedure  Call

Y Kermarrec

client server

Stub functions7. Marshal return value and send message

client functions

client stub

network routines

server functions

server stub(skeleton)

network routines

Page 15: RPC Remote Procedure  Call

Y Kermarrec

client server

Stub functions8. Transfer message over network

client functions

client stub

network routines

server functions

server stub(skeleton)

network routines

Page 16: RPC Remote Procedure  Call

Y Kermarrec

client server

Stub functions9. Receive message: direct to stub

client functions

client stub

network routines

server functions

server stub(skeleton)

network routines

Page 17: RPC Remote Procedure  Call

Y Kermarrec

client server

Stub functions10. Unmarshal return, return to client code

client functions

client stub

network routines

server functions

server stub(skeleton)

network routines

Page 18: RPC Remote Procedure  Call

Y Kermarrec

RPCL : an example

program MESSAGE_PROG {version MESSAGE_VERS {

int PRINT_MESSAGE (string) = 1 ;

} = 1 ;

} = 0x 2000 0001 ;

Page 19: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview19

Procedure Arguments

To reduce the complexity of the interface specification, Sun RPC includes support for a single argument to a remote procedure.*

Typically the single argument is a structure that contains a number of values (the parameters).

* Newer versions can handle multiple args.

Page 20: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview20

Procedure Identification

Each procedure is identified by:• Hostname (IP Address)• Program identifier (32 bit integer)• Procedure identifier (32 bit integer)

– Program Version identifier» for testing and migration » Used also to detect out dated version of a server

Page 21: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview21

Procedure Identifiers &Program Version Numbers

Procedure Identifiers usually start at 1 and are numbered sequentially

Version Numbers typically start at 1 and are numbered sequentially.

Service number is coded on 32 bits• Possible user value range : 0x 2000 0000 à 0x 3fff

ffff

Page 22: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview22

Iterative Server

Sun RPC specifies that at most one remote procedure within a program can be invoked at any given time.

If a 2nd procedure is called, the call blocks until the 1st procedure has completed.

Page 23: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview23

Call Semantics

What does it mean to call a local procedure?• the procedure is run exactly one time.

What does it mean to call a remote procedure?• It might not mean "run exactly once"!

Page 24: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview24

Remote Call Semantics

To act like a local procedure (exactly one invocation per call) - a reliable transport (TCP) is necessary.

Sun RPC does not support reliable call semantics.

"At Least Once" Semantics "Zero or More" Semantics

Page 25: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview25

Sun RPC Call Semantics

At Least Once Semantics• if we get a response (a return value)

Zero or More Semantics• if we don't hear back from the remote subroutine.

Page 26: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview26

Remote Procedure deposit()

deposit(DavesAccount,$100)

Always remember that you don't know how many times the remote procedure was run!• The net can duplicate the request (UDP).

Page 27: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview27

Network Communication

The actual network communication is nothing new - it's just TCP/IP.

Many RPC implementations are built upon the sockets library.• the RPC library does all the work!

The programmer may select UDP or TCP based on his/her requirements

Page 28: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview28

Dynamic Port Mapping

How to determine where the server is waiting requests ?

Servers typically do not use well known protocol ports

Clients know the Program ID (and host IP address).

RPC includes support for looking up the port number of a remote program.

Page 29: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview29

The portmapper

Each system which will support RPC servers runs a port mapper server that provides a central registry for RPC services.

Servers tell the port mapper what services they offer.

Page 30: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview30

More on the portmapper

Clients ask a remote port mapper for the port number corresponding to Remote Program ID.

The portmapper is itself an RPC server!

The portmapper is available on a well-known port (111).

Page 31: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview31

RPCGEN

There is a tool for automating the creation of RPC clients and servers.

The program rpcgen does most of the work for you.

The input to rpcgen is a protocol definition in the form of a list of remote procedures and parameter types.

Page 32: RPC Remote Procedure  Call

Y Kermarrec

Protocol Definition: simp.x

struct operands { int x; int y;};program SIMP_PROG { version SIMP_VERSION { int ADD(operands) = 1; int SUB(operands) = 2; } = VERSION_NUMBER;} = 555555555;

RPC Programming32

Page 33: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview33

RPCGEN

Input File

rpcgen

Client Stubs XDR filters header file Server skeleton

C Source Code

ProtocolDescription

Page 34: RPC Remote Procedure  Call

Y Kermarrec Netprog: RPC Overview34

rpcgen Output Files

> rpcgen –C foo.x

foo_clnt.c (client stubs)foo_svc.c (server main)foo_xdr.c (xdr filters)foo.h (shared header file)

Page 35: RPC Remote Procedure  Call

Y Kermarrec

RPC compiler in action

IDL RPCcompiler

client code (main)

server functions

client stub

headers

server skeleton

data conv.

data conv. compiler

compiler server

client

Code you write

Code RPC compiler generates

Page 36: RPC Remote Procedure  Call

Y Kermarrec

XDR

Powerful paradigm for creation and transfer of complex data structures

XDR provides a service associated with the OSI Presentation Layer.• Common data representation• Library

- not part of the O.S.• Easy to port to new architectures• Independence from transport layer

XDR36

Page 37: RPC Remote Procedure  Call

Y Kermarrec

Data Conversion

Asymmetric Data Conversion• client always converts to the server’s data

representation.

Symmetric Data Conversion• both client and server convert to/from some

standard representation.

XDR is Symmetric Data Conversion

XDR37

Page 38: RPC Remote Procedure  Call

Y Kermarrec

Implicit vs. Explicit Typing

Explicit typing• each piece of data includes information about the

type

Implicit typing• the sender and receiver must agree on the order

and type of all data

XDR uses Implicit Typing

XDR38

Page 39: RPC Remote Procedure  Call

Y Kermarrec

XDR Data Types

boolean char short int long float double

XDR39

enumeration structure string fixed length array (1-D) variable length array (1-D) union opaque data

Page 40: RPC Remote Procedure  Call

Y Kermarrec

XDR Programming

XDR libraries are based on a stream paradigm The process of converting local data to XDR also puts

the data in the XDR stream When extracting an item from a stream, conversion is

done to the local representation Streams can be attached to a file, pipe, socket or

memory• Individual data items are added to (removed from) the

stream one at a time

XDR40

Page 41: RPC Remote Procedure  Call

Y Kermarrec

Conversion Terminology

Converting from local representation to XDR representation is called Encoding.

Converting from XDR representation to local representation is called Decoding.

XDR41

Sender ReceiverXDRENCODE DECODE

Page 42: RPC Remote Procedure  Call

Y Kermarrec

Information for the labs

You are going to experiment :• how to go from a classic procedure call to an RPC• How to run a server and activate clients calls• What is the magic (the work of rpcgen) behind the

scene in terms of socket management, connections, errors and fault detection.

• Get the initial insights for all the other paradigms (distributed object, Java RMI, web services…) work and are handled

Page 43: RPC Remote Procedure  Call

Y Kermarrec

Survey

RPC is a powerful way to program distributed system quite easily

It was initialy an OS feature that has been moved to the programmer’s world

Numerous benefits in terms of transparencies and above all fault tolerance