RMI & RPC. CS 475, Spring 2019 Concurrent & Distributed Systems

Similar documents
Systems Fundamentals. SWE 622, Spring 2017 Distributed Software Engineering

416 Distributed Systems. RPC Day 2 Jan 12, 2018

416 Distributed Systems. RPC Day 2 Jan 11, 2017

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 22: Remote Procedure Call (RPC)

REMOTE PROCEDURE CALLS EE324

Remote Procedure Calls

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

CSci Introduction to Distributed Systems. Communication: RPC

DISTRIBUTED COMPUTER SYSTEMS

Today: Distributed Objects. Distributed Objects

Distributed Systems Theory 4. Remote Procedure Call. October 17, 2008

C 1. Recap: Finger Table. CSE 486/586 Distributed Systems Remote Procedure Call. Chord: Node Joins and Leaves. Recall? Socket API

Administrivia. Remote Procedure Calls. Reminder about last time. Building up to today

Distributed Systems. Lecture 06 Remote Procedure Calls Thursday, September 13 th, 2018

a. Under overload, whole network collapsed iii. How do you make an efficient high-level communication mechanism? 1. Similar to using compiler instead

Async Programming & Networking. CS 475, Spring 2018 Concurrent & Distributed Systems

Lecture 5: RMI etc. Servant. Java Remote Method Invocation Invocation Semantics Distributed Events CDK: Chapter 5 TVS: Section 8.3


Remote Procedure Call (RPC) and Transparency

RPC. Remote Procedure Calls. Robert Grimm New York University

Building up to today. Remote Procedure Calls. Reminder about last time. Threads - impl

Remote Invocation. Today. Next time. l Overlay networks and P2P. l Request-reply, RPC, RMI

CHAPTER - 4 REMOTE COMMUNICATION

L1: Complexity, Enforced Modularity, and client/server organization Frans Kaashoek and Dina Katabi

Communication. Distributed Systems Santa Clara University 2016

Consistency. CS 475, Spring 2018 Concurrent & Distributed Systems

Remote Invocation Vladimir Vlassov and Johan Montelius

Remote Procedure Call

How do modules communicate? Enforcing modularity. Modularity: client-server organization. Tradeoffs of enforcing modularity

Page 1. Goals for Today" Remote Procedure Call" Raw messaging is a bit too low-level for programming! RPC Details"

15-498: Distributed Systems Project #1: Design and Implementation of a RMI Facility for Java

DISTRIBUTED OBJECTS AND REMOTE INVOCATION

Middleware. Adapted from Alonso, Casati, Kuno, Machiraju Web Services Springer 2004

MODELS OF DISTRIBUTED SYSTEMS

CAS 703 Software Design

DS 2009: middleware. David Evans

RMI: Design & Implementation

Remote Invocation. Today. Next time. l Indirect communication. l Request-reply, RPC, RMI

Today CSCI Communication. Communication in Distributed Systems. Communication in Distributed Systems. Remote Procedure Calls (RPC)

MODELS OF DISTRIBUTED SYSTEMS

3. Remote Procedure Call

Agreement and Consensus. SWE 622, Spring 2017 Distributed Software Engineering

Structured communication (Remote invocation)

COMMUNICATION IN DISTRIBUTED SYSTEMS

Contents. Java RMI. Java RMI. Java RMI system elements. Example application processes/machines Client machine Process/Application A

CMSC 433 Programming Language Technologies and Paradigms. Spring 2013

Distributed Systems. The main method of distributed object communication is with remote method invocation

Lecture 15: Network File Systems

Distributed Systems. 5. Remote Method Invocation

CSCI-1680 RPC and Data Representation. Rodrigo Fonseca

Remote Procedure Call

Distributed systems. Programming with threads

Example File Systems Using Replication CS 188 Distributed Systems February 10, 2015

Message Passing vs. Distributed Objects. 5/15/2009 Distributed Computing, M. L. Liu 1

CS603: Distributed Systems

COMMUNICATION PROTOCOLS: REMOTE PROCEDURE CALL (RPC)

struct foomsg { u_int32_t len; }

Remote Invocation. To do. Request-reply, RPC, RMI. q Today q. q Next time: Indirect communication

Lecture 5: Object Interaction: RMI and RPC

Operating Systems. 18. Remote Procedure Calls. Paul Krzyzanowski. Rutgers University. Spring /20/ Paul Krzyzanowski

Lecture 06: Distributed Object

Lightweight RPC. Robert Grimm New York University

CSCI-1680 RPC and Data Representation. Rodrigo Fonseca

CS 355. Computer Networking. Wei Lu, Ph.D., P.Eng.

Remote Method Invocation

Transactions. CS 475, Spring 2018 Concurrent & Distributed Systems

Chapter 4 Communication

Lecture VI: Distributed Objects. Remote Method Invocation

MTAT Enterprise System Integration. Lecture 2: Middleware & Web Services

EECS 482 Introduction to Operating Systems

CSCD 330 Network Programming Spring 2018

Last Class: Network Overview. Today: Distributed Systems

Distributed Systems. How do regular procedure calls work in programming languages? Problems with sockets RPC. Regular procedure calls

Distributed Information Systems

IBD Intergiciels et Bases de Données

Distributed Systems 8. Remote Procedure Calls

Networked Systems and Services, Fall 2018 Chapter 4. Jussi Kangasharju Markku Kojo Lea Kutvonen

Networks and Operating Systems Chapter 3: Remote Procedure Call (RPC)

Remote Objects and RMI

RPC flow. 4.3 Remote procedure calls IDL. RPC components. Procedure. Program. sum (j,k) int j,k; {return j+k;} i = sum (3,7); Local procedure call

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01

RPCs in Go. COS 418: Distributed Systems Precept 2. Themis Melissaris and Daniel Suo

Distributed Systems. Lec 9: Distributed File Systems NFS, AFS. Slide acks: Dave Andersen

1.264 Lecture 16. Legacy Middleware

Outline. EEC-681/781 Distributed Computing Systems. The OSI Network Architecture. Inter-Process Communications (IPC) Lecture 4

JAVA RMI. Remote Method Invocation

CS153: Communication. Chengyu Song. Slides modified from Harsha Madhyvasta, Nael Abu-Ghazaleh, and Zhiyun Qian

CSCI-1680 RPC and Data Representation John Jannotti

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

Chapter 2 Application Layer

CS162 Operating Systems and Systems Programming Lecture 24. Distributed File Systems. Review: Distributed Applications

COMP 6231: Distributed System Design

CS 5523 Operating Systems: Remote Objects and RMI

Page 1. Goals for Today" Remote Procedure Call" Distributed Systems Message Passing" CS162 Operating Systems and Systems Programming Lecture 23

Distributed Architectures & Microservices. CS 475, Spring 2018 Concurrent & Distributed Systems

Chapter IV INTERPROCESS COMMUNICATION. Jehan-François Pâris

03 Remote invoaction. Request-reply RPC. Coulouris 5 Birrel_Nelson_84.pdf RMI

5 Distributed Objects: The Java Approach

A Report on RMI and RPC Submitted by Sudharshan Reddy B

Lecture 8: February 19

Transcription:

RMI & RPC CS 475, Spring 2019 Concurrent & Distributed Systems

Why expand to distributed systems? Scalability Performance Latency Availability Fault Tolerance Distributed Systems for Fun and Profit, Takada!2

Networks as Abstractions A network consists of communication links Networks have several interesting properties we will look at Latency Failure modes What is the abstraction? Machine 1 Machine 2!3

3 Layer Abstraction The typical network abstraction model has 7 layers Take CS 455 if you want to know more about these We ll think about 3 abstraction layers, and really focus on the top one End-to-End layer Network layer Link layer Handles packet loss, etc. Translates from application-data to packets, implements a protocol Figures out where to send packets Physical links: care about how to deliver packets!4

Today Network abstractions - RMI & RPC Reminders: Midterm HW3 posted Bug in barrier sync slides (now fixed)!5

Abstractions Using sockets directly is annoying - very low level, likely someone else already figured out a way to solve your problem and their fix is bug free High level protocols: FTP, SMTP HTTP (REST, SOAP and other web service stuff) For general purpose, lower level: RPC - Remote Procedure Call, and for Java: RMI - Remote Method Invocation Language agnostic: Google ProtocolBuffers!6

Remote Procedure Calls Example: Address book We ll store our address book on a server But to simplify writing the code, can we pretend that the address book is stored on the client? RPC Client program will think it s directly talking to the server Server program will think it s directly talking to the client In reality, there s a ton of glue in between them!7

Remote Procedure Calls RPC Magic Address Book Client Stub addperson( Prof Bell, ENGR 4422 ); Client Address Book Server Stub addperson( Prof Bell, ENGR 4422 ); Server!8

Remote Procedure Calls Magic is (surprise?) really complicated Challenges in building RPC will re-occur in almost any distributed system What is the alternative? void sendrequest(string name, String office) { Socket clientsocket = new Socket(ADDRESSBOOK_SERVER, ADDRESSBOOK_PORT); DataOutputStream outtoserver = new DataOutputStream(clientSocket.getOutputStream()); BufferedReader infromserver = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); outtoserver.writebytes("addperson" + '\n'); outtoserver.writebytes(name + '\n'); outtoserver.writebytes(office + '\n'); clientsocket.close(); }!9

Why use an abstraction Ugly boilerplate Might have bugs? (Almost definitely) Not portable (string encoding) Hard to understand and maintain Vulnerability-prone!10

What abstraction to use RPC -> use an abstraction all programmers already use E.g. Local Procedure Call (LPC) E.g. just calling functions RPC makes transparent whether server is local or remote RPC allows applications to become distributed transparently RPC makes architecture of remote machine transparent!11

RPC Challenges Calling and called procedures run on different machines, with different address spaces And perhaps different languages, environments, or operating systems Must convert to local representation of data Machines and network can fail!12

RPC: High Level Approach Caller Machine User Code local call Callee Machine User Code local call work local return local return!13

RPC: High Level Approach Caller Machine Callee Machine User Code User Stub RPC Runtime RPC Runtime User Stub User Code local call pack args transmit receive unpack args local call wait work local return unpack return receive transmit pack return local return!14

RPC Stubs Compiler automatically generates these Client stub Marshals arguments into machine-independent format Sends request to server Waits for response Unmarshals result and returns to caller Server stub Unmarshals arguments and builds stack frame Calls procedure Server stub marshals results and sends reply!15

Marshalling and Unmarshalling How did we decide to send the data? How did we decide to encode the data? This is marshalling (done poorly) void sendrequest(string name, String office) { Socket clientsocket = new Socket(ADDRESSBOOK_SERVER, ADDRESSBOOK_PORT); DataOutputStream outtoserver = new DataOutputStream(clientSocket.getOutputStream()); BufferedReader infromserver = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); outtoserver.writebytes("addperson" + '\n'); outtoserver.writebytes(name + '\n'); outtoserver.writebytes(office + '\n'); clientsocket.close(); }!16

RPC Stubs How does the compiler know what to generate? Usually there is a formal spec of the calling interface "Interface Definition Language" Java: Just any old Interface Other RPC systems: specified in a small language similarly (including XML)!17

RPC: The Good Stuff Hides networking details Hides marshaling details Lets you evolve the protocol separately from the communication path Easy to add extra shared features Authentication Naming/location!18

RPC: The Bad Stuff Latency Pointer transfers Failures!19

Local Procedure Call - Failures Local code calls addperson What can happen? LPC returns (OK, can see return value/error code) LPC doesn t return (OK, know it s still running) lpccallingfunction addperson!20

Shared Fate Two methods/threads/processes running on the same computer generally have shared fate They will either both crash, or neither will crash!21

RPC Failures If our client makes an RPC request, but hasn t heard back yet, how do we know what happened? RPC Magic Address Book Client Stub addperson( Prof Bell, ENGR 4422 ); Client!22

RPC Failures If we haven't heard back from the server yet, possibilities are: Server never received request Server received request and crashed Server received request, processed it, crashed Server received requested, processed it, sent response but never received it!23

Split Brain When two machines in a distributed system can t talk to each other, they might start believing different things Two sides can not reconcile view of world because they can t talk to each other We call this a split brain problem!24

Split Brain in RPC Times out, assumes server crashed RPC Magic Address Book Client Stub addperson( Prof Bell, ENGR 4422 ); Client Address Book Server Stub addperson( Prof Bell, ENGR 4422 ); Server Split brain: Client thinks addperson didn t succeed, server did complete it though!!25

Split Brain in RPC This gets even worse when you consider more complicated semantics RPC Magic Lock Client Stub lockkey Client Lock Server Stub lockkey Server Who has the lock?!26

RPC Semantics No matter what we do, if we want RPC, we have networks, networks might have timeouts/failures How do we handle the potential for split brain? If we don't hear a response, just freeze? What can the abstraction guarantee? Leak some of this complexity through!27

RPC Semantics: Exactly once delivery Can our RPC abstraction guarantee call is sent and processed exactly once? In general, not possible: Server can crash at any point Never will know exactly what happened!28

RPC Semantics: At least once RPC system might guarantee at least once delivery Client library keeps track of unconfirmed messages If message is not confirmed, keep re-sending Works fine for idempotent requests (requests that can be repeated with no side effect)!29

RPC Semantics: At most once RPC system might guarantee at most once delivery Client library re-sends if it doesn t hear an ACK Client library adds message IDs Server library keeps track of received message IDs Problems? Server needs to perpetually track received IDs!30

RPC - Implementation Issues Performance is the usual issue: When do you generate the stubs? How do you patch in the stubs? What data is copied from client to server? Environmental concerns: What if client/server are very different (OS/language)?!31

Java RMI Synchronous (client method doesn t return until server completes) At most once delivery Hence, in the event of a communication failure, an exception is thrown on your client Implications: Client code needs to be aware that failures might happen (and exception might be thrown) Client code needs to have some plan to handle when a message fails to get through (application specific)!32

Java RMI Threading model: What happens when there are multiple simultaneous RMI requests to the same server? RMI creates a thread pool, a set of threads ready to handle each request Subsequent calls from the same client might or might not use the same thread Subsequent calls from other clients might use the same thread as others Implications: Can process multiple requests simultaneously Need to be cognizant of thread safety!33

Java RMI public interface AddressBook extends Remote { public LinkedList<Person> getaddressbook() throws RemoteException; } public void addperson(person p) throws RemoteException; AddressBook book = new AddressBookServer(); AddressBook stub = (AddressBook) UnicastRemoteObject.exportObject(book, 0); Registry registry = LocateRegistry.createRegistry(port); registry.rebind("addressbook", stub); Registry registry = LocateRegistry.getRegistry("localhost", 9000); AddressBook addressbook = (AddressBook) registry.lookup("addressbook");!34

Java RMI Registration of a server makes it possible for a client to locate the server and bind to it Server location is done in two steps: Locate the server s machine. Locate the server on that machine.!35

Split Brain in RPC This gets even worse when you consider more complicated semantics RPC Magic Lock Client Stub lockkey Client Lock Server Stub lockkey Server Who has the lock? How do we handle this?!36

Split Brain in RPC This gets even worse when you consider more complicated semantics RPC Magic Lock Client Stub unlockkey Client Lock Server Stub unlockkey Server Who has the lock? How do we handle this?!37

Sidebar: Heartbeat Protocols Allow client/server to remain aware of each other s status For HW3: does client still have locks (client checking server, server checking client) Client lock( foo ) Server OK, stamp = 1 Hi, I m stamp 1, still have foo CRASH! Hmm, I guess server is gone, maybe lock is not valid!38

Sidebar: Heartbeat Protocols Allow client/server to remain aware of each other s status For HW3: does client still have locks (client checking server, server checking client) Client lock( foo ) Server OK, stamp = 1 Hi, I m stamp 1, still have foo CRASH! OK Hmm, I guess foo is no longer locked!39

Sidebar: Heartbeat Protocols We call these time-limited locks leases What does a lease guarantee? If no network failures Locks that are relinquished when client crashes If network failures/delays: Nothing!40

RPC Summary 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!41

Summary 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!42

This work is licensed under a Creative Commons Attribution- ShareAlike license This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/ You are free to: Share copy and redistribute the material in any medium or format Adapt remix, transform, and build upon the material for any purpose, even commercially. Under the following terms: Attribution You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. ShareAlike If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original. No additional restrictions You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.!43