(a) parameter passing in a local procedure call: the stack before the call (b) the stack while the...

31
Remote Procedure Prepared by :Sai Keerthana Bhimanadhuni Instructor: Dr. Yanqing Zhang Georgia State University

Upload: tabitha-shelton

Post on 03-Jan-2016

231 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Remote Procedure Call

Prepared by :Sai Keerthana Bhimanadhuni

Instructor: Dr. Yanqing Zhang

Georgia State University

Page 2: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Contents

• Introduction•Models Of Communication• Remote Procedure Call• Basic RPC Operation• Types of Passing Parameters• Client and Server stubs

Page 3: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Contents

•Marshalling• RPC Issues•Asynchronous RPC• Practical RPC Systems•Writing a Client and Server- DCE• RPC Binding

Page 4: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Introduction

Distributed Systems:A distributed system is a software system in which components located on networked computers communicate and coordinate their actions by passing messages.

Inter process communication is at the heart of all distributed systems.

It makes no sense to study distributed systems without carefully examining the ways that processes on different machines can exchange information.

Page 5: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Models of Communication

Three widely-used models for communication:• Remote Procedure Call (RPC)

• Message-Oriented Middleware (MOM)

• Data streaming.

Our first model for communication in distributed systems is the remote procedure call (RPC). An RPC aims at hiding most of the intricacies of message passing.

It is ideal for client-server applications.

It is the most common framework for newer protocols and for middleware.

Page 6: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Remote Procedure Call (RPC)

Remote Procedure Call (RPC) is a protocol that one program can use to request a service from a program located in another computer in a network without having to understand network details.

• When a process on machine A calls' a procedure on machine B, the calling process on A is suspended, and execution of the called procedure takes place on B.

• Information can be transported from the caller to the callee in the parameters and can come back in the procedure result.

• No message passing or I/O at all is visible to the programmer.

Page 7: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Remote Procedure Call (RPC)• A remote procedure call makes a call to a remote service look like a

local call• RPC makes transparent whether server is local or remote• RPC allows applications to become distributed transparently• RPC makes architecture of remote machine transparent.

No message passing at all is visible to the programmer

Page 8: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Remote Procedure Call (RPC)• Fundamental idea: – • Server process exports an interface of procedures or functions

that can be called by client programs• similar to library API, class definitions, etc.

• Clients make local procedure/function calls • As if directly linked with the server process• Under the covers, procedure/function call is converted into a

message exchange with remote server process

Page 9: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Basic RPC Operation• Conventional Procedure Call

• How are parameters passed in a local procedure call• E.g., #include <sys/types.h>

#include <unistd.h> ... char buf[20]; size_t nbytes; ssize_t bytes_read; int fd; ... nbytes = sizeof(buf); bytes_read = read(fd, buf, nbytes); ...

Page 10: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Ordinary procedure/ Function call

(a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active.

count = read(fd, buf, nbytes)

Page 11: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

count =read(fd, buf, nbytes);

where fd is an integer indicating a file,

buf is an array of characters into which data are read,

nbytes is another integer telling how many bytes to read.

• If the call is made from the main program, the stack will be as shown in Fig(a) before the call. • To make the call, the caller pushes the parameters onto the stack

in order, last one first, as shown in Fig(b).

Page 12: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Types of Passing parametersCall-by-value A value parameter, such as fd or nbytes, is simply copied to the stack as shown in Fig(b). To the called procedure, a value parameters just an initialized local variable. The called procedure may modify it , but such changes do not affect the original value at the calling side.

Call-by-referenceA reference parameter in C is a pointer to a variable (i.e., the address of the variable), rather than the value of the variable. In the call to read. the second parameter is a reference parameter because arrays are always passed by reference in C. What is actually pushed onto the stack is the address of the character array. If the called procedure uses this parameter to store something into the character array, it does modify the array in the calling procedure.

• .

Page 13: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Types of Passing parameters

Call-by-copy It consists of having the variable copied to the stack by the caller, as in call-by-value, and then copied back after the call, overwriting the caller's original value. Under most conditions, this achieves exactly the same effect as call-by-reference, but in some situations such as the same parameter being present multiple times in the parameter list, the semantics are different. The call-by-copy/restore mechanism is not used in many languages.

The decision of which parameter passing mechanism to use is normally made by the language designers and is a fixed property of the language. Sometimes it depends on the data type being passed.

Page 14: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Client and Server Stubs

Principle of RPC between a client and server program.

Page 15: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Steps of a Remote Procedure Call1. Client procedure calls client stub in normal way

2. Client stub builds message, calls local OS

3. Client's OS sends message to remote OS

4. Remote OS gives message to server stub

5. Server stub unpacks parameters, calls server

6. Server does work, returns result to the stub

7. Server stub packs it in message, calls local OS

8. Server's OS sends message to client's OS

9. Client's OS gives message to client stub

10. Stub unpacks result, returns to client

Page 16: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

RPC: The basic mechanism

Page 17: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

RPC Stubs • Client-side stub• Looks like local server function• Same interface as local function• Bundles arguments into a message, sends to server-side stub• Waits for reply, un-bundles/un-marshals results• Returns

• Server-side stub• Looks like local client function to server• Listens on a socket for message from client stub• Un-bundles/un-marshals arguments to local variables• Makes a local function call to server• Bundles result into reply message to client stub

Page 18: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

MarshallingValues must cross the network

Machine formats differ• Integer byte order• Little-endian or big-endian

• Floating point format• IEEE 754 or not

• Marshalling transferring data structure used in remote procedure call from one address space to another.

Page 19: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

RPC – Issues• How to make the “remote” part of RPC invisible to the programmer?

• What are semantics of parameter passing?• E.g., pass by reference?

• How to bind (locate & connect) to servers?

• How to handle heterogeneity?• OS, language, architecture, …

• How to make it go fast?

Page 20: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Issue #1 — representation of dataEach machine often has its own representation for numbers,characters, and other data items. Some machines, such as the Intel Pentium, number their bytes from right to left, whereas others, such as the Sun SPARC,number them the other way.

The Intel format is called little endian and theSPARC format is called big endian,

Page 21: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Passing Value Parameters

a) Original message on the Pentium (little-endian)b) The message after receipt on the SPARC (big-endian)c) The message after being inverted (integer 5, string: “LLIJ”)Note: the little numbers in boxes indicate the address of each byte

Page 22: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Issue #2 — Pointers and Referencesread(int fd, char* buf, int nbytes)

• Pointers are only valid within one address space

• Cannot be interpreted by another process• Even on same machine!

• Pointers and references are ubiquitous in C, C++• Even in Java implementations!

Page 23: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Transport of Remote Procedure Call• Option — TCP

• Connection-based, reliable transmission• Useful but heavyweight, less efficient• Necessary if repeating a call produces different result

• Alternative — UDP• If message fails to arrive within a reasonable time, caller’s

stub simply sends it again• Okay if repeating a call produces same result

Page 24: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Asynchronous RPC

Analogous to spawning a threadCaller must eventually wait for result

Analogous to join

The interconnection between client and server in a traditional RPC

Page 25: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Asynchronous RPC (continued)

Analogous to spawning a threadCaller must eventually wait for result

Analogous to joinOr be interrupted (software interrupt)

Page 26: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Practical RPC Systems• DCE (Distributed Computing Environment)

• Open Software Foundation• Basis for Microsoft DCOM• Tanenbaum & Van Steen, §4.2.4

• Sun’s ONC (Open Network Computing)• Very similar to DCE• Widely used• rpcgen• http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATI

ON/HTML/AA-Q0R5B-TET1_html/TITLE.html

Page 27: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Practical RPC Systems (continued)

• Java RMI (Remote Method Invocation)• java.rmi standard package• Java-oriented approach — objects and methods

• CORBA (Common Object Request Broker Architecture) • Standard, multi-language, multi-platform middleware• Object-oriented• Heavyweight

• …

Page 28: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Writing a Client and a Server

The steps in writing a client and a server in DCE RPCDCE: Distributed Computing Environment

Page 29: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

RPC Binding• Binding is the process of connecting the client to the server• the server, when it starts up, exports its interface• identifies itself to a network name server• tells RPC runtime that it is alive and ready to accept calls

• the client, before issuing any calls, imports the server• RPC runtime uses the name server to find the location of the server and

establish a connection

• Registration of a server makes it possible for a client to locate the server and bind to it.

• Server location is done in two steps:1.Locate the server’s machine.2.Locate the server on that machine.

Page 30: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

References

• :Distributed Systems: Principles and Paradigms, Andrew S. Tanenbaum and Maarten Van Steen, 2006. (Second Edition)

Page 31: (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the called procedure is active. count =

Thank You