REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading...
-
Upload
kenneth-lucas -
Category
Documents
-
view
216 -
download
1
Transcript of REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading...
![Page 1: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/1.jpg)
REMOTE PROCEDURE CALLS
EE324
![Page 2: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/2.jpg)
Administrivia
Course feedback Midterm plan Reading material/textbook/slides are updated.
Computer Systems: A Programmer's Perspective, by Bryant and O'Hallaron
Some reading material (URL) in the slides. (lecture 9)
![Page 3: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/3.jpg)
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
![Page 4: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/4.jpg)
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. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/5.jpg)
5
Distributed Systems
The middleware layer extends over multiple machines, and offers each application the same interface.
![Page 6: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/6.jpg)
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. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/7.jpg)
7
How?
The middleware layer extends over multiple machines, and offers each application the same interface.
![Page 8: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/8.jpg)
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. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/9.jpg)
Many ways
Request-reply protocols Remote procedure calls (RPC) 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. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/10.jpg)
Request-reply protocols
Client ServerHey, do something
working {
Done/Result
![Page 11: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/11.jpg)
Request-reply protocols
eg, 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. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/12.jpg)
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. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/13.jpg)
Remote Procedure Call (RPC)
A type of client/server communica-tion
Attempts to make remote proce-dure calls look like local ones
figure from Microsoft MSDN
{ ... foo()}void foo() { invoke_remote_foo()}
![Page 14: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/14.jpg)
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 Proce-dure Call., 1981 :)
![Page 15: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/15.jpg)
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. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/16.jpg)
16
RPC
The interaction between client and server in a traditional RPC.
![Page 17: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/17.jpg)
17
Passing Value Parameters (1)
The steps involved in a doing a remote computation through RPC.
![Page 18: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/18.jpg)
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. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/19.jpg)
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 marshalling, too. Floating point... Nested structures? (Design question for the RPC system - do you
support them?) Complex datastructures? (Some RPC systems let you send lists
and maps as first-order objects)
![Page 20: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/20.jpg)
“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. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/21.jpg)
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. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/22.jpg)
And describes functions
program FOOPROG { version VERSION { void FOO(fooargs) = 1; void BAR(barargs) = 2; } = 1;} = 9999;
![Page 23: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/23.jpg)
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. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/24.jpg)
24
RPC vs. LPC
Memory access Partial failures Latency
![Page 25: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/25.jpg)
But it’s not always simple
Properties of distributed computing that make achieving trans-parency difficult: Calling and called procedures run on different machines,
with different address spaces Machines and network can fail Latency
![Page 26: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/26.jpg)
26
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 27: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/27.jpg)
27
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 28: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/28.jpg)
RPC failures
Request from cli -> srv lost Reply from srv -> cli lost Server crashes after receiving request Client crashes after sending request
![Page 29: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/29.jpg)
29
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 30: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/30.jpg)
30
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 31: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/31.jpg)
RPC semantics: Exactly-Once?
Sorry - no can do in general. Imagine that message triggers an external physical
thing (say, a robot fires a missle) 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 32: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/32.jpg)
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 33: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/33.jpg)
Implementing at-most-once
At-least-once: Just keep retrying on client side until you get a re-sponse. Server just processes requests as normal, doesn’t remember any-
thing. Simple! At-most-once: Server might get same request twice...
Must re-send previous reply and not process request (implies: keep cache of handled requests/responses)
Must be able to identify requests Strawman: remember all RPC IDs handled. -> Ugh! Requires infi-
nite memory. Real: Keep sliding window of valid RPC IDs, have client number them
sequentially.
![Page 34: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/34.jpg)
34
Summary: expose remoteness to client
Expose RPC properties to client, since you cannot hide them
Application writers have to decide how to deal with par-tial failures Consider: E-commerce application vs. game
![Page 35: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/35.jpg)
35
RPC implementation issues
![Page 36: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/36.jpg)
36
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 37: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/37.jpg)
37
Writing a Client and a Server (1)
The steps in writing a client and a server in DCE RPC.
![Page 38: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/38.jpg)
38
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 39: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/39.jpg)
39
RPC protocol
Guarantee at-most-once semantics by tagging requests 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 40: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/40.jpg)
40
RPC transport
Use reliable transport layer Flow control Congestion control Reliable message transfer
Combine RPC and transport protocol Reduce number of messages
RPC response can also function as acknowledgement for message transport protocol
![Page 41: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/41.jpg)
Performance
As a general library, performance is often a big concern for RPC systems
Major source of overhead: copies and marshaling/unmarshaling 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 between two little-endian ma-chines
Scatter-gather writes (writev() and friends)
![Page 42: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/42.jpg)
Complex / Pointer Data Structures
Very few low-level RPC systems support C is messy about things like that -- can’t always understand the
structure and know where to stop chasing 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!
![Page 43: REMOTE PROCEDURE CALLS EE324. Administrivia Course feedback Midterm plan Reading material/textbook/slides are updated. Computer Systems: A Programmer's.](https://reader035.fdocuments.in/reader035/viewer/2022070408/56649e605503460f94b5b7b1/html5/thumbnails/43.jpg)
43
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”