remote procedure call protocols - brown university · rpc were layered on udp, on the theory that...

41
Operating Systems In Depth XXIX–1 Copyright © 2019 Thomas W. Doeppner. All rights reserved. Remote Procedure Call Protocols

Upload: others

Post on 24-Jul-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–1 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Remote Procedure Call Protocols

Page 2: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–2 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Local Procedure Calls

// Client code. . .

result = procedure(arg1, arg2);. . .

// Server coderesult_t procedure(a1_t arg1, a2_t arg2) {

. . .return(result);

}

Page 3: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–3 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Remote Procedure Calls (1)

// Client code. . .

result = procedure(arg1, arg2);. . .

// Server coderesult_t procedure(a1_t arg1, a2_t arg2) {

. . .return(result);

}

?

Page 4: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–4 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Remote Procedure Calls (2)

// Client code. . .

result = procedure(arg1, arg2);. . .

// Server coderesult_t procedure(a1_t arg1, a2_t arg2) {

. . .return(result);

}

Client-Side Stub

Server-Side Stub

Page 5: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–5 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Block Diagram

Client

Application

Stub

RPC supportcode

Transportprotocol

Server

Remoteprocedure

Stub

RPC supportcode

Transportprotocol

Page 6: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–6 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

ONC RPC

• Used with NFS• eXternal Data Representation (XDR)

– specification for how data is transmitted– language for specifying interfaces

Page 7: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–7 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Example

typedef struct {int comp1;float comp2[6];char *annotation;

} value_t;

typedef struct {value_t item;list_t *next;

} list_t;

bool add(int key, value_t item);bool remove(int key, value_t item);list_t query(int key);

Page 8: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–8 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Placing a Call

result = add(key, item);bool add(int k, value_t v) {

…return(result);

}

marshal

Wire

unmarshal

Page 9: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–9 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Returning From the Call

result = add(key, item);char add(int k, value_t v) {

…return(result);

}

Wire

marshalunmarshal

Page 10: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–10 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Marshalled Arguments

intfloat (1)float (2)float (3)float (4)float (5)float (6)

string lengthstring (1 – 4)

string (5 – 8)

int keycomp1

comp2

annotation

item

Page 11: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–11 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Marshalled Linked List

value_t

value_t

value_t

value_t

value_t

value_t

value_t

next: 1

next: 2

next: 3

next: 4

next: 5

next: 6

next: -1

0:

1:

2:

3:

4:

5:

6:

array length

Page 12: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–12 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Reliability Explained …

• Assume, for now, that RPC is layered on top

of (unreliable) UDP

• Exactly once semantics

– each RPC request is handled exactly once on

the server

Page 13: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–13 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

RPC Exchanges

Client ServerRequest 1

Client ServerRequest 2

Client ServerResponse 2

Client ServerResponse 1

Page 14: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–14 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Uncertainty

Client ServerRequest

Client Server

Client ServerRequest

Client Server

Client ServerRequest

Client ServerResponse

Page 15: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–15 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Idempotent Procedures

Client ServerWrite File A Block 0

Client ServerDone

Client Server(Ahem …) Write File A Block 0

Client ServerDone

At-least-once semantics

Page 16: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–16 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Non-Idempotent Procedures

Client ServerTransfer $1000 from Alice’s

Account to Bob’s

Client ServerDone

Client ServerDo it again and again and

again!

Client ServerDone

At-most-once semantics

Page 17: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–17 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Maintaining History

Client ServerTransfer $1000 from Alice’s

Account to Bob’s

Client ServerDone

Client ServerDo it again!

Client ServerDone (replay)

At-most-once semantics

Page 18: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–18 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

No History

Client ServerTransfer $1000 from Alice’s

Account to Bob’s

Client ServerDone

Client ServerDo it again!

Client ServerSorry …

At-most-once semantics

CRASH!!

Page 19: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–19 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Making ONC RPC Reliable

• Each request uniquely identified by transmission ID (XID)– transmission and retransmission share same

XID

• Server maintains duplicate request cache(DRC)

– holds XIDs of non-idempotent requests and copies of their complete responses

– kept in cache for a few minutes

Page 20: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–20 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

AlgorithmReceiverequest

Duplicate?

Repeatoriginal

response

Performrequest

Yes

No

Page 21: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–21 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Did It Work?

• No

Page 22: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–22 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Problem …

Client nfsd2write(data) xid=1

(retransmission)

Client nfsd1write(data) xid=1

blocks

Clientdone

Client nfsd2write(newdata) xid=2

updatesfile

Clientdone updates

file

updatesfile

done

Page 23: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–23 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

SolutionReceiverequest

Duplicate?

Originalin

progress?

Originalsuccessful?

Discard

Idempotent?

Repeatoriginal

reply

Performrequest

Yes

No

No

Yes

No

Yes

No

Yes

Page 24: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–24 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Quiz 1

An idempotent request from the client is received by the server, executed, and the response sent back. But the response doesn’t make it to the client.a) The client retransmits its request and the

original response is sent back (again) to the client

b) The client retransmits its request, but the original response is not sent back and thus, from the client’s point of view, the server has crashed

c) The client, after multiple retransmissions, eventually gets a response

Page 25: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–25 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Did It Work?

• Sort of …• Works fine in well behaved networks• Doesn’t work with “Byzantine” routers

– programmed by your worst (and brightest) enemy

– probably doesn’t occur in local environment– good approximation of behavior on overloaded

Internet• Doesn’t work if server crashes at inopportune

moment (and comes back up)

Page 26: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–26 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Enter TCP

RPC

UDP

IP

TCP

Page 27: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–27 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Quiz 2

UDP is easy to implement efficiently. Early implementations of TCP were not terribly efficient, therefore early implementations of RPC were layered on UDP, on the theory that UDP usually provided reliable delivery.a) TCP is reliable, therefore layering RPC on

top of TCP makes RPC reliableb) The notions of at-most-once and at-least-

once semantics are still relevant, even if RPC is layered on top of TCP

c) There are additional reliability concerns when layering RPC on top of TCP

Page 28: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–28 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

What’s Wrong?

• The problem is the duplicate request cache (DRC)– it’s necessary

– but when may cached entries be removed?

Page 29: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–29 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Session-Oriented RPC

XIDseq.

#response

XIDseq.

#response

XIDseq.

#response

XIDseq.

#response

XIDseq.

#response

Client 1

Client 2

2-slot DRC for client 1

3-slot DRC for client 2

Page 30: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–30 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

DCE RPC

• Designed by Apollo and Digital in the 1980s– both companies later absorbed by HP

• Does everything ONC RPC can do, and more• Basis for Microsoft RPC

Page 31: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–31 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Same Example …

typedef struct {double comp1;int comp2;long long comp3;char *annotation;

} value_t;

char add(int key, value_t value);char remove(int key, value_t value);int query(int key, int number, value_t values[]);

Page 32: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–32 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

An Interface Specification

interface db {typedef struct {double comp1;long comp2;hyper comp3;[string, ptr]ISO_LATIN_1*annotation;

} value_t;

boolean add([in] long key,[in] value_t value

);

boolean remove([in] long key,[in] value_t value

);

[idempotent] long query([in] long key,[in] long number,[out, size_is(number)]value_t values[]

);}

Page 33: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–33 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

An Interface Specification(notes continued)

interface db {typedef struct {double comp1;long comp2;hyper comp3;[string, ptr]ISO_LATIN_1*annotation;

} value_t;

boolean add([in] long key,[in] value_t value

);

boolean remove([in] long key,[in] value_t value

);

[idempotent] long query([in] long key,[in] long number,[out, size_is(number)]value_t values[]

);}

Page 34: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–34 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Representing an Array

Length Item 1 Item 2 … Item n

Page 35: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–35 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Representing Pointers

P *Psender

*Pmarshalled

P *Preceiver

on stack on callee’sstack

Page 36: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–36 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Complications

Page 37: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–37 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Marshalling Unrestricted Pointers

A:

B: C:

D: E:

24

0 (A):

-16

2 (B):

68

4 (C):

6 (D):

8 (E):

Page 38: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–38 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Referring to Server State

ClientServer

pointer

Page 39: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–39 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Maintaining Client State on Servers

interface trees {typedef [context_handle] void *tree_t;

void create ([in] long value,[out] tree_t pine

);

void insert ([in] long value,[in, out] tree_t pine

);}

Page 40: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–40 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

Unique Identifiers

[uuid (333A2276-0000-0000-0D00-008090C000000),version (3.1)]

interface vectorops {

small inner ([in] long size,[in, size_is (size)] long A[ ],[in, size_is (size)] long B[ ],[out] long *result

);}

Page 41: Remote Procedure Call Protocols - Brown University · RPC were layered on UDP, on the theory that UDP usually provided reliable delivery. a)TCP is reliable, therefore layering RPC

Operating Systems In Depth XXIX–41 Copyright © 2019 Thomas W. Doeppner. All rights reserved.

UUIDs

low bits of time mid bits of time high bitsof time

32 16 4 12

version

clockseq high

clockseq Low node address

2 6 8 48

reserved