Distributed Programming

Similar documents
Message Passing. Frédéric Haziza Summer Department of Computer Systems Uppsala University

Lecture 5: Message Passing & Other Communication Mechanisms (SR & Java)

G52CON: Concepts of Concurrency Lecture 15: Message Passing. Gabriela Ochoa School of Computer Science & IT

Network Programming. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

URL Kullanımı Get URL

Distributed Programming - Sockets

CS2307 NETWORKS LAB 1. Programs using TCP Sockets (like date and time server & client, echo server & client, etc.) 2. Programs using UDP Sockets

CS September 2017

Internet Technology 2/7/2013

Previous lecture: threads G51PRG: Introduction to Programming Second semester Lecture 12 URL

Networking Basics. network communication.

Chapter 4: Processes

protocols September 15,

Lecture 6. Introduction to Message Passing

CS 351 Design of Large Programs Sockets Example

Socket 101 Excerpt from Network Programming

Message Passing. Lecture 7. Shared Variables? Shared Variables? Synchronisation. Overview of Message Passing

Unit 9: Network Programming

Lecture 3: Socket Programming

CPSC 441 Assignment-3 Discussion. Department of Computer Science University of Calgary

Outlines. Networking in Java. Internet hardware structure. Networking Diagram. IP Address. Networking in Java. Networking basics

Chapter 4: Processes. Process Concept. Process State

COMP 213. Advanced Object-oriented Programming. Lecture 20. Network Programming

CPSC 441 Tutorial TCP Server. Department of Computer Science University of Calgary

Java Networking (sockets)

Introduction to Sockets

Networking: IPv6, UDP and TCP. Network Programming in Java UDP and TCP

CPSC 441 Assignment-3 Discussion. Department of Computer Science University of Calgary

Assignment 2 CISC 650 Computer Networks Fall 2016 Due Date: 10/9/ :59PM ET Total Points: 100

BrickNet (cont d) Other Academic Projects

World Scientific Research Journal (WSRJ) ISSN: The Implementation of Tcp Socket Programming based on Java

Chapter 2 Applications and

Principles of Software Construction. Introduction to networks and distributed systems School of Computer Science

Semaphores. Derived Inference Rules. (R g>0) Q g (g 1) {R} V (g) {Q} R Q g (g+1) V (s), hs := 1; i

Networking Fundamentals

Java Support for developing TCP Network Based Programs

Coupling Thursday, October 21, :23 PM

Network. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

Multi-threaded Web Server (Assignment 1) Georgios Georgiadis

Lab 10: Sockets 12:00 PM, Apr 4, 2018

??? Traceroute. app. app. host. host. Apps talk to other apps with no real idea of what is inside the network

31 Network Programming

Merge Sort Quicksort 9 Abstract Windowing Toolkit & Swing Abstract Windowing Toolkit (AWT) vs. Swing AWT GUI Components Layout Managers Swing GUI

Distributed Systems Recitation 2. Tamim Jabban

Chapter 4: Processes. Process Concept

M257 Past Paper Oct 2007 Attempted Solution

CSCD 330 Network Programming Winter 2019

Outlook. Process Concept Process Scheduling Operations on Processes. IPC Examples

Chapter 4: Processes

Aggregation. Chapter 8. Java By Abstraction Chapter 8. Outline. 8.1 What is Aggregation? Copyright 2006 Pearson Education Canada Inc.

Lecture 11.1 I/O Streams

Process. Program Vs. process. During execution, the process may be in one of the following states

CONCURRENCY IN JAVA Course Parallel Computing

CSCD 330 Network Programming Spring 2018

Lecture 2 Process Management

CSE 486/586 Distributed Systems

IT101. File Input and Output

CSE 461 Module 11. Connections

CS 251 Intermediate Programming Java I/O Streams

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

Homework # 7 Distributed Computing due Saturday, December 13th, 2:00 PM

Network Programming Benoît Garbinato

Communication Paradigms

Interprocess Communication

Process management. Desarrollo de Aplicaciones en Red. Process in memory. Concepts. Process state diagram. Process state

Java Time Machine. Wang Yang

Protocols SPL/ SPL

Java Development: Do s and Don ts

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Course Content. Objectives of Lecture 22 File Input/Output. Outline of Lecture 22. CMPUT 102: File Input/Output Dr. Osmar R.

Threads and Parallelism in Java

Web Server Project. Tom Kelliher, CS points, due May 4, 2011

Multitasking / Multithreading system Supports multiple tasks

TCP and Concurrency. The third assignment at DA

Threads CS1372. Lecture 13. CS1372 Threads Fall / 10

PIC 20A Streams and I/O

CHAPTER 6: PROCESS SYNCHRONIZATION

Disruptor Using High Performance, Low Latency Technology in the CERN Control System

Performance Throughput Utilization of system resources

Distributed Systems. coordination Johan Montelius ID2201. Distributed Systems ID2201

Implementation of Process Networks in Java

What HTTP is : it forms elements (.html..xml) with programs (processes) running on the server (e.g. java) and on clients (e.g. javascript), cookies).

Multiple Inheritance. Computer object can be viewed as

CPSC 441 UDP Socket Programming. Department of Computer Science University of Calgary

CSCD 330 Network Programming Spring 2018

Page 1. Analogy: Problems: Operating Systems Lecture 7. Operating Systems Lecture 7

CSCD 330 Network Programming

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Reading from URL. Intent - open URL get an input stream on the connection, and read from the input stream.

09-1. CSE 143 Java GREAT IDEAS IN COMPUTER SCIENCE. Overview. Data Representation. Representation of Primitive Java Types. Input and Output.

CSCD 330 Network Programming

SE 552: Lecture 9. Overview. Asynchronous method calls. Worker pools. Timers. Event loops. Polling IO

Chapter 13: I/O Systems

Chapter 13: I/O Systems

About this exam review

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

CSCD 330 Network Programming

CS 160: Interactive Programming

BSc ( Hons) Computer Science with Network Security. Examinations for / Semester 2

Module 12: I/O Systems

Transcription:

Distributed Programming Processes don t share memory. Processes share channels over which messages are passed Channels may be Global, receiver specific, or sender & receiver specific. One or two way. c 2003,2005 Typeset February 27, 2009 1

Distributed Paradigms Filter Data translator Read input stream, write to output stream. Client Active (triggering) process Request service, often wait for response. Server Reactive process Wait for request, respond. Peer Cooperating process.jjjjjjj c 2003,2005 Typeset February 27, 2009 2

Asynchronous Message Passing chan c(type1 v1, type2 v2...); send c(x1, x2...); receive c(y1, y2...); empty(c) Channels are considered unbounded FIFO queues Non-blocking send. Blocking receive. send and receive generalize V and P by adding data. Since receive is the only blocking call, deadlock can only occur there. Translation: send c(d) = hc := concatenate(c, [d])i receive c(d) = hawait( empty(c)) d, c := head(c), tail(c)i c 2003,2005 Typeset February 27, 2009 3

Filter: Mergesort Problem: Sort a list of values Solution: Network filters in a tree structure process Merge { int v1, v2; receive in1(v1); receive in2(v2); while (!(v1==eosand v2==eos)){ if (v2 == EOS or v1!= EOS and v1 <= v2){ send out(v1); receive in1(v1); } else{##v1==eosor v2!= EOS and v2 < v1 send out(v2); receive in2(v2); } } send out(eos); } c 2003,2005 Typeset February 27, 2009 4

Client-Server. SimulatingamonitorusingAMP. Clients send operation name and parameters and receive result Server receives requests and sends results Monitor invariant becomes loop invariant of the server. process Server() { declare data initialize data while( true){##m receive request(clientid, opkind, parameters) case( opkind ) { when OP 0 { op 0 body. Calculate result send reply[clientid]( result ) ; }... when OP k { op k body. Calculate result send reply[clientid]( result ) ; } } } c 2003,2005 Typeset February 27, 2009 5

Conditions Signal and Urgent (LIFO) Wait Each condition c becomes a queue q c local to the server. procedure op i () { W wait c ; X return result; } procedure op j () { Y signal c ; Z return result; } Becomes case( opkind ) {... when OP i { W q c.insert( clientid ) ; } when OP j { Y if(!q c.empty()){ q c.remove( id ) ; X 0 send reply[id]( result 0 );} Z send reply[clientid]( result ) ; }... } Considerations Local data may have to be put on queue c 2003,2005 Typeset February 27, 2009 6

Multiple wait(c) in monitor: queue indication of which wait. Multiple signal(c) in monitor: write subroutine for signal. c 2003,2005 Typeset February 27, 2009 7

Session-based: client-server Each client has the undivided attention of a server for as long as it needs. Example: process Server [ i = 1 to N]{ while( true){ int clientid ; receive openchan( clientid ) send replychan[ clientid ]( openack( i ) ) State serverstate := initstate ; do { Request request ; receive requestchan[i]( request ) ; Reply reply ;... compute reply and change state... send replychan[ clientid ]( reply ) ; } while(...session not over... ) ; } } c 2003,2005 Typeset February 27, 2009 8

Interacting Peers: Exchanging Values Task: Determine the largest and smallest value held by processes. Centralized: Coordinator gathers all, and sends results. Asymmetric coordinator does all the work 2(n 1) messages, n channels Symmetric: Each sends data to all others, receives from all others, then computes results. n(n 1) messages, 2n channels Logical Ring: Recv local max, min from prev; Send local max, min to next; Recv global max, min from prev; Send global max, min to next. 2(n 1) messages, n channels c 2003,2005 Typeset February 27, 2009 9

AMP in Java Sockets Two-way channels for bytes. ServerSocket allocates a port for the channel. Socket opens a channel on the port. inputstream outputstream (Disclaimer: Don t take the following code too literally. I ve omitted some necessary exception handling.) c 2003,2005 Typeset February 27, 2009 10

Multi-session Server void startsession(final Socket socket) { Thread sessionthread = new Thread() { public void run() { BufferedReader from_client = new BufferedReader( new InputStreamReader( socket.getinputstream())); PrintWriter to_client = new PrintWriter( socket.getoutputstream());... communicate with client... to_client.close(); from_client.close(); socket.close(); } } sessionthread.start() ; }... ServerSocket listen = new ServerSocket(8080); while( true ){ Socket socket = listen.accept(); startsession( socket ) ; } c 2003,2005 Typeset February 27, 2009 11

Client InetAddress serverhost = InetAddress.getByName( web.engr.mun.ca ) ; Socket socket = new Socket(serverHost, 8080); BufferedReader from_server = new BufferedReader( new InputStreamReader( socket.getinputstream())); PrintWriter to_server = new PrintWriter( socket.getoutputstream());... use socket to communicate with server... from_server.close(); to_server.close(); socket.close(); c 2003,2005 Typeset February 27, 2009 12

Synchronous Message Passing Non-buffered communication sync_send blocks until message is received Combined communication and synchronization Can be viewed as distributed assignment statement. Often reduces concurrency sender or receiver waiting. More prone to deadlock. c 2003,2005 Typeset February 27, 2009 13

Examples Pipelined sieve of Eratosthenes - First number received, p i,isprime - From remaining values, pass on only if x%p i 6=0 Heartbeat compare and exchange sort Each of k processes holds n/k data elements Even rounds: if i is even, P[i] sends its largest to P[i +1], receives from P[i +1]its smallest. if i is odd, P[i] sends its smallest to P[i 1], receives from P[i 1] its smallest. Odd rounds: if i is odd, P[i] sends its largest to P[i +1], receive from P[i +1]its smallest. if i is even, P[i] sends its smallest to P[i 1], receive from P[i 1] its largest. c 2003,2005 Typeset February 27, 2009 14

process HeartBeatSort[ i : 0 to k-1] {...find largest and smallest of local items... int round := 0 ; while(... ) if( (i+round) is even and i < k-1 ) { send c[i+1]( largest ) ; receive c[i](largest);} else if( (i+round) is odd and i > 0){ send c[i-1]( smallest ) ; receive c[i]( smallest ) ; }...recalculate largest and smallest... round += 1 ; } } Termination is a bit tricky. We need to run at least 2(n/k + k 1) rounds, but then have to make sure that the last exchange that each pair makes is not counterproductive. c 2003,2005 Typeset February 27, 2009 15