1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

40
1 Remote Procedure Calls (RPC) Remote Procedure Calls (RPC) and Distributed Objects and Distributed Objects G53ACC G53ACC Chris Greenhalgh Chris Greenhalgh

Transcript of 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

Page 1: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

1

Remote Procedure Calls (RPC) and Remote Procedure Calls (RPC) and Distributed ObjectsDistributed Objects

G53ACCG53ACCChris GreenhalghChris Greenhalgh

Page 2: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

2

ContentsContents

Local procedure callsLocal procedure calls Remote Procedure Call ModelRemote Procedure Call Model Implementation IssuesImplementation Issues

– TransparencyTransparency

– BindingBinding

– HeterogeneityHeterogeneity

– ConcurrencyConcurrency Making a Remote Procedure CallMaking a Remote Procedure Call

– Stubless RPCStubless RPC Distributed ObjectsDistributed Objects

Page 3: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

3

BooksBooks

Comer (4Comer (4thth ed) Chapter 38 ed) Chapter 38 Farley Chapter 3Farley Chapter 3

Page 4: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

4

Remote Procedure CallsRemote Procedure Calls

High level representation of Inter Process High level representation of Inter Process CommunicationCommunication– To transfer informationTo transfer information– To invoke an action in a remote processTo invoke an action in a remote process

Natural fit with client-server approachNatural fit with client-server approach Uses the normal procedure call metaphor and Uses the normal procedure call metaphor and

programming styleprogramming style Calls a procedure in another processCalls a procedure in another process

Page 5: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

5

A “C” function call A “C” function call (cf. Java static [class] method invocation)(cf. Java static [class] method invocation)

int main(){ int a=10; int b=20; int result; result=add_numbers(a,b)

}

int add_numbers(int a, int b){ return a+b;}

2 3

4

Process X

1

Page 6: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

6

What is a procedure call?What is a procedure call?

A general abstraction mechanism in imperative A general abstraction mechanism in imperative programming languagesprogramming languages

Parameterised “language extension”Parameterised “language extension” Defined by an Defined by an interfaceinterface which specifies: which specifies:

– the name of the operationthe name of the operation– the arguments to be passedthe arguments to be passed

In some systems their direction, e.g. in/out/inoutIn some systems their direction, e.g. in/out/inout– In is typically the default and/or only option (e.g. RMI)In is typically the default and/or only option (e.g. RMI)

– the type of results to be returnedthe type of results to be returned

Page 7: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

7

The procedure call interfaceThe procedure call interface

Caller

example (x1,...,xn);

Callee

example (y1,...,yn){ ...}

A procedure call must specify the argument and return types.A remote procedure call must also specify which process to locate the procedure in.

Interface

tr e

xam

ple(

t1,..

.,tn)

Page 8: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

8

Making a local procedure Making a local procedure (or method) call…(or method) call…

A local procedure call:A local procedure call:– Copies the arguments onto the stackCopies the arguments onto the stack

(or “invocation record”)(or “invocation record”)

– Allocates space for the return resultsAllocates space for the return results– Calls the procedure:Calls the procedure:

Preserves the address of the next instruction on the Preserves the address of the next instruction on the stackstack

Sets the program counter to the start of the called Sets the program counter to the start of the called function…function…

Page 9: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

9

Making a local procedure call (2)Making a local procedure call (2)

Called function starts to execute:Called function starts to execute:

– Access arguments according to their position on the Access arguments according to their position on the stackstack

Has access to the same stack/invocation recordHas access to the same stack/invocation record

– Copies a return value into registers or onto the stackCopies a return value into registers or onto the stack

– Restores the program counter to the value placed on the Restores the program counter to the value placed on the stack by the caller…stack by the caller…

Which resumes execution:Which resumes execution:

– Collects result from the stackCollects result from the stack

– Tidies up stackTidies up stack

Page 10: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

10

A remote procedure callA remote procedure call

int main(){ int a=10; int b=20; int result; result=add_numbers(a,b)

}

int add_numbers(int a, int b){ return a+b;}

Process Y

2 3

4

Process X

1

Page 11: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

11

RPC InterfaceRPC Interface

Flows 1 and 3 are identical in both casesFlows 1 and 3 are identical in both cases– but each must be a different thread/processbut each must be a different thread/process

Flow 2: call jumps from process X to YFlow 2: call jumps from process X to Y Flow 4: return jumps from process Y to XFlow 4: return jumps from process Y to X

=> Corresponds to two network messages => Corresponds to two network messages (2 and 4) plus control over execution(2 and 4) plus control over execution

Page 12: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

12

Local procedure call structureLocal procedure call structureProcess/Application A

procedure call interface

Callee

Caller

Page 13: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

13

RPC versionRPC version

Callee

Process/Application B

Caller

Process/Application A

RPC support

Remote Procedure Call standard(?) protocol

(typically over a TCP/IP connection)

Identicalprocedure

call interface

RequestResponse

networking

RPC support

networking

“middleware”

Page 14: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

14

Implementation IssuesImplementation Issues

TransparencyTransparency BindingBinding HeterogeneityHeterogeneity ConcurrencyConcurrency

Page 15: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

15

Implementation Issues 1:Implementation Issues 1:TransparencyTransparency

Def.Def.“Hiding” from the programmer whether a “Hiding” from the programmer whether a particular procedure call is local or remote, or particular procedure call is local or remote, or which machine it runs on.which machine it runs on.– Does/should the programmer “care” whether a Does/should the programmer “care” whether a

call was local or remote?call was local or remote?– Is it even possible to discover this? Is it even possible to discover this?

Page 16: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

16

TransparencyTransparency

Pro:Pro:

No “special”/extra knowledge or information No “special”/extra knowledge or information required to required to – Write a distributed applicationWrite a distributed application– Understand a distributed programUnderstand a distributed program

Page 17: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

17

TransparencyTransparency

But…But…– More things can go wrong in the remote case:More things can go wrong in the remote case:

Partial failure: server – no answer?Partial failure: server – no answer? Partial failure: client – not worth continuing?Partial failure: client – not worth continuing? Network failure: cannot communicate request Network failure: cannot communicate request

and/or responseand/or response

– In general the program may need to deal with In general the program may need to deal with these…these…

Page 18: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

18

TransparencyTransparency

Ideal?!Ideal?!– Make it as much like a local procedure as Make it as much like a local procedure as

possiblepossible– Minimise the situations in which extra Minimise the situations in which extra

knowledge is requiredknowledge is required– Provide facilities for programmer to access Provide facilities for programmer to access

“hidden” details if required“hidden” details if required [Forward reference: Java RMI remote methods [Forward reference: Java RMI remote methods

throw RemoteException]throw RemoteException]

Page 19: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

19

Achieving transparencyAchieving transparency

““Stub” code on client Stub” code on client – Generated by RPC toolsGenerated by RPC tools– Has same interface as remote procedureHas same interface as remote procedure called in exactly the same waycalled in exactly the same way

Same nameSame name Same arguments on stackSame arguments on stack Same return typeSame return type

Page 20: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

20

Achieving transparencyAchieving transparency

Similar “Stub” or “skeleton” code on serverSimilar “Stub” or “skeleton” code on server– Also generated by RPC toolsAlso generated by RPC tools– Calls the remote procedure body in the same Calls the remote procedure body in the same

way as a normal procedure callway as a normal procedure call Same nameSame name Same arguments on stackSame arguments on stack Same return typeSame return type

Page 21: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

21

Other Unavoidable DifferencesOther Unavoidable Differences

No shared memory between caller and calleeNo shared memory between caller and callee

– Arguments and results are Arguments and results are copiedcopied across the network across the network

– So changes made to arguments in callee are not visible So changes made to arguments in callee are not visible to callerto caller

Unless RPC system supports in/out & out arguments, which Unless RPC system supports in/out & out arguments, which are copied back to the callee [not JavaRMI]are copied back to the callee [not JavaRMI]

– Result object cannot be a direct reference to an Result object cannot be a direct reference to an argument – will be a copyargument – will be a copy

– Methods are invoked on the local copy Methods are invoked on the local copy [unless they are themselves distribution/remote objects][unless they are themselves distribution/remote objects]

Binding must be specified – see next issueBinding must be specified – see next issue

Page 22: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

22

Implementation Issues 2:Implementation Issues 2:BindingBinding

A local procedure call is satisfied in the local A local procedure call is satisfied in the local process:process:– linker matches procedure names linker matches procedure names – fills in process-local address of procedurefills in process-local address of procedure

An RPC allows us to call a procedure in another An RPC allows us to call a procedure in another process:process:– How is an appropriate remote procedure How is an appropriate remote procedure

located?located?– How do we specify (i.e. name) it?How do we specify (i.e. name) it?– How do we communicate with it at the network How do we communicate with it at the network

layer?layer?

Page 23: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

23

BindingBinding

Option 1: use some configuration option or Option 1: use some configuration option or additional support API to specify the remote additional support API to specify the remote procedureprocedure– Con: extra API, different to local caseCon: extra API, different to local case

Option 2: change the interface to include extra Option 2: change the interface to include extra informationinformation– Con: different interface to local caseCon: different interface to local case

But object-oriented But object-oriented methodmethod invocations already invocations already have an explicit target!have an explicit target!

Page 24: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

24

Distributed ObjectsDistributed Objects

Remote Remote Prodedure Call Prodedure Call becomes becomes Remote Remote Method InvocationMethod Invocation– i.e. methods can be invoked on objects which are i.e. methods can be invoked on objects which are

[ultimately] in another process.[ultimately] in another process. Access and location transparency:Access and location transparency:

just another method invocation, but…just another method invocation, but…– Local object references are ultimately obtained by Local object references are ultimately obtained by

instantiating an object (or loading a class) in the local instantiating an object (or loading a class) in the local process.process.

– Remote object references are obtained from the Remote object references are obtained from the distributed object system itself.distributed object system itself.

– More things can still go wrong (see “transparency”)More things can still go wrong (see “transparency”)

Page 25: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

25

Implementation Issues 3:Implementation Issues 3:HeterogeneityHeterogeneity

Def.Def.Allowing RPCs/RMIs between processes on Allowing RPCs/RMIs between processes on different machinesdifferent machines– different operating systemsdifferent operating systems– different data representationdifferent data representation

little endian vs big endian representationslittle endian vs big endian representations integer and other type sizes and representationsinteger and other type sizes and representations character setscharacter sets

Page 26: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

26

Heterogeneity:Heterogeneity:Specifying the InterfaceSpecifying the Interface

For describing the data structures (requests, responses, For describing the data structures (requests, responses, arguments, results) being passed in an RPC we can use arguments, results) being passed in an RPC we can use either:either:– a platform and programming language-independent a platform and programming language-independent

specification language, e.g. specification language, e.g. OSI has ASN.1OSI has ASN.1 Internet (e.g. NFS) has XDRInternet (e.g. NFS) has XDR OMG CORBA has (an) IDLOMG CORBA has (an) IDL COM/DCOM IDLCOM/DCOM IDL

– a particular programming language, e.g.a particular programming language, e.g. Java for RMIJava for RMI

Page 27: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

27

HeterogeneityHeterogeneity

The interface definition (and/or data representation) The interface definition (and/or data representation) language allows us to:language allows us to:

– translate a language and platform specific data structure translate a language and platform specific data structure into a standard sequence of bytes (“marshall”)into a standard sequence of bytes (“marshall”)

– translate those bytes back into an equivalent data translate those bytes back into an equivalent data structure (at the other end) (“unmarshall”)structure (at the other end) (“unmarshall”)

Byte sequences are used in the lower layers of the Byte sequences are used in the lower layers of the implementation and on the networkimplementation and on the network

Native structures used in the higher layers – the actual Native structures used in the higher layers – the actual procedure/method call(s)procedure/method call(s)

Page 28: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

28

Implementation Issues 4:Implementation Issues 4:ConcurrencyConcurrency

A local procedure call has one thread A local procedure call has one thread ((– I.e. flow of control or virtual CPU I.e. flow of control or virtual CPU

Threads are local to a single process Threads are local to a single process – (excepting some specialised distributed OSs)(excepting some specialised distributed OSs)

So an RPC has (at least) two threadsSo an RPC has (at least) two threads– caller threadcaller thread– callee threadcallee thread

Page 29: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

29

ConcurrencyConcurrency

Server side has a Server side has a dispatcherdispatcher – with its own thread(s).with its own thread(s).

The dispatcher calls the appropriate function stub The dispatcher calls the appropriate function stub with the data bytes with the data bytes – gives the stub a thread of control to executegives the stub a thread of control to execute

Client thread Client thread maymay block waiting for results block waiting for results– Synchronous (wait) vs. asynchronous (not)Synchronous (wait) vs. asynchronous (not)

Page 30: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

30

ConcurrencyConcurrency

Synchronous (blocking)Synchronous (blocking)

– Same “feel” as local procedure caseSame “feel” as local procedure case

– Thread resources (memory) are idleThread resources (memory) are idle

– Client may be left idleClient may be left idle (other threads with things to do?)(other threads with things to do?)

Asynchronous (non-blocking)Asynchronous (non-blocking)

– Could be unreliable – never collects resultCould be unreliable – never collects result

– Could be reliableCould be reliable continue with other operations until the result is returned.continue with other operations until the result is returned. => need some way to “rejoin” results (new API)=> need some way to “rejoin” results (new API)

Page 31: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

31

Making a Remote Procedure Call (cont.)Making a Remote Procedure Call (cont.)

ClientStub

1 6

8

ClientComms

2 9

Callee5

ServerStub

47ServerComms

3Network

CallerStart

10

Finish

genericspecific

Page 32: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

33

Request messageRequest message

Contains:Contains:

– Byte sequence representations of argumentsByte sequence representations of arguments

– Byte sequence representation of method/procedure to Byte sequence representation of method/procedure to callcall

– [option] byte sequence representation of server object [option] byte sequence representation of server object identityidentity

– [option] unique request identifier[option] unique request identifier To match responses and/or avoid duplicatesTo match responses and/or avoid duplicates

Also requires return information and error checking Also requires return information and error checking

– often part of networking support, e.g. TCPoften part of networking support, e.g. TCP

Page 33: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

36

Response messageResponse message

Contains:Contains:– Byte sequence representations of result (if any)Byte sequence representations of result (if any)

Or byte sequence representation of failure Or byte sequence representation of failure description if unsuccessfuldescription if unsuccessful

– [option] unique request identifier[option] unique request identifier To match with request and/or avoid duplicatesTo match with request and/or avoid duplicates

Also requires error checking Also requires error checking – often part of networking support, e.g. TCPoften part of networking support, e.g. TCP

Page 34: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

37

Making a remote procedure call (cont.)Making a remote procedure call (cont.)Results in ClientResults in Client

Client comms function receives the responseClient comms function receives the response– Standard networkingStandard networking– Incoming response must be linked with calling Incoming response must be linked with calling

thread thread E.g. by exclusive connection or explicit request IDE.g. by exclusive connection or explicit request ID

– returns the values to the waiting client stub (9) returns the values to the waiting client stub (9) Unmarshalling resultUnmarshalling result

– which returns the value to the calling function which returns the value to the calling function (10) which continues executing(10) which continues executing

Page 35: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

38

If something goes wrong…If something goes wrong…

An error in the serverAn error in the server– Could be caught by the server stub (e.g. an Could be caught by the server stub (e.g. an

exception in the callee code)exception in the callee code) An error message returned to the clientAn error message returned to the client Client stub reports this error to the caller Client stub reports this error to the caller

– E.g. throws an exception E.g. throws an exception

– Could be detected by the client (e.g. a network Could be detected by the client (e.g. a network failure)failure)

Client stub reports this error directly to the caller Client stub reports this error directly to the caller – E.g. throws an exception E.g. throws an exception

Page 36: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

39

Stubless Remote Procedure CallsStubless Remote Procedure Calls

Dynamic Invocation

API

1 6

8

ClientComms

2 9

Callee

5

(Reflective?)Generic

despatcher47

ServerComms

3Network

CallerStart

10

Finish

generic

specific

reflective

Page 37: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

40

Stubless Remote Procedure Calls Stubless Remote Procedure Calls

No custom-generated interface-specific stubNo custom-generated interface-specific stub– No custom-generated marshallingNo custom-generated marshalling

Stubless clientStubless client– Caller directly constructs (using API) generic Caller directly constructs (using API) generic

RPC requests, that can be sent to any serverRPC requests, that can be sent to any server Still needs to know what the server will expectStill needs to know what the server will expect System may have a way to retrieve this informationSystem may have a way to retrieve this information

Can make generic (universal) clientsCan make generic (universal) clients– E.g. for testing, configuration and managementE.g. for testing, configuration and management

Page 38: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

41

Stubless Remote Procedure CallsStubless Remote Procedure Calls

Stubless serverStubless server– Generic stub translates request to local form Generic stub translates request to local form

and invokes callee code directlyand invokes callee code directly E.g. using language reflection facilitiesE.g. using language reflection facilities Less code generationLess code generation Requires suitable language support and generic Requires suitable language support and generic

marshalling frameworkmarshalling framework

– Or generic stub delivers generic RPC requests Or generic stub delivers generic RPC requests to generic callee codeto generic callee code

E.g. for generic server that passes requests on to E.g. for generic server that passes requests on to another system, or for testing another system, or for testing

Page 39: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

42

Distributed Object SystemsDistributed Object Systems

Often called “middleware”, or Often called “middleware”, or “run-time infrastructure”:“run-time infrastructure”:

– Above the networking and OS, below the applicationAbove the networking and OS, below the application

– Provide the “glue” to link objects in different process/on Provide the “glue” to link objects in different process/on different machines.different machines.

– May provide additional services and support.May provide additional services and support. Examples:Examples:

– Java RMIJava RMI

– CORBA (platform independent standard)CORBA (platform independent standard)

– DCOM (Microsoft, Windows-specific)DCOM (Microsoft, Windows-specific)

– ANSAware, ...ANSAware, ...

Page 40: 1 Remote Procedure Calls (RPC) and Distributed Objects G53ACC Chris Greenhalgh.

43

Distributed Objects Systems (2)Distributed Objects Systems (2)

Like RPCs (as already noted)Like RPCs (as already noted) Relies on interface definitionsRelies on interface definitions

– e.g. Corba IDL, Java RMI interface bytecode e.g. Corba IDL, Java RMI interface bytecode Defines what a client can ask Defines what a client can ask

– client-middleware interface (method signatures) client-middleware interface (method signatures)

– Supporting services (e.g. naming)Supporting services (e.g. naming) Defines what a server can do Defines what a server can do

– middleware-server interfacemiddleware-server interface

– Supporting services (e.g. persistence)Supporting services (e.g. persistence) Middleware handles requests in generic, portable formMiddleware handles requests in generic, portable form