remote procedure callssetia/cs707-s00/slides/rpc.pdfinstructor’s guide for coulouris, dollimore...
TRANSCRIPT
![Page 1: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/1.jpg)
Remote Procedure Calls
CS 707
![Page 2: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/2.jpg)
CS 707 2
Motivation
• Send and Recv calls ⇔ I/O
• Goal: make distributed nature of systemtransparent to the programmer
• RPC provides procedural interface todistributed services
![Page 3: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/3.jpg)
Instructor’s Guide for
Coulouris, Dollimore and Kindberg
Distributed Systems: Concepts and Design
Edn. 2 (2nd impression)
Addison-Wesley Publishers 1994 46
Figure 4.5 Request-reply communication.
Request
ServerClient
DoOperation
(wait)
(continuation)•
Replymessage
GetRequest
SendReply
executerequest
message••
•
![Page 4: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/4.jpg)
Instructor’s Guide for
Coulouris, Dollimore and Kindberg
Distributed Systems: Concepts and Design
Edn. 2 (2nd impression)
Addison-Wesley Publishers 1994 55
Figure 5.2 Stub procedures.
Localcall
Localreturn
Marshalarguments
Unmarshalresults
SendRequest
ReceiveReply
ReceiveRequest
SendReply
Unmarshalarguments
Marshalresults
Executeprocedure
Return
Selectprocedure
Client computer Server computer
Client Client stubprocedure
Communicationmodule
Communi-cationmodule
DespatcherServer stub
Serviceprocedure
Client process Server process
![Page 5: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/5.jpg)
CS 707 3
Issues in RPC
• Parameter Passing– marshalling
– big endian vs little endian
0 0 0 5
J I L L
5 0 0 0
L L I J
Intel 386 Sparc
0 1 2 3 3 2 1 0
4 5 6 7 7 6 5 4
![Page 6: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/6.jpg)
CS 707 4
Parameter Passing
• Passing arrays– in C by reference
• Canonical forms– SUN XDR, Xerox Courier
• Passing pointers?
![Page 7: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/7.jpg)
Instructor’s Guide for
Coulouris, Dollimore and Kindberg
Distributed Systems: Concepts and Design
Edn. 2 (2nd impression)
Addison-Wesley Publishers 1994 42
4
Figure 4.1 XDR message.
5 length of sequence
" S m i t " ‘Smith’
" h _ _ _ "
6 length of sequence
" L o n d " ‘London’
" o n _ _ "
1 9 3 4 CARDINAL
4 bytes
The message is: ‘Smith’, ‘London’, 1934
![Page 8: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/8.jpg)
Instructor’s Guide for
Coulouris, Dollimore and Kindberg
Distributed Systems: Concepts and Design
Edn. 2 (2nd impression)
Addison-Wesley Publishers 1994 47
Figure 4.6 Request-reply message structure.
messageType (Request, Reply)
requestId CARDINAL
procedureId CARDINAL
arguments (* flattened list*)
![Page 9: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/9.jpg)
Instructor’s Guide for
Coulouris, Dollimore and Kindberg
Distributed Systems: Concepts and Design
Edn. 2 (2nd impression)
Addison-Wesley Publishers 1994 48
Figure 4.7 RPC protocols.
Name Messages sent by
Client Server Client
R Request
RR Request Reply
RRA Request Reply Acknowledge reply
![Page 10: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/10.jpg)
CS 707 5
Handling Failures
• Types of failure– client unable to locate server
– request message lost
– reply message lost
– server crashes after receiving a request
– client crashes after sending a request
![Page 11: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/11.jpg)
CS 707 6
Handling failures
• Client cannot locate server– Reasons
• server crashed
• client compiled using old version of server interface
– RPC system must be able to report error toclient
– loss of transparency
![Page 12: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/12.jpg)
CS 707 7
Handling failures
• Lost request message– retransmit a fixed number of times
• Lost reply message– client retransmits request
– server choices• filter duplicates ⇒ hold on to results until ACK
• re-execute procedure ⇒ service should beidempotent so that it can be safely repeated
![Page 13: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/13.jpg)
CS 707 8
Handling failures
• Server crashes
Recvexecreply
REQ
REP
Recvexeccrash
REQ
NOREP
Recvcrash
REQ
NOREP
Client cannot tell difference
![Page 14: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/14.jpg)
CS 707 9
Handling failures
• Server crashes– at least once (keep trying till server comes up)
– at most once (return immediately)
– exactly once impossible to achieve
• ONC RPC (Sun) uses at least oncesemantics if a RPC is successful and “zeroor more” semantics if call fails
![Page 15: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/15.jpg)
Instructor’s Guide for
Coulouris, Dollimore and Kindberg
Distributed Systems: Concepts and Design
Edn. 2 (2nd impression)
Addison-Wesley Publishers 1994 54
Delivery guarantees RPC call semantics
Retry request message
Duplicatefiltering
Re-execute procedure or retransmit reply
No Not applicable Not applicable Maybe
Yes No Re-execute procedure At-least-once
Yes Yes Retransmit reply At-most-once
![Page 16: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/16.jpg)
CS 707 10
Handling failures• Client crashes
– if a client crashes before RPC returns, we havean “orphan” computation at server
– wastes resources, could also start other remotecomputations
– orphan detection• reincarnation (client broadcasts new “epoch” when
it comes up)
• expiration (RPC has fixed amount of time T to dowork)
![Page 17: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/17.jpg)
CS 707 11
Binding
• Dynamic– Servers
• register service with binder
• withdraw
– Client• lookup address of service
– SUN RPC portmapper runs on every host
![Page 18: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/18.jpg)
Instructor’s Guide for
Coulouris, Dollimore and Kindberg
Distributed Systems: Concepts and Design
Edn. 2 (2nd impression)
Addison-Wesley Publishers 1994 56
Figure 5.3 Binder Interface.
PROCEDURE Register (serviceName:String; serverPort:Port; version:integer)causes the binder to record the service name and server port of a service in its table, together with a version number.
PROCEDURE Withdraw (serviceName:String; serverPort:Port; version:integer)causes the binder to remove the service from its table.
PROCEDURE LookUp (serviceName:String; version:integer): Port the binder looks up the named service and returns its address(or set of addresses) if the version number agrees with the one stored in its table.
![Page 19: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/19.jpg)
CS 707 12
RPC protocols
• Connection-oriented or connection-less– connectionless has better performance on LANs
• UDP/IP or roll your own protocol– specialized protocol better but more effort
• large RPCs have to be broken up intomultiple packets
![Page 20: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/20.jpg)
CS 707 13
Interface definition languages
• SUN XDR
• rpcgen (IDL compiler)– creates client and server stub procedures,
header files, despatcher, server main procedure
– stubs use XDR for marshalling andunmarshalling
![Page 21: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/21.jpg)
Instructor’s Guide for
Coulouris, Dollimore and Kindberg
Distributed Systems: Concepts and Design
Edn. 2 (2nd impression)
Addison-Wesley Publishers 1994 53
5
Figure 5.1 Levels in the client software.
Client program
User package
Client stub proceduresRPC interface
User package interface
Communication handler
![Page 22: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/22.jpg)
Instructor’s Guide for
Coulouris, Dollimore and Kindberg
Distributed Systems: Concepts and Design
Edn. 2 (2nd impression)
Addison-Wesley Publishers 1994 57
Figure 5.4 Files interface in Sun XDR.
/* FileReadWrite service interface definition in file FileReadWrite.x*/const MAX = 1000;typedef int FileIdentifier;typedef int FilePointer;typedef int Length;struct Data {
int length;char buffer[MAX];
};struct writeargs {
FileIdentifier f;FilePointer position;Data data;
};struct readargs {
FileIdentifier f;FilePointer position;Length length;
};
program FILEREADWRITE { version VERSION {
void WRITE(writeargs)=1;Data READ(readargs)=2;}=2;
} = 9999;
![Page 23: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/23.jpg)
Instructor’s Guide for
Coulouris, Dollimore and Kindberg
Distributed Systems: Concepts and Design
Edn. 2 (2nd impression)
Addison-Wesley Publishers 1994 58
Figure 5.5 C program for client in Sun RPC.
/* File : C.c - Simple client of the FileReadWrite service. */
#include <stdio.h>#include <rpc/rpc.h>#include "FileReadWrite .h"main(int argc, char ** argv){
CLIENT *clientHandle;char *serverName = "coffee";readargs a;Data *data;
clientHandle= clnt_create(serverName, FILEREADWRITE, VERSION, "udp"); /* creates socket and a client handle*/
if (clientHandle==NULL){ clnt_pcreateerror(serverName); /* unable to contact server */exit(1);
}a.f = 10;a.position = 100;a.length = 1000;data = read_2(&a, clientHandle);/* call to remote read procedure */•••clnt_destroy(clientHandle); /* closes socket */
}
![Page 24: Remote Procedure Callssetia/cs707-S00/slides/rpc.pdfInstructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 2 (2nd impression) Addison-Wesley](https://reader033.vdocuments.site/reader033/viewer/2022051600/5aad3d487f8b9a9c2e8df820/html5/thumbnails/24.jpg)
Instructor’s Guide for
Coulouris, Dollimore and Kindberg
Distributed Systems: Concepts and Design
Edn. 2 (2nd impression)
Addison-Wesley Publishers 1994 59
Figure 5.6 C program for server procedures in Sun RPC.
/* File S.c - server procedures for the FileReadWrite service */#include <stdio.h>#include <rpc/rpc.h>#include"FileReadWrite.h"
void * write_2(writeargs *a){ /* do the writing to the file */}
Data * read_2(readargs * a){
static Data result; /* must be static */result.buffer = ... /* do the reading from the file */result.length = ... /* amount read from the file */return &result;
}