Distributed Systems. Lec 4: Remote Procedure Calls (RPC)

Similar documents
Distributed Systems [Fall 2013]

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

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

REMOTE PROCEDURE CALLS EE324

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

416 Distributed Systems. RPC Day 2 Jan 12, 2018

416 Distributed Systems. RPC Day 2 Jan 11, 2017

Remote Procedure Calls

416 Distributed Systems. Networks review; Day 2 of 2 And start of RPC Jan 13, 2016

416 Distributed Systems. Networks review; Day 2 of 2 Fate sharing, e2e principle And start of RPC Jan 10, 2018

Distributed Systems 8. Remote Procedure Calls

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

struct foomsg { u_int32_t len; }

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

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

Network Communication and Remote Procedure Calls

Distributed Systems. Big Topic: Synchronization. Lec 6: Local Synchronization Primitives. Slide acks: Jinyang Li, Dave Andersen, Randy Bryant

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

Remote Procedure Call (RPC) and Transparency

Communication in Distributed Systems

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

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

CSci Introduction to Distributed Systems. Communication: RPC

CS 138: Communication II

Remote Procedure Call

Remote Procedure Calls (RPC)

Lecture 8: February 19

Communication. Distributed Systems Santa Clara University 2016

Distributed Systems. 03. Remote Procedure Calls. Paul Krzyzanowski. Rutgers University. Fall 2017

Distributed systems. Programming with threads

CHAPTER - 4 REMOTE COMMUNICATION

CS 417 9/18/17. Paul Krzyzanowski 1. Socket-based communication. Distributed Systems 03. Remote Procedure Calls. Sample SMTP Interaction

CSCI-1680 RPC and Data Representation. Rodrigo Fonseca

Outline. Interprocess Communication. Interprocess Communication. Communication Models: Message Passing and shared Memory.

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

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

Project 2: Part 1: RPC and Locks

Overview. Communication types and role of Middleware Remote Procedure Call (RPC) Message Oriented Communication Multicasting 2/36

Last Time. Internet in a Day Day 2 of 1. Today: TCP and Apps

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

COS 318: Operating Systems. Message Passing. Kai Li and Andy Bavier Computer Science Department Princeton University

COMMUNICATION IN DISTRIBUTED SYSTEMS

MODELS OF DISTRIBUTED SYSTEMS

CS 326: Operating Systems. Networking. Lecture 17

Lecture 8: February 17

Network File System (NFS)

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

Remote Procedure Call. Tom Anderson

Advanced Distributed Systems

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

Last Class: RPCs. Today:

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

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

DISTRIBUTED FILE SYSTEMS & NFS

RMI: Design & Implementation

CSCI-1680 RPC and Data Representation John Jannotti

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

ECE 650 Systems Programming & Engineering. Spring 2018

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

Announcements. P4: Graded Will resolve all Project grading issues this week P5: File Systems

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

MODELS OF DISTRIBUTED SYSTEMS

Lecture 5: Object Interaction: RMI and RPC

416 Distributed Systems. Distributed File Systems 1: NFS Sep 18, 2018

CSMC 412. Computer Networks Prof. Ashok K Agrawala Ashok Agrawala Set 2. September 15 CMSC417 Set 2 1

A Report on RMI and RPC Submitted by Sudharshan Reddy B

CS454/654 Midterm Exam Fall 2004

Consistency. CS 475, Spring 2018 Concurrent & Distributed Systems

Networks and distributed computing

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

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

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 21: Network Protocols (and 2 Phase Commit)

Dr. Robert N. M. Watson

Networked Applications: Sockets. End System: Computer on the Net

Computer Networks Prof. Ashok K. Agrawala

6.824 Distributed System Engineering: Spring Quiz I Solutions

CS603: Distributed Systems

Lecture 15: Network File Systems

Internetworking Models The OSI Reference Model

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

CSCI-1680 RPC and Data Representation. Rodrigo Fonseca

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

ECE 435 Network Engineering Lecture 10

Socket Programming. #In the name of Allah. Computer Engineering Department Sharif University of Technology CE443- Computer Networks

DISTRIBUTED COMPUTER SYSTEMS

Map-Reduce. Marco Mura 2010 March, 31th

Consistency: Relaxed. SWE 622, Spring 2017 Distributed Software Engineering

Interprocess Communication

Distributed Systems. Lec 10: Distributed File Systems GFS. Slide acks: Sanjay Ghemawat, Howard Gobioff, and Shun-Tak Leung

Networked Applications: Sockets. Goals of Todayʼs Lecture. End System: Computer on the ʻNet. Client-server paradigm End systems Clients and servers

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

416 Distributed Systems. Distributed File Systems 2 Jan 20, 2016

Distributed Systems Principles and Paradigms. Chapter 04: Communication

Socket Programming for TCP and UDP

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

Distributed File Systems

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 20: Networks and Distributed Systems

Remote Procedure Calls CS 707

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

NFS Design Goals. Network File System - NFS

Transcription:

Distributed Systems Lec 4: Remote Procedure Calls (RPC) Slide acks: Dave Andersen, Jinyang Li (http://www.cs.cmu.edu/~dga/15-440/f10/lectures/05-rpc.pdf, http://www.news.cs.nyu.edu/~jinyang/fa10/notes/ds-lec2.ppt) 1

HW 2 has been released Due in two weeks Much longer than HW1! And it'll be GRADED! So start very early News TA will give background now 2

YFS Lab Series Background 3

YFS Instructional distributed file system developed by MIT after a research distributed file system, called Frangipani Analogous to xv6 for OS courses When we discuss YFS, we really refer to Frangipani (or a simplified version thereof) Thekkath, Chandramohan A., Timothy Mann, and Edward K. Lee. "Frangipani: A scalable distributed file system." ACM SIGOPS Operating Systems Review. Vol. 31. No. 5. ACM, 1997.

YFS Design Goals Aggregate many disks from many servers Incrementally scalable Tolerates and recovers from node, network, disk failures

Design

Lock Service Resolve concurrent read/write issues If one client is writing to a file while another client is reading it, inconsistency appears. Lock server grants/releases locks to client upon request Becomes scalable with more instances All the actual data are provided by the extent server

Some Specific Questions I How to make a file system in user space? We need to build a real file system that can be mounted. How? Use FUSE library ( http://fuse.sourceforge.net/) We will provide you with skeleton code You are responsible for filling in the actual function implementations.

Some Specific Questions II How do nodes communicate with each other? Use the in-house RPC library No more low-level socket programming! It has drawbacks though, next homework will ask you to fix it. How do I store the actual data? The data does not need to be persistent. Store them in memory is OK.

Lab Schedule Lab 1: C++ warm up (Passed) Lab 2: Lock server and reliable RPC Lab 3: File server Lab 4: Cache Locks Lab 5: Paxos Lab 6: Replicated lock server

Lab 2: Lock Server and Reliable RPC Centralized lock server Lock service consists of: Lock server: grant a lock to clients, one at a time Lock client: talk to server to acquire/release locks Correctness: At most one lock is granted to any client Additional requirement: acquire() at client returns only once lock is granted

Lab 2 Steps Step 1: Checkout the skeleton code from git Step 2: Implement server lock and client lock Test it using locker_tester Step 3: Implement RPC at-most-once semantics Use a sliding window to store the sent RPC ids.

Today's Lecture 13

Local OS Concepts Processes: A resource container for execution on a single machine Threads: One thread of execution through code. Can have multiple threads per process. Why processes? Why threads? Why either? Local communication Inter-process communication Thread synchronization 14

Distributed Concepts Distributed processes Processes that run on different machines separated by a network They can be multithreaded or singlethreaded In this class, we will generally treat one thread as an independent process Distributed communication Multiple models Today we'll introduce these models and focus on socket communication and remote procedure calls (RPCs) 15

Common Communication Pattern Client Hey, do something Server working { Done/Result time

Other Communication Patterns Broadcast Node 1 Node 2 Node 3 bcast medium Multicast Node 1 Node 2 Node 3 mcast medium Broadcaster Source Publisher 1 Publisher 2 Publish/Subscribe Subscriber 1 Subscriber 2 Subscriber 3 What's this?

Other Communication Patterns Broadcast Node 1 Node 2 Node 3 bcast medium Multicast Node 1 Node 2 Node 3 mcast medium Broadcaster Source Publisher 1 Publisher 2 Publish/Subscribe Subscriber 1 Subscriber 2 Subscriber 3 Map/Reduce (roughly)

Communication Mechanisms Many possibilities and protocols for communicating in a distributed system Sockets (mostly in HW1) RPC (today) Distributed shared memory (later classes) Map/Reduce (later classes) MPI (on your own) 19

Socket Communication You write your own protocol on top of a transmission protocol (e.g., TCP or UDP) Quiz from your networking course : What s TCP? What s UDP? When is it best to use TCP vs. UDP? 20

Socket Communication TCP (Transmission Control Protocol) Protocol built upon the IP networking protocol, which supports sequenced, reliable, two-way transmission over a connection (or session, stream) between two sockets UDP (User Datagram Protocol) Also protocol built on top of IP. Supports best-effort, transmission of single datagrams Use: TCP when you need reliability, or when latency overheads are comparatively small (e.g., file transmission, a lock service) UDP when it s OK to lose, re-order, or duplicate messages, but you want low latency (e.g., online games, messaging, games) 21

POSIX Socket API Overview Client Server socket socket int socket(domain, type, protocol) connect(client_sock, &server_addr, server_len) Client / Server Session connect write read Connection request bind listen accept read write bind(server_sock, &server_address, server_len) listen(server_sock, backlog) accept(server_sock, &client_addr, &client_len) close EOF read close

Complexities of Using the Socket API Lots of boiler-plate when using a raw socket API Lots of bugs/inefficiencies if you re not careful E.g.: retransmissions, multi-threading, Plus, you have to invent the data transmission protocol Can be complex Hard to maintain May not interact well with others protocols 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); } 23

RPC A type of client/server communication Attempts to make remote procedure calls look like local ones Client: {... resp = foo( hello ); } Server: int foo(char* arg) { }

RPC Goals Ease of programming Familiar model for programmers (just make a function call) Hide complexity (or some of it we ll see later) Automate a lot of implementation tasks Standardize some low-level data packaging protocols across components Historical note: Seems obvious in retrospect, but RPC was only invented in the 80s. See Birrell & Nelson, Implementing Remote Procedure Call... or Bruce Nelson, Ph.D. Thesis, Carnegie Mellon University: Remote Procedure Call., 1981 :)

RPC Architecture Overview Servers export APIs containing local procedures On client, RPC library generates RPC requests over network to server On server, called procedure executes, result is returned in RPC response to client Client: { Back on client, RPC library... reconstructs the response and } returns it to the caller resp = foo( hello ); Server: int foo(char* arg) { }

RPC Architecture App Client rpc call RPC client library marshal args send RPC request RPC server library receive unmarshal args App Server rpc handler wait work rpc call return unmarshal result receive RPC response send marshal result rpc handler return Client: {... resp = foo( hello ); } Server: int foo(char* arg) { }

Why Marshaling? Calling and called procedures run on different machines, with different address spaces Therefore, pointers are meaningless Plus, perhaps different environments, different operating systems, different machine organizations, E.g.: the endian problem: If I send a request to transfer $1 from my little-endian machine, the server might try to transfer $16M if it s a big-endian machine Must convert to local representation of data (structs, strings, etc.) That s what marshaling does for you

Marshaling and Unmarshaling htonl() -- host to network-byte-order, long network-byte-order (big-endian) standardized to deal with cross-platform variance

Marshaling and Unmarshaling htonl() -- host to network-byte-order, long network-byte-order (big-endian) standardized to deal with cross-platform variance In our foomsg example, remember how we decided to send the string by sending its length followed by len bytes of the string? That s manual marshaling. 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); }

Marshaling and Unmarshaling htonl() -- host to network-byte-order, long network-byte-order (big-endian) standardized to deal with cross-platform variance In our foomsg example, remember how we decided to send the string by sending its length followed by len bytes of the string? That s manual marshaling. Other things to marshal: Floating point Nested structures Complex data structures? (Some RPC systems let you send lists and maps as first-order objects)

Stubs and IDLs RPC stubs are automatically generated pieces of code that appear to implement the desired functions, but actually do just call the RPC library to marshal/unmarshal and transmission How does this stub generation work? Typically: Write a description of the function signature using an interface definition language (IDL), then the RPC library compiler produces stub Lots of these. Some look like C, some like XML Example: SunRPC (now), next time we ll look at other IDLs (e.g., Google s protocol buffers)

SunRPC Venerable, widely-used RPC system Defines XDR ( external Data Representation ) -- C-like language for describing structures and functions -- and provides a compiler that creates stubs struct fooargs { string msg<255>; int baz; }

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

Other features 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 management)

Limitations What happens during communication failures? Programmer code still has to deal with exceptions! In the local procedure case, calling foo() to add 5 + 5 can t fail and doesn t take 10 seconds to return Machine failures? Did server fail before/after processing request?? Impossible to tell, if it s still down... It s impossible to hide all complexity under an RPC system and make it look like a local procedure call! But marshaling/unmarshaling support is great

Key challenges of RPC RPC semantics in the face of Communication failures delayed and lost messages connection resets expected packets never arrive Machine failures Server or client failures Did server fail before or after processing the request? Might be impossible to tell communication failures from machine failures This is in fact a fundamental problem in distributed systems

Example failures Request from cli -> srv lost Reply from srv -> cli lost Server crashes after receiving request Before it has completed it or After it has completed it Client crashes after sending request He won t know whether the server executed the request

At-least-once semantics Keep retrying... RPC semantics At-most-once semantics Use a sequence # to recognize duplicates upon retransmissions Remember that at the server Then keep retrying... When is one suitable compared to the other?

At-least-once versus at-most-once? (for your own reading) let's take an example: acquiring a lock if client and server stay up, client receives lock if client fails, it may have the lock or not (server needs a plan!) if server fails, client may have lock or not at-least-once: client keeps trying at-most-once: client will receive an exception what does a client do in the case of an exception? need to implement some application-specific protocol ask server, do i have the lock? server needs to have a plan for remembering state across reboots e.g., store locks on disk. at-least-once (if we never give up) clients keep trying. server may run procedure several times server must use application state to handle duplicates if requests are not idempotent but difficult to make all request idempotent e.g., server good store on disk who has lock and req id check table for each requst even if server fails and reboots, we get correct semantics What is right? depends where RPC is used. simple applications: at-most-once is cool (more like procedure calls) more sophisticated applications: need an application-level plan in both cases not clear at-once gives you a leg up => Handling machine failures makes RPC different than procedure calls comparison from Kaashoek, 6.842 notes

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 remember anything. 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 infinite memory. Real: Keep sliding window of valid RPC IDs, have client number them sequentially.

Exactly-Once? Sorry - no can do in general. Imagine that message triggers an external physical thing (say, a robot fires a nerf dart at the professor) The robot could crash immediately before or after firing and lose its state. Don t know which one happened. Can, however, make this window very small.

Implementation Concerns 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 machines

Next Time A bunch of RPC library examples With code! 44