Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "1 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001."— Presentation transcript:

1 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

2 2 Interprocess communication – middleware layers

3 3 Interprocess communication – basics zMessage passing by send and receive. zMessages put in and taken from queues. zIssues: yReliability xValidity (all messages are delivered despite a ‘reasonable’ number of packets are lost) xIntegrity (uncorrupted, without duplication) yOrdering xRandom order / sender order zCommunication patterns: ySynchronous. yAsynchronous.

4 4 Interprocess communication – Communication patterns zSynchronous ySend is blocking yReceive is blocking zAsynchronous ySend is non-blocking yReceive can be both blocking and non-blocking xUsually blocking – compensate by using threads Simple and non-complex code xNon-blocking more efficient Involves extra complexity to deal with

5 5 Interprocess communication – ports and sockets message agreed port any port socket Internet address = 138.37.88.249Internet address = 138.37.94.248 other ports client server zPort: Message destination within a computer (process) zSocket: Endpoint for communication between processes yAssociated with either UDP or TCP yProcess may use any number of sockets yCan’t be shared between processes

6 6 UDP – User Datagram Protocol zNo acknowledgements, no retries. zNon-blocking send operation. zBlocking receive operation. zTimeouts may be applied yServer: Receive blocks for ever yClient: Timeout on receive (value difficult, fairly large) zFailure model: yOmission failures (dropped: checksum / no buffer). yOrdering (out of order deliveries). zExample of use: DNS.

7 7 UDP – Java API zDatagramPacket: yArray of bytes containing message. yLength of message. yInternet address. yPort number. yMethods: new, getData, getLength, getPort, getAddress. zDatagramSocket: yMethods: new, send, receive, …

8 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());} }

9 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());} }

10 10 TCP – Transmission Control Protocol zTwo-way stream of bytes. zTCP uses: yconnect operation. yaccept operations. zClient creates a stream socket bound to any port and makes a connect. zServer creates a listening socket bound to a server port. zUpon accept, a connection between client and server established using a new socket yAllows peer communication

11 11 TCP – properties zTCP hides: yMessage sizes (splits stream into messages). yLost messages (retransmits non-acknowledge messages). yFlow control (blocks sender if receiver can’t keep up). yMessage duplication and ordering. yMessage destinations (connected – no addressing). zFailure model: yEnsures (almost always) integrity. yNot reliability: Cannot survive all situations. yUnable to distinguish network and process failures. zExamples of use: HTTP, FTP, Telnet, SMTP.

12 12 External data representation and marshalling – basics zPrograms use data structures; messages are sequences of bytes. zConvert by marshalling / unmarshalling. zIssues: yCharacter sets – ASCII (1 byte) vs. Unicode (2 bytes). yByte order – big-endian vs. little-endian. zTwo methods for data exchange: yConvert values to agreed external format before transmission. yTransmit values in sender’s format. zExternal data representation: Agreed standard for representation of data structures and primitive values.

13 13 External data representation and marshalling – approaches zCORBA’s common data representation (CDR): yRepresentation of data types used as arguments and return values in remote invocations in CORBA. y15 primitive types (short, long, char, boolean, …). yComposed types. zJava’s object serialization. yBoth objects and primitive data values may be passed as arguments and results of method invocation. zMarshalling and unmarshalling by middleware; no involvement of application programmer.

14 14 External data representation and marshalling – CORBA CDR message The flattened form represents aPerson struct with value: {‘Smith’, ‘London’, 1934} 0–3 4–7 8–11 12–15 16–19 20-23 24–27 5 "Smit" "h___" 6 "Lond" "on__" 1934 index in sequence of bytes4 bytes notes on representation length of string ‘Smith’ length of string ‘London’ unsigned long Marshalling operations can be generated automatically from the spec of the types of data items to be transmitted; types described by CORBA IDL (interface definition language).

15 15 Request-reply protocol – client-server communication Request ServerClient doOperation (wait) (continuation) Reply message getRequest execute method message select object sendReply zSynchronous yClient blocks until reply zBuilds on UPD send and receive

16 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.

17 17 Request-reply protocol – message structure messageType requestId objectReference methodId arguments int (0=Request, 1= Reply) int RemoteObjectRef int or Method array of bytes

18 18 Request-reply protocol – failure model zProblems: yOmission failures. yNo guarantee of delivery in order. zSolutions: yTimeouts. yDiscarding duplicate request messages. yLost reply messages. yHistory. yIdempotent operations.

19 19 Group communication – basics zSending of a single message from one process to each of the members of a group of processes. zUseful for: yFault tolerance based on replicated services. yFinding the discovery servers in spontaneous networking. yBetter performance through replicated data. yPropagation of event notification.

20 20 Group communication – IP multicast zBuilt on top of IP. zAllows transmission of a single IP packet to a set of computers (a multicast group; class D internet address). zAt the application level, IP multicast is available only via UDP. zFailure model: Unreliable.

21 21 Group communication – IP multicast Java API zMulticastSocket (subclass of DatagramSocket). zAdding capability to join and leave multicast groups.

22 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

23 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());} }

24 24 Summary zIntro to interprocess communication, incl. ports and sockets. zUDP and TCP. zExternal data representation, marshalling; CORBA CDR, Java object serialization. zRequest-reply protocol. zGroup communication.


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

Similar presentations


Ads by Google