1 / 70

Interprocess Communication (IPC)

Interprocess Communication (IPC). Source: George Colouris , Jean Dollimore , Tim Kinderberg & Gordon Blair (2012). Distributed Systems: Concepts & Design (5 th Ed.). Essex: Addison-Wesley Power point presentation was adapted from: http://faculty.ksu.edu.sa/metwally/Pages/IS335.aspx

durin
Download Presentation

Interprocess Communication (IPC)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. InterprocessCommunication (IPC) Source: George Colouris, Jean Dollimore, Tim Kinderberg & Gordon Blair (2012). Distributed Systems: Concepts & Design (5th Ed.). Essex: Addison-Wesley • Power point presentation was adapted from: • http://faculty.ksu.edu.sa/metwally/Pages/IS335.aspx • http://www.cdk5.net/wp/preface

  2. Contents • Introduction • The API for the Internet Protocol • External data representation and marshalling • Multicast communication • Network virtualization: Overlay networks • Case Study: MPI

  3. Contents • Introduction • The API for the Internet Protocol • External data representation and marshalling • Multicast communication • Network virtualization: Overlay networks • Case Study: MPI

  4. Introduction

  5. Introduction Applications, services Remote Method Invocation (RMI) Remote Procedure Calling (RPC) Middleware request-reply protocol This layers chapter marshalling and external data representation UDP and TCP

  6. Contents • Introduction • The API for the Internet Protocol • External data representation and marshalling • Multicast communication • Network virtualization: Overlay networks • Case Study: MPI

  7. The API for the Internet Protocol • Massage passing between a pair of processes are supported by two communication operations: Send and Receive • A queue is at the message destination - a buffer between the sender and receiver: • When the buffer is empty the receiver must wait. • When the buffer is full the sender must wait, or messages will be lost. • Communication is termed as synchronous or asynchronous depending on the degree of coordination imposed between sender and receiver: • Synchronous: both send and receive are blocking operations: • Sender blocks until a receive is issued • Receiver blocks until a message arrives • Asynchronous: send operation is non-blocking • Sender is non-blocking (copy goes to its local buffer) • Receiver blocking (ALWAYS) or non-blocking (out of control flow) • Characteristics of IPC

  8. The API for the Internet Protocol • Message destinations • A local port is a message destination within a computer, specified as an integer. • A port has an exactly one receiver but can have many senders. • Reliability • A reliable communication is defined in terms of validity and integrity. • A point-to-point message service is described as reliable if messages are guaranteed to be delivered despite a reasonable number of packets being dropped or lost. • For integrity, messages must arrive uncorrupted and without duplication. • Ordering • Some applications require that messages be delivered in sender order. • Characteristics of IPC

  9. The API for the Internet Protocol • Communication between processes is made between ports. • Each computer has 216 possible ports represented by integer numbers: • some ports have specific use but others are available for general use. • Each port corresponds to a single receiving process, but each process may have more than one port at which it receives. • Any number of senders can send messages to a port. • Socketsare software abstractions of ports used within running processes. • Messages are sent between a pair of sockets. • Sockets need to be bound to a port number and a host IP address in order to be useable for sending and receiving messages. • Socket binding may be automatic (Java) or done explicitly (BSD UNIX). • Each socket is associated with a particular transport protocol, i.e. UDP (datagrams) or TCP (streams). • Ports and Sockets

  10. The API for the Internet Protocol • Internet IPC mechanism of Unix and other operating systems (BSD Unix, Solaris, Linux, Windows NT, Macintosh OS) • Processes in the above OS can send and receive messages via a socket. • Sockets need to be boundto a port number and an internet address in order to send and receive messages. • Each socket has a transport protocol (TCP or UDP). • Messages sent to some internet address and port number can only be received by a process using a socket that is bound to this address and port number. • Processes cannot share ports (exception: TCP multicast). • Ports and Sockets

  11. The API for the Internet Protocol • Both forms of communication, UDP and TCP, use the socket abstraction, which provides and endpoint for communication between processes. • Interprocess communication (IPC) consists of transmitting a message between a socket in one process and a socket in another process. • Ports and Sockets

  12. The API for the Internet Protocol • Ports and Sockets agreed port any port socket socket message client server other ports IP address = 138.37.94.248 IP address = 138.37.88.249

  13. The API for the Internet Protocol • The java.net package is intended to provide an application programmer with a powerful infrastructure for networking: • Java provides three basic socket classes: • DatagramSocket for datagram communication and • Both of ServerSocket and Socket for stream communication. • Java includes classes for representing URLs (the URL class) and Internet addresses (the InetAddress class). • More explicit networking can be considered using the socket classes, which makes use of the InetAddress class. • InetAddress class has no public constructor but has getByName() method that take a DNS name and make use of the DNS server. • InetAddressaComputer = InetAddress.getByName(“wassif.ccis.ksu.edu.sa"); • InetAddress class is designed to handle both IPv4 (4 bytes) and IPv6 (16 bytes) addresses. • Ports and Sockets

  14. The API for the Internet Protocol • UDP datagram properties • No guarantee of order preservation • Message loss and duplications are possible • Necessary steps • Creating a socket • Binding a socket to a port and local Internet address • A client binds to any free local port • A server binds to a server port • Receive method • It returns Internet address and port of sender, plus message. • UDP datagram Communication

  15. The API for the Internet Protocol • Comparison of UDP and TCP • UDP & TCP URL: http://commons.wikimedia.org/wiki/File:Tcp_udp.jpg

  16. The API for the Internet Protocol • Issues related to datagram communications are: • Message size • IP allows for messages of up to 216 bytes. • Most implementations restrict this to around 8 kbytes. • Any application requiring messages larger than the maximum must fragment. • If arriving message is too big for array allocated to receive message content, truncation occurs. • UDP datagram Communication

  17. The API for the Internet Protocol • Issues related to datagram communications are: • Blocking • Send: non-blocking • upon arrival, message is placed in a queue for the socket that is bound to the destination port. • Receive: blocking • Pre-emption by timeout possible • If process wishes to continue while waiting for packet, use separate thread • UDP datagram Communication

  18. The API for the Internet Protocol • Issues related to datagram communications are: • Timeout • The receive that blocks forever is suitable for use by a server that is waiting to receive requests from its clients • Not appropriate for some program, e.g. crash/lost requests • Set time out on sockets • UDP datagram Communication

  19. The API for the Internet Protocol • Issues related to datagram communications are: • Receive from any • The receive method does not specify an origin for messages, an invocation of receive gets a message addressed to its socket from any origin • Connect a datagram socket to a particular remote port and Internet address – the socket is only able to send messages to and receive messages from that address • UDP datagram Communication

  20. The API for the Internet Protocol • The Java API provides datagram communication by two classes: • Datagram Packet • Datagram Socket • Datagram Packet: • It provides a constructor to make an array of bytes comprising: • Message content • Length of message • Internet address • Local port number • It provides another similar constructor for receiving a message. • Java API for UDP Datagrams array of bytes containing message | length of message| Internet address | port number|

  21. The API for the Internet Protocol • Datagram Socket • This class supports sockets for sending and receiving UDP datagram. • It provides a constructor with port number as argument. • No-argument constructor is used to choose a free local port. • Datagram Socket methods are: • send and receive • setSoTimeout • Connect • Example: The process creates a socket, sends a message to a server at port 6789 and waits to receive a reply. • Java API for UDP Datagrams

  22. The API for the Internet Protocol • Java API for UDP Datagrams import java.net.*; import java.io.*; public class UDPClient{ public static void main(String args[]){ // args give message contents and server hostname DatagramSocketaSocket = null; try { aSocket= new DatagramSocket(); byte [] m = args[0].getBytes(); InetAddressaHost = InetAddress.getByName(args[1]); intserverPort = 6789; DatagramPacketrequest = new DatagramPacket(m, m.length(), aHost, serverPort); aSocket.send(request); byte[] buffer = new byte[1000]; DatagramPacketreply = new DatagramPacket(buffer, buffer.length); aSocket.receive(reply); System.out.println("Reply: " + new String(reply.getData())); }catch (SocketException e){System.out.println("Socket: " + e.getMessage()); }catch (IOException e){System.out.println("IO: " + e.getMessage());} }finally {if(aSocket != null) aSocket.close();} } } UDP client sends a message to the server and gets a reply

  23. The API for the Internet Protocol • Example • The process creates a socket, bound to its server port 6789 and waits to receive a request message from a client. • Java API for UDP Datagrams

  24. The API for the Internet Protocol • Java API for UDP Datagrams import java.net.*; import java.io.*; public class UDPServer{ public static void main(String args[]){ DatagramSocketaSocket = null; try{ 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());} }finally {if(aSocket != null) aSocket.close();} } } UDP server repeatedly receives a request and sends it back to the client

  25. The API for the Internet Protocol • The API to the TCP protocol provides the abstraction of a stream of bytes to be written to or read from. • Characteristics of the stream abstraction: • Message sizes • Lost messages • Flow control • Message destinations • TCP Stream Communication

  26. The API for the Internet Protocol • Issues related to stream communication: • Matching of data items • Blocking • Threads • TCP Stream Communication

  27. The API for the Internet Protocol • Use of TCP • Many services that run over TCP connections, with reserved port number are: • HTTP (Hypertext Transfer Protocol) • FTP (File Transfer Protocol) • Telnet • SMTP (Simple Mail Transfer Protocol) • TCP Stream Communication

  28. The API for the Internet Protocol • Java API for TCP streams • The Java interface to TCP streams is provided in the classes: • ServerSocket • It is used by a server to create a socket at server port to listen for connect requests from clients. • Socket • It is used by a pair of processes with a connection. • The client uses a constructor to create a socket and connect it to the remote host and port of a server. • It provides methods for accessing input and output streams associated with a socket. Example: The client process creates a socket, bound to the hostname and server port 6789 and the server process opens a server socket to its server port 6789 and listens for connect requests. • TCP Stream Communication

  29. The API for the Internet Protocol import java.net.*; import java.io.*; public class TCPServer { public static void main (String args[]) { try{ intserverPort = 7896; ServerSocketlistenSocket = new ServerSocket(serverPort); while(true) { Socket clientSocket = listenSocket.accept(); Connection c = new Connection(clientSocket); } } catch(IOException e) {System.out.println("Listen socket:"+e.getMessage());} } } • TCP Stream Communication TCP server makes a connection for each client and then echoes the client’s request

  30. The API for the Internet Protocol class Connection extends Thread { DataInputStream in; DataOutputStream out; Socket clientSocket; public Connection (Socket aClientSocket) { try { clientSocket = aClientSocket; in = new DataInputStream( clientSocket.getInputStream()); out =new DataOutputStream( clientSocket.getOutputStream()); this.start(); } catch(IOException e){System.out.println("Connection:"+e.getMessage());} } public void run(){ try { // an echo server String data = in.readUTF(); out.writeUTF(data); } catch (EOFException e){System.out.println("EOF:"+e.getMessage()); } catch (IOException e) {System.out.println("readline:"+e.getMessage());} } finally {try{clientSocket.close();}catch(IOException e){/*close failed*/}} } } • TCP Stream Communication TCP server makes a connection for each client and then echoes the client’s request

  31. Contents • Introduction • The API for the Internet Protocol • External data representation and marshalling • Multicast communication • Network virtualization: Overlay networks • Case Study: MPI

  32. External Data Representation • Representation problems: • The information stored in running programs is represented as data structures, whereas the information in messages consists of sequences of bytes. • Irrespective of the form of communication used, the data structure must be converted to a sequence of bytes before transmission and rebuilt on arrival. • External Data Representation is an agreed standard for the representation of data structures and primitive values.

  33. External Data Representation • Marshalling • Marshalling is the process of taking a collection of data items and assembling them into a form suitable for transmission in a message. • Unmarshalling • Unmarshalling is the process of disassembling a collection of data on arrival to produce an equivalent collection of data items at the destination. • Three approaches to external data representation and marshalling are: • CORBA • Java’s object serialization • XML

  34. External Data Representation • Marshalling and unmarshalling activitiesis usually performed automatically by middleware layer. • Marshalling is likely error-prone if carried out by hand.

  35. External Data Representation • CORBA CDR is the external data representation defined with CORBA 2.0. • It consists 15 primitive types: • Short (16 bit) • Long (32 bit) • Unsigned short • Unsigned long • Float(32 bit) • Double(64 bit) • Char • Boolean(TRUE,FALSE) • Octet(8 bit) • Any(can represent any basic or constructed type) • CORBA Common Data Representation (CDR)

  36. External Data Representation • CORBA Common Data Representation (CDR)

  37. External Data Representation example: struct with value {‘Smith’, ‘London’, 1934} • CORBA Common Data Representation (CDR)

  38. External Data Representation • Marshaling and unmarshalling operations are generated automatically from the specification of data items transmitted in a message. • The type definitions of data structures and primitive data items are described in CORBA Interface Definition Language (IDL). • CORBA interface compiler generates appropriate marshaling and unmarshalling operations from the type definitions of remote methods arguments and results • CORBA Common Data Representation (CDR)

  39. External Data Representation • In Java RMI, both object and primitive data values may be passed as arguments and results of method invocation. • An object is an instance of a Java class. • Example, the Java class equivalent to the Person struct Public class Person implements Serializable { Private String name; Private String place; Private int year; Public Person(String aName ,String aPlace, intaYear) { name = aName; place = aPlace; year = aYear; } //followed by methods for accessing the instance variables } • Java Object Serialization

  40. External Data Representation • Serialization and deserialization in Java: • Serialization is the activity of flattening object or a related set of objects in a serial form suitable for transmitting in a message. • Deserialization is the activity of restoring the state of an object or a set of objects from their serialized form. • All objects referenced on an object are serialized as handles when that object is serialized. • Serialization of a specific object is done by creating an instance of the class ObjectOutputStreamand invoking itswriteObjectmethod with the object name as rgument. • ObjectInputStreamclassis opened on a stream of data to deserialize an object from that stream using the readObjectmethod. • Making generic serialization and deserialization is possible using reflection rather than to generate special marshalling functions for each type of object (as in CORBA). • Java Object Serialization

  41. External Data Representation • Java Object Serialization

  42. External Data Representation • XML is a mark up language that was defined by the WWW Consortium (W3C) for general use of web. • Mark up language refers to a textual encoding that represents both a text and details as to its structure or its appearance • XML data items are tagged with “markup” strings. • The tags are used to describe the logical structure of the data and to associate attribute-value pairs with logical structure • It is used to enable clients to communicate with web services and for defining the interfaces and other properties of web services. • Extensible Markup Language

  43. External Data Representation • Extensible – users can define their own tags. • If a document is intended to be used by more than one application, the names of the tags must be agreed between them • Advantage of XML • Binary data representation is not required • Disadvantage of XML • Longer processing time • Try writing XML - www.w3schools.com/xml/default.asp • Extensible Markup Language

  44. External Data Representation • XML elements and attributes: • Element: a portion of character data surrounded by matching start and end tags • Attribute : a start tag may optionally include pairs of associated attribute name and values such as id=“123456789” • Extensible Markup Language <person id="123456789"> <name>Smith</name> <place>London</place> <year>1984</year> <!-- a comment --> </person >

  45. External Data Representation • Extensible Markup Language • Parsing and well-formed documents • Well-formed documents – matching tags and nested • Example: <x>….<y>….</y>….</x> • Visit this website to develop and parse your own XML • http://www.xmlfiles.com/examples/tryit.asp?filename=note_parsertest • XML prolog • prolog must be written in the first line of a XML document • Example : <?xml version="1.0"?>

  46. External Data Representation • XML namespaces • A set of names for a collection of element types and attributes that is referenced by a URL. Any other XN documents can use an XML namespace by referring to its URL • Extensible Markup Language <person pers:id="123456789" xmlns:pers = "http://www.cdk5.net/person"> <pers:name> Smith </pers:name> <pers:place> London </pers:place > <pers:year> 1984 </pers:year> </person>

  47. External Data Representation • XML Schemas • Defines the elements and attributes that can appear in a document, how the elements are nested and the order and number of elements, and whether the element can empty or include text. • Extensible Markup Language <xsd:schemaxmlns:xsd = URL of XML schema definitions > <xsd:element name= "person" type ="personType" /> <xsd:complexType name="personType"> <xsd:sequence> <xsd:element name = "name" type="xs:string"/> <xsd:element name = "place" type="xs:string"/> <xsd:element name = "year" type="xs:positiveInteger"/> </xsd:sequence> <xsd:attribute name= "id" type = "xs:positiveInteger"/> </xsd:complexType> </xsd:schema>

  48. External Data Representation • Needed when a client invokes a method of an object located on a remote server. • Must be generated in a manner that ensure uniqueness over space and time. • Unique among all of the processes in the various computers in a distributed system. • References of deleted remote objects are not reused to avoid accessing different objects. • Constructed by connecting the IP address of its computer and the port number of the process created it with the time of its creation and a local object number. • Remote Object References

  49. 32 bits 32 bits 32 bits 32 bits interface of Internet address port number time object number remote object External Data Representation • Internet address/port number: process which created object • Time: creation time • Object number: local counter, incremented each time an object is created in the creating process • Interface: how to access the remote object (if object reference is passed from one client to another) • Remote Object References

  50. Contents • Introduction • The API for the Internet Protocol • External data representation and marshalling • Multicast communication • Network virtualization: Overlay networks • Case Study: MPI

More Related