Lecture 3: Sockets, Remote Procedure Calls. EECE 411: Design of Distributed Software Applications Last time: Pitfalls when developing distributed systems.

Slides:



Advertisements
Similar presentations
1 Communication in Distributed Systems REKs adaptation of Tanenbaums Distributed Systems Chapter 2.
Advertisements

RPC Robert Grimm New York University Remote Procedure Calls.
Remote Procedure Call (RPC)
Remote Procedure Call Design issues Implementation RPC programming
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Tam Vu Remote Procedure Call CISC 879 – Spring 03 Tam Vu March 06, 03.
Remote Procedure CallCS-4513, D-Term Remote Procedure Call CS-4513 Distributed Computing Systems (Slides include materials from Operating System.
Distributed Systems Lecture #3: Remote Communication.
Tutorials 2 A programmer can use two approaches when designing a distributed application. Describe what are they? Communication-Oriented Design Begin with.
Remote Procedure Call Chin-Chih Chang. Remote Procedure Call Remote Procedure Call (RPC) is a protocol that allows programs to call procedures located.
Outcomes What is RPC? The difference between conventional procedure call and RPC? Understand the function of client and server stubs How many steps could.
EECE 411: Design of Distributed Software Applications What is a Distributed System? You know when you have one … … when the failure of a computer you’ve.
EEC-681/781 Distributed Computing Systems Lecture 4 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University
.NET Mobile Application Development Remote Procedure Call.
Lecture 8 Epidemic communication, Server implementation.
An adapted reference model for networked communication.
Communication. Asynchronous RPC (1) a)The interconnection between client and server in a traditional RPC b)The interaction using asynchronous RPC 2-12.
TCP/IP Sockets in Java: Practical Guide for Programmers Kenneth L. Calvert Michael J. Donahoo.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
1 Chapter 2. Communication. STEM-PNU 2 Layered Protocol TCP/IP : de facto standard Our Major Concern Not always 7-layered Protocol But some other protocols.
Communication Tran, Van Hoai Department of Systems & Networking Faculty of Computer Science & Engineering HCMC University of Technology.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
Introduction to Distributed Systems Slides for CSCI 3171 Lectures E. W. Grundke.
Lecture 3: OSI Stack, Sockets, Protocols. EECE 411: Design of Distributed Software Applications Academic honesty is essential to the continued functioning.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
3.1 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8 th Edition Chapter 3: Processes.
 Remote Procedure Call (RPC) is a high-level model for client-sever communication.  It provides the programmers with a familiar mechanism for building.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved RPC Tanenbaum.
Lecture 4-5-6: Remote Procedure Calls. EECE 411: Design of Distributed Software Applications Academic honesty is essential to the continued functioning.
CSE 451: Operating Systems Winter 2015 Module 22 Remote Procedure Call (RPC) Mark Zbikowski Allen Center 476 © 2013 Gribble, Lazowska,
Page 1 Remote Procedure Calls Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation.
Remote Procedure CallCS-502 Fall Remote Procedure Call (continued) CS-502, Operating Systems Fall 2007 (Slides include materials from Operating System.
Distributed Computing Systems
Remote Procedure Call Andy Wang Operating Systems COP 4610 / CGS 5765.
Remote Procedure Call RPC
Mark Stanovich Operating Systems COP Primitives to Build Distributed Applications send and receive Used to synchronize cooperating processes running.
Computer Science Lecture 3, page 1 CS677: Distributed OS Last Class: Communication in Distributed Systems Structured or unstructured? Addressing? Blocking/non-blocking?
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
Implementing Remote Procedure Call Landon Cox February 12, 2016.
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
© Oxford University Press 2011 DISTRIBUTED COMPUTING Sunita Mahajan Sunita Mahajan, Principal, Institute of Computer Science, MET League of Colleges, Mumbai.
Distributed Computing & Embedded Systems Chapter 4: Remote Method Invocation Dr. Umair Ali Khan.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Lecture 5: RPC (exercises/questions). 26-Jun-16COMP28112 Lecture 52 First Six Steps of RPC TvS: Figure 4-7.
03 – Remote invoaction Request-reply RPC RMI Coulouris 5
Prof. Leonardo Mostarda University of Camerino
Remote Procedure Call present by :Enas Alkhoshi
Distributed Systems CS
CMSC621: Advanced Operating Systems Advanced Operating Systems
CSE 451: Operating Systems Winter 2006 Module 20 Remote Procedure Call (RPC) Ed Lazowska Allen Center
Lecture 4: RPC Remote Procedure Call Coulouris et al: Chapter 5
Sarah Diesburg Operating Systems COP 4610
CSE 451: Operating Systems Autumn 2003 Lecture 16 RPC
CSE 451: Operating Systems Winter 2007 Module 20 Remote Procedure Call (RPC) Ed Lazowska Allen Center
Lecture 4: RPC Remote Procedure Call CDK: Chapter 5
CSE 451: Operating Systems Winter 2004 Module 19 Remote Procedure Call (RPC) Ed Lazowska Allen Center
CSE 451: Operating Systems Spring 2012 Module 22 Remote Procedure Call (RPC) Ed Lazowska Allen Center
CSE 451: Operating Systems Autumn 2009 Module 21 Remote Procedure Call (RPC) Ed Lazowska Allen Center
Lecture 6: RPC (exercises/questions)
Distributed Systems CS
CSE 451: Operating Systems Autumn 2010 Module 21 Remote Procedure Call (RPC) Ed Lazowska Allen Center
Lecture 6: RPC (exercises/questions)
Lecture 7: RPC (exercises/questions)
CSE 451: Operating Systems Winter 2003 Lecture 16 RPC
TCP/IP Sockets in Java: Practical Guide for Programmers
Last Class: Communication in Distributed Systems
CSE 451: Operating Systems Messaging and Remote Procedure Call (RPC)
Distributed Systems CS
Presentation transcript:

Lecture 3: Sockets, Remote Procedure Calls

EECE 411: Design of Distributed Software Applications Last time: Pitfalls when developing distributed systems The network is reliable Latency is zero Bandwidth is infinite Transport cost is zero The network is secure The topology does not change There is one administrator The network is homogeneous [aka Peter Deutsch’s “8 fallacies”]

EECE 411: Design of Distributed Software Applications Last time: Architectural Styles for Distributed Applications

EECE 411: Design of Distributed Software Applications Summary so far: Definition of distributed systems collection of independent components that appears to its users as a single coherent system Goals, pitfalls, scalability techniques, architecture styles Requirement: Components need to communicate  Shared memory  Message exchange  need to agree on many things  Protocols: data formats, exception handling, naming, …

EECE 411: Design of Distributed Software Applications Types of communication protocols: Persistence and Synchronicity Synchronicity: Does the sender wait for a reply or acknowledgement? Yes  synchronous communication No  asynchronous communication Persistence: Do the sender and the receiver have to be both online for the message exchange to happen? No  persistent communication Yes  non-persistent communication

EECE 411: Design of Distributed Software Applications Persistence and Synchronicity … (II) Persistent communication of letters back in the days of the Pony Express. Asynchronous, Persistent

EECE 411: Design of Distributed Software Applications Persistence and Synchronicity … (III) Persistent asynchronous communication Persistent synchronous communication

EECE 411: Design of Distributed Software Applications Persistence and Synchronicity … (IV) Transient asynchronous communication Receipt-based transient synchronous communication

EECE 411: Design of Distributed Software Applications Getting more hands on Crash course on socket programming

EECE 411: Design of Distributed Software Applications Socket-programming using TCP Socket: a ‘ door ’ between an application process and an end-end-transport protocol (UCP or TCP) TCP: reliable transfer of bytes from one process to another process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server internet

EECE 411: Design of Distributed Software Applications Socket programming [with TCP] Client must contact server server process must first be running server must have created socket (door) that welcomes client ’ s contact Client contacts server by: creating client-local TCP socket specifying IP address, port number of server process client establishes connection to server TCP When contacted by client, server TCP creates new socket for server process to communicate with client allows server to talk with multiple clients source port numbers used to distinguish clients TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server application viewpoint

EECE 411: Design of Distributed Software Applications State machine PrimitiveMeaning SocketCreate a new communication endpoint BindAttach a local address to a socket ListenAnnounce willingness to accept connections AcceptBlock caller until a connection request arrives ConnectActively attempt to establish a connection SendSend some data over the connection ReceiveReceive some data over the connection CloseRelease the connection

EECE 411: Design of Distributed Software Applications public class TCPEchoClient { public static void main(String[] args) throws IOException { String server = args[0]; // Server name or IP address byte[] byteBuffer = args[1].getBytes(); int servPort = (args.length == 3) ? Integer.parseInt(args[2]) : 7; // Create socket that is connected to server on specified port Socket socket = new Socket(server, servPort); System.out.println("Connected to server...sending echo string"); InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); out.write(byteBuffer); // Send the encoded string to the server // Receive the same string back from the server int totalBytesRcvd = 0; // Total bytes received so far int bytesRcvd; // Bytes received in last read while (totalBytesRcvd < byteBuffer.length) { if ((bytesRcvd = in.read(byteBuffer, totalBytesRcvd, byteBuffer.length - totalBytesRcvd)) == -1) throw new SocketException("Connection close prematurely"); totalBytesRcvd += bytesRcvd; } socket.close(); // Close the socket and its streams } Example: echo – client

EECE 411: Design of Distributed Software Applications Example: echo – server public class TCPEchoServer { private static final int BUFSIZE = 32; // Size of receive buffer public static void main(String[] args) throws IOException { int servPort = Integer.parseInt(args[0]); // Create a server socket to accept client connection requests ServerSocket servSock = new ServerSocket(servPort); int recvMsgSize; // Size of received message byte[] byteBuffer = new byte[BUFSIZE]; // Receive buffer for (;;) { // Run forever, accepting and servicing connections Socket clntSock = servSock.accept(); // Get client connection System.out.println("Handling client at " + clntSock.getInetAddress().getHostAddress()); InputStream in = clntSock.getInputStream(); OutputStream out = clntSock.getOutputStream(); // Receive until client closes connection, indicated by -1 return while ((recvMsgSize = in.read(byteBuffer)) != -1) out.write(byteBuffer, 0, recvMsgSize); clntSock.close(); // Close the socket. We are done with this client! }

EECE 411: Design of Distributed Software Applications First assignment Client for “encoding server”. Protocol Client sends: four byte integer (your student ID) Server replies with message containing Length of useful code (four bytes) ‘Secret’ unique encoding of your ID (as a set of bytes to be converted to a string) Padding (junk) Closes connection Submit individually: Your client The ‘secret’ encoding you’ve got by successfully running your client

Remote Procedure Calls

EECE 411: Design of Distributed Software Applications Building Distributed Applications: Two Paradigms Communication oriented design Start with communication protocol; Design message format and syntax Design components (clients, servers) by specifying how they react to incoming messages Problems Protocol design problems Specify components as finite state machines Focus on communication instead of on application RPC offers support here! Application-oriented design Start with application Design, build, test conventional (single-box) application Partition program Problems Preserving semantics when using partitioning program (using remote resources) Masking failures Concurrency

EECE 411: Design of Distributed Software Applications Building distributed applications RPC goal: minimize the difference between a single box and a distributed deployment environment Observations: Application developers are familiar with simple procedure model Well-engineered procedures operate in isolation (black box) There are few reasons not to execute procedures on separate machines Idea: communication between caller & callee can be hidden by using procedure-call mechanism. (local program calls procedures hosted remotely in a similar way to local procedures)

EECE 411: Design of Distributed Software Applications Remote Procedure Calls (RPC) Idea: local program calls procedures hosted remotely in a similar way to local procedures Information is passed in procedure arguments, results Problem: Provide transparency Mask difference in data representation Handle failures Different address spaces Security (?)

EECE 411: Design of Distributed Software Applications Outline Mechanics. How does it actually work … … and limitations RPC in practice. Case study: The Network File System Discussion: Reliable RPC Asynchronous RPC

EECE 411: Design of Distributed Software Applications Conventional (local) Procedure Call count = read(fd, buf, bytes) Parameter passing in a local procedure call – the stack before & after the call

EECE 411: Design of Distributed Software Applications Passing Value Parameters Steps involved in doing remote computation through RPC 2-8

EECE 411: Design of Distributed Software Applications Parameter passing - Parameter marshaling More than just wrapping parameters into a message: Client and server machines may have different data representations (think of byte ordering) Client and server have to agree on the same encoding: How are basic data values represented (integers, floats, characters) How are complex data values represented (arrays, structures)

EECE 411: Design of Distributed Software Applications Steps of a Remote Procedure Call. Stubs 1. Client procedure calls client stub in normal way 2. Client stub builds message calls local OS 3. Client's OS sends message to remote OS 4. Remote OS gives message to server stub 5. Server stub unpacks parameters, calls server 6. Server does work, returns result to the stub 7. Server stub packs it in message, calls local OS 8. Server's OS sends message to client's OS 9. Client's OS gives message to client stub 10. Stub unpacks result, returns to client

EECE 411: Design of Distributed Software Applications Parameter passing (II): Problems: Pointers and global data What happens with pointers and references to global data? Traditional parameter-passing possibilities: By value Parameter value is copied on the stack and/or sent on the wire By reference Reference/Identifier is passed How does this work for remote calls? Copy in/copy out A copy of the referenced object is copied in/out While procedure is executed, nothing can be assumed about parameter values Do they lead to different results after a procedure call?

EECE 411: Design of Distributed Software Applications Discussion: Pointer and global variable handling An simple example. But things are more complex …..

EECE 411: Design of Distributed Software Applications Outline Mechanics. How does it actually work … … and limitations RPC in practice. Case study: The Network File System Discussion: Reliable RPC Asynchronous RPC

EECE 411: Design of Distributed Software Applications RPC in mechanics practice Objective: Let the developer concentrate on only the client- and server-specific code; let the RPC system (generators and libraries) do the rest. What components does an RPC system consist of? Standards for wire format of RPC msgs and data types. Example: Sun’s XDR Library of routines to marshal / unmarshal data. Stub generator or RPC compiler, to produce "stubs". For client: marshal arguments, call, wait, unmarshal reply. For server: unmarshal arguments, call real fn, marshal reply. Server framework: Dispatch each call message to correct server stub. Client framework: Give each reply to correct waiting thread / callback. Binding mechanisms: how does client find the right server?

EECE 411: Design of Distributed Software Applications RPC in practice: Writing a Client and a Server The steps in writing a client and a server in DCE RPC. 2-14

EECE 411: Design of Distributed Software Applications Practicalities: Binding a Client to a Server Issues: Client must locate the server machine Client must locate the server (port) 2-15

EECE 411: Design of Distributed Software Applications Discussion: Did we achieve transparency? Yes: Hides wire formats and marshal / unmarshal. Hides details of send / receive APIs Hides details of transport protocol (TCP vs. UDP) Hides who the client is. No: Global variables / concurrency Failures