45
REMOTE PROCEDURE CALLS EE324

REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

Embed Size (px)

Citation preview

Page 1: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

REMOTE PROCEDURE CALLS

EE324

Page 2: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

2

일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기

억지로 좋아하려고 하기 보다 열정을 가지기

억지로 열정을 가지려하기 보다 주어진 일에 몰입하기

억지로 몰입하려고 하기보다 즐거움으로 최선을 다 하기

Page 3: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

Building up to today

Abstractions for communication Internetworking protocol: IP TCP masks some of the pain of communicating across un-

reliable IP Abstractions for computation and I/O

Process: A resource container for execution on a single machine

Thread: pthread and synchronization primitives (sem, mu-tex, cv)

File (later)

Page 4: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

4

Now back to Distributed Systems: remember?

A distributed system is: “A collection of independent computers that appears to its users as a single coherent system”

"A distributed system is one in which the failure of a computer you didn't even know existed can render your own computer unusable." – Leslie Lamport

Page 5: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

5

Distributed Systems

The middleware layer extends over multiple machines, and offers each application the same interface.

Page 6: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

6

What does it do?

Hide complexity to programmers/usersHide the fact that its processes and resources are physically distributed across multiple machines.

Transparency in a Distributed System

Page 7: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

7

How?

The middleware layer extends over multiple machines, and offers each application the same interface.

Page 8: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

Starter for Today

Splitting computation across the net-work

What programming abstractions work well to split work among multiple networked

computers?

Page 9: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

Many ways

Request-reply protocols Remote procedure calls (RPC) or Remote method invocation (RMI)

Recommended reading : Distributed Systems: Concepts and Design 5th edition, by Coulouris, et al.(CDK5) chapter 5

Page 10: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

Request-reply protocols

Client ServerHey, do something

working {

Done/Result

Page 11: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

Request-reply protocols

E.g., your PA1 (binary protocol)

struct foomsg { u_int32_t len;}

send_foo(char *contents) { int msglen = sizeof(struct foomsg) + strlen(contents); char buf = malloc(msglen); struct foomsg *fm = (struct foomsg *)buf; fm->len = htonl(strlen(contents)); memcpy(buf + sizeof(struct foomsg), contents, strlen(contents)); write(outsock, buf, msglen);}

Then wait for response, handle timeout, etc.

Page 12: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

Request-reply protocols: text protocol

HTTP See the HTTP/1.1 standard: http://www.w3.org/Protocols/rfc2616/rfc2616.html Done with your PA2 yet?

Page 13: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

Remote Procedure Call (RPC)

A type of client/server communication Attempts to make remote procedure calls look like

local ones

figure from Microsoft MSDN

{ ... foo()}void foo() { invoke_remote_foo()}

Page 14: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

RPC Goals

Ease of programming Hide complexity Automate a lot of task of implementing Familiar model for programmers (just make a function

call)

Historical note: Seems obvious in retrospect, but RPC was only invented in the ‘80s. See Birrell & Nelson, “Implementing Remote Procedure Call” ... orBruce Nelson, Ph.D. Thesis, Carnegie Mellon University: Remote Procedure Call., 1981 :)

Page 15: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

15

Remote procedure call

A remote procedure call makes a call to a remote ser-vice 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

Page 16: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

16

RPC

The interaction between client and server in a traditional RPC.

Page 17: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

17

Passing Value Parameters (1)

The steps involved in a doing a remote computation through RPC.

Page 18: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

But it’s not always simple

Calling and called procedures run on different ma-chines, with different address spaces And perhaps different environments .. or operating

systems .. Must convert to local representation of data Machines and network can fail

Page 19: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

Marshaling and Unmarshaling

(From example) hotnl() -- “host to network-byte-order, long”. network-byte-order (big-endian) standardized to deal with

cross-platform variance Note how we arbitrarily decided to send the string by sending

its length followed by L bytes of the string? That’s mar-shalling, too.

Floating point... Nested structures? (Design question for the RPC system - do

you support them?) Complex data structures? (Some RPC systems let you send

lists and maps as first-order objects)

Page 20: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

“stubs” and IDLs

RPC stubs do the work of marshaling and unmarshaling data

But how do they know how to do it? Typically: Write a description of the function signature us-

ing an IDL -- interface definition language. Lots of these. Some look like C, some look like XML, ...

details don’t matter much.

Page 21: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

SunRPC

Venerable, widely-used RPC system Defines “XDR” (“eXternal Data Representation”) -- C-

like language for describing functions -- and provides a compiler that creates stubs

struct fooargs { string msg<255>; int baz;}

Page 22: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

And describes functions

program FOOPROG { version VERSION { void FOO(fooargs) = 1; void BAR(barargs) = 2; } = 1;} = 9999;

Page 23: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

More requirements

Provide reliable transmission (or indicate failure) May have a “runtime” that handles this

Authentication, encryption, etc. Nice when you can add encryption to your system by

changing a few lines in your IDL file (it’s never really that simple, of course -- identity/key manage-

ment)

Page 24: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로
Page 25: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

XML-RPC request/response example

<?xml version="1.0"?> <methodCall> <methodName>examples.getStateName</methodName> <params> <param> <value><i4>40</i4></value> </param> </params> </methodCall>

<?xml version="1.0"?> <methodResponse> <params> <param> <value><string>South Dakota</string></value> </param> </params> </methodResponse>

Page 26: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

26

RPC vs. LPC

Memory access Partial failures Latency

Page 27: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

But it’s not always simple

Properties of distributed computing that make achieving transparency difficult: Calling and called procedures run on different machines,

with different address spaces Machines and network can fail Latency is much longer for RPC because it involves in net-

work transmission and marshalling/unmarshalling

Page 28: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

28

Passing Reference Parameters

Replace with pass by copy/restore Need to know size of data to copy

Difficult in some programming languages

Solves the problem only partially What about data structures containing pointers? Access to memory in general?

Page 29: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

29

Partial failures

In local computing: if machine fails, application fails

In distributed computing: if a machine fails, part of application fails one cannot tell the difference between a machine failure and

network failure How to make partial failures transparent to client?

Page 30: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

RPC failures

Request from cli -> srv lost Reply from srv -> cli lost Server crashes after receiving request Client crashes after sending request

Page 31: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

31

Strawman solution

Make remote behavior identical to local behavior: Every partial failure results in complete failure

You abort and reboot the whole system You wait patiently until system is repaired

Problems with this solution: Many catastrophic failures Clients block for long periods

System might not be able to recover

Page 32: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

32

Real solution: break transparency

Possible semantics for RPC: Exactly-once

Impossible in practice At least once:

Only for idempotent operations At most once

Zero, don’t know, or once Zero or once

Transactional semantics At-most-once most practical

But different from LPC

Page 33: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

RPC semantics: Exactly-Once?

Sorry - no can do in general. Imagine that message triggers an external physical

thing (say, a robot fires a missile) The robot could crash immediately before or after fir-

ing and lose its state. Don’t know which one hap-pened. Can, however, make this window very small.

Page 34: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

RPC semantics

At-least-once semantics Keep retrying...

At-most-once Use a sequence # to ensure idempotency against network

retransmissions and remember it at the server

Page 35: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

Implementing at-most-once

At-least-once: Just keep retrying on client side until you get a response. Server just processes requests as normal, doesn’t re-

member anything. Simple! At-most-once: Server might get same request twice...

Must re-send previous reply and not process request (im-plies: keep cache of handled requests/responses)

Must be able to identify requests Strawman: remember all RPC IDs handled. -> Ugh! Re-

quires infinite memory. Real: Keep sliding window of valid RPC IDs, have client

number them sequentially.

Page 36: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

36

Summary: expose remoteness to client

Expose RPC properties to client, since you cannot hide them

Application writers have to decide how to deal with partial failures Consider: E-commerce application vs. game

Page 37: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

37

RPC implementation issues

Page 38: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

38

RPC implementation

Stub compiler Generates stubs for client and server Language dependent Compile into machine-independent format

E.g., XDR Format describes types and values

RPC protocol RPC transport

Page 39: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

39

Writing a Client and a Server (1)

The steps in writing a client and a server in DCE RPC.

Page 40: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

40

Writing a Client and a Server (2)

Three files output by the IDL compiler:

A header file (e.g., interface.h, in C terms). The client stub. The server stub.

Page 41: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

41

RPC protocol

Guarantee at-most-once semantics by tagging re-quests and response with a nonce

RPC request header: Request nonce Service Identifier Call identifier

Protocol: Client resends after time out Server maintains table of nonces and replies

Page 42: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

42

RPC transport

Use reliable transport layer Flow control Congestion control Reliable message transfer

Page 43: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

Performance

As a general library, performance is often a big concern for RPC systems

Major source of overhead: copies and marshaling/un-marshaling overhead

Zero-copy tricks: Representation: Send on the wire in native format

and indicate that format with a bit/byte beforehand. What does this do? Think about sending uint32 be-tween two little-endian machines

Scatter-gather writes (writev() and friends)

Page 44: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

Complex / Pointer Data Structures

Very few low-level RPC systems support C is messy about things like that -- can’t always under-

stand the structure and know where to stop chasing Hard to go with C like language

Java RMI (and many other higher-level languages) allows sending objects as part of an RPC But be careful - don’t want to send megabytes of data

across network to ask simple question! Java support object serialization (remember python?)

Page 45: REMOTE PROCEDURE CALLS EE324. 일과 행복 억지로 잘하려고 하기 보다 좋아하려고 노력하기 억지로 좋아하려고 하기 보다 열정을 가지기 억지로

45

Important Lessons

Procedure calls Simple way to pass control and data Elegant transparent way to distribute application Not only way…

Hard to provide true transparency Failures Performance Memory access Etc.

How to deal with hard problem give up and let programmer deal with it “Worse is better”