(a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the...
-
Upload
tabitha-shelton -
Category
Documents
-
view
231 -
download
0
Transcript of (a) Parameter passing in a local procedure call: the stack before the call (b) The stack while the...
Remote Procedure Call
Prepared by :Sai Keerthana Bhimanadhuni
Instructor: Dr. Yanqing Zhang
Georgia State University
Contents
• Introduction•Models Of Communication• Remote Procedure Call• Basic RPC Operation• Types of Passing Parameters• Client and Server stubs
Contents
•Marshalling• RPC Issues•Asynchronous RPC• Practical RPC Systems•Writing a Client and Server- DCE• RPC Binding
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.
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.
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.
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
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
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); ...
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)
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).
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.
• .
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.
Client and Server Stubs
Principle of RPC between a client and server program.
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
RPC: The basic mechanism
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
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.
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?
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,
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
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!
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
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
Asynchronous RPC (continued)
Analogous to spawning a threadCaller must eventually wait for result
Analogous to joinOr be interrupted (software interrupt)
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
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
• …
Writing a Client and a Server
The steps in writing a client and a server in DCE RPCDCE: Distributed Computing Environment
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.
References
• :Distributed Systems: Principles and Paradigms, Andrew S. Tanenbaum and Maarten Van Steen, 2006. (Second Edition)
Thank You