1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems:...

24
1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001 sentation based on slides by Coulouris et al; ified by Jens B Jorgensen and Jonas Thomsen, versity of Aarhus
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    228
  • download

    0

Transcript of 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems:...

Page 1: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

1

Chapter 4: Interprocess Communication

From Coulouris, Dollimore and Kindberg

Distributed Systems: Concepts and Design

Edition 3, © Addison-Wesley 2001

Presentation based on slides by Coulouris et al;modified by Jens B Jorgensen and Jonas Thomsen,University of Aarhus

Page 2: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

2

Interprocess communication – middleware layers

Applications, services

Middlewarelayers

request-reply protocol

marshalling and external data representation

UDP and TCP

Thischapter

RMI and RPC

Page 3: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

3

Interprocess communication – basics

Message passing by send and receive.Messages put in and taken from queues. Issues:

Reliability Validity (all messages are delivered despite a ‘reasonable’ number of

packets are lost) Integrity (uncorrupted, without duplication)

Ordering Random order / sender order

Communication patterns: Synchronous. Asynchronous.

Page 4: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

4

Interprocess communication – Communication patterns

Synchronous Send is blocking Receive is blocking

Asynchronous Send is non-blocking Receive can be both blocking and non-blocking

Usually blocking – compensate by using threads

• Simple and non-complex code Non-blocking more efficient

• Involves extra complexity to deal with

Page 5: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

5

Interprocess communication – ports and sockets

message

agreed portany port

socketsocket

Internet address = 138.37.88.249Internet address = 138.37.94.248

other ports

client server

Port: Message destination within a computer (process) Socket: Endpoint for communication between processes

Associated with either UDP or TCP Process may use any number of sockets Can’t be shared between processes

Page 6: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

6

UDP – User Datagram Protocol

No acknowledgements, no retries.Non-blocking send operation.Blocking receive operation.Timeouts may be applied

Server: Receive blocks for ever Client: Timeout on receive (value difficult, fairly large)

Failure model: Omission failures (dropped: checksum / no buffer). Ordering (out of order deliveries).

Example of use: DNS.

Page 7: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

7

UDP – Java API

DatagramPacket: Array of bytes containing message. Length of message. Internet address. Port number. Methods: new, getData, getLength, getPort, getAddress.

DatagramSocket: Methods: new, send, receive, …

Page 8: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

8

UDP – Java client

import java.net.*;import java.io.*;public class UDPClient{ public static void main(String args[]){

// args give message contents and server hostname try {

DatagramSocket aSocket = new DatagramSocket(); byte [] m = args[0].getBytes();InetAddress aHost = InetAddress.getByName(args[1]);int serverPort = 6789; DatagramPacket request = new DatagramPacket(m, args[0].length(), aHost, serverPort);aSocket.send(request); byte[] buffer = new byte[1000];DatagramPacket reply = new DatagramPacket(buffer, buffer.length);aSocket.receive(reply);System.out.println("Reply: " + new String(reply.getData()));aSocket.close();

}catch (SocketException e){System.out.println("Socket: " + e.getMessage()); }catch (IOException e){System.out.println("IO: " + e.getMessage());}

} }

Page 9: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

9

UDP – Java server

import java.net.*;import java.io.*;public class UDPServer{

public static void main(String args[]){ try{ DatagramSocket aSocket = new DatagramSocket(6789);

byte[] buffer = new byte[1000]; while(true){ DatagramPacket request = new DatagramPacket(buffer, buffer.length); aSocket.receive(request); DatagramPacket reply = new DatagramPacket(request.getData(),

request.getLength(), request.getAddress(), request.getPort()); aSocket.send(reply);}

}catch (SocketException e){System.out.println("Socket: " + e.getMessage()); }catch (IOException e) {System.out.println("IO: " + e.getMessage());}

}}

Page 10: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

10

TCP – Transmission Control Protocol

Two-way stream of bytes.TCP uses:

connect operation. accept operations.

Client creates a stream socket bound to any port and makes a connect.

Server creates a listening socket bound to a server port.

Upon accept, a connection between client and server established using a new socket Allows peer communication

Page 11: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

11

TCP – properties

TCP hides: Message sizes (splits stream into messages). Lost messages (retransmits non-acknowledge messages). Flow control (blocks sender if receiver can’t keep up). Message duplication and ordering. Message destinations (connected – no addressing).

Failure model: Ensures (almost always) integrity. Not reliability: Cannot survive all situations. Unable to distinguish network and process failures.

Examples of use: HTTP, FTP, Telnet, SMTP.

Page 12: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

12

External data representation and marshalling – basics

Programs use data structures; messages are sequences of bytes.

Convert by marshalling / unmarshalling. Issues:

Character sets – ASCII (1 byte) vs. Unicode (2 bytes). Byte order – big-endian vs. little-endian.

Two methods for data exchange: Convert values to agreed external format before transmission. Transmit values in sender’s format.

External data representation: Agreed standard for representation of data structures and primitive values.

Page 13: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

13

External data representation and marshalling – approaches

CORBA’s common data representation (CDR): Representation of data types used as arguments and

return values in remote invocations in CORBA. 15 primitive types (short, long, char, boolean, …). Composed types.

Java’s object serialization. Both objects and primitive data values may be passed as

arguments and results of method invocation.

Marshalling and unmarshalling by middleware; no involvement of application programmer.

Page 14: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

14

External data representation and marshalling – CORBA CDR message

The flattened form represents a Person struct with value: {‘Smith’, ‘London’, 1934}

0–34–78–1112–15

16–19

20-23

24–27

5

"Smit""h___"

6"Lond""on__"

1934

index in sequence of bytes 4 bytes

notes on representation

length of string

‘Smith’

length of string

‘London’

unsigned long

Marshalling operations can be generated automatically fromthe spec of the types of data items to be transmitted; typesdescribed by CORBA IDL (interface definition language).

Page 15: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

15

Request-reply protocol – client-server communication

Request

ServerClient

doOperation

(wait)

(continuation)

Replymessage

getRequest

execute

method

messageselect object

sendReply

Synchronous Client blocks until reply

Builds on UPD send and receive

Page 16: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

16

Request-reply protocol – operations

public byte[] doOperation (RemoteObjectRef o, int methodId, byte[] arguments)sends a request message to the remote object and returns the reply. The arguments specify the remote object, the method to be invoked and the arguments of that method.

public byte[] getRequest ();acquires a client request via the server port.

public void sendReply (byte[] reply, InetAddress clientHost, int clientPort); sends the reply message reply to the client at its Internet address and port.

Page 17: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

17

Request-reply protocol – message structure

messageType

requestId

objectReference

methodId

arguments

int (0=Request, 1= Reply)

int

RemoteObjectRef

int or Method

array of bytes

Page 18: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

18

Request-reply protocol – failure model

Problems: Omission failures. No guarantee of delivery in order.

Solutions: Timeouts. Discarding duplicate request messages. Lost reply messages. History. Idempotent operations.

Page 19: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

19

Group communication – basics

Sending of a single message from one process to each of the members of a group of processes.

Useful for: Fault tolerance based on replicated services. Finding the discovery servers in spontaneous networking. Better performance through replicated data. Propagation of event notification.

Page 20: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

20

Group communication – IP multicast

Built on top of IP.Allows transmission of a single IP packet to a set of

computers (a multicast group; class D internet address).

At the application level, IP multicast is available only via UDP.

Failure model: Unreliable.

Page 21: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

21

Group communication – IP multicast Java API

MulticastSocket (subclass of DatagramSocket).Adding capability to join and leave multicast groups.

Page 22: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

22

Group communication – IP multicast peers (1)

import java.net.*;import java.io.*;public class MulticastPeer{

public static void main(String args[]){ // args give message contents & destination multicast group (e.g. "228.5.6.7")

try { InetAddress group = InetAddress.getByName(args[1]); MulticastSocket s = new MulticastSocket(6789); s.joinGroup(group);

byte [] m = args[0].getBytes(); DatagramPacket messageOut =

new DatagramPacket(m, m.length, group, 6789); s.send(messageOut);

// this figure continued on the next slide

Page 23: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

23

Group communication – IP multicast peers (2)

// get messages from others in group byte[] buffer = new byte[1000];

for(int i=0; i< 3; i++) { DatagramPacket messageIn =

new DatagramPacket(buffer, buffer.length); s.receive(messageIn); System.out.println("Received:" + new String(messageIn.getData())); }

s.leaveGroup(group); }catch (SocketException e){System.out.println("Socket: " + e.getMessage());

}catch (IOException e){System.out.println("IO: " + e.getMessage());} } }

Page 24: 1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001.

24

Summary

Intro to interprocess communication, incl. ports and sockets.

UDP and TCP.External data representation, marshalling; CORBA

CDR, Java object serialization.Request-reply protocol.Group communication.