Presentation is loading. Please wait.

Presentation is loading. Please wait.

Source: George Colouris, Jean Dollimore, Tim Kinderberg & Gordon Blair (2012). Distributed Systems: Concepts & Design (5 th Ed.). Essex: Addison-Wesley.

Similar presentations


Presentation on theme: "Source: George Colouris, Jean Dollimore, Tim Kinderberg & Gordon Blair (2012). Distributed Systems: Concepts & Design (5 th Ed.). Essex: Addison-Wesley."— Presentation transcript:

1 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: (i)http://faculty.ksu.edu.sa/metwally/Pages/IS335.aspx (ii)http://www.cdk5.net/wp/preface

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

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

4

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

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

7  Massage passing between a pair of processes are supported by two communication operations: Send and Receive queue  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. synchronous or asynchronous  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  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  Communication between processes is made between ports.  Each computer has 2 16 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.  Sockets  Sockets are 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  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 bound to 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  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 message agreed port any port socket IP address = 138.37.88.249IP address = 138.37.94.248 other ports client server

13  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.  InetAddress aComputer = 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  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  Comparison of UDP and TCP  UDP & TCP URL: http://commons.wikimedia.org/wiki/Fil e:Tcp_udp.jpg

16  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  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  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  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 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  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 import java.net.*; import java.io.*; public class UDPClient{ public static void main(String args[]){ // args give message contents and server hostname DatagramSocket aSocket = null; try { aSocket = new DatagramSocket(); byte [] m = args[0].getBytes(); InetAddress aHost = InetAddress.getByName(args[1]); int serverPort = 6789; DatagramPacket request = new DatagramPacket(m, m.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())); }catch (SocketException e){System.out.println("Socket: " + e.getMessage()); }catch (IOException e){System.out.println("IO: " + e.getMessage());} }finally {if(aSocket != null) aSocket.close();} }

23  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 import java.net.*; import java.io.*; public class UDPServer{ public static void main(String args[]){ DatagramSocket aSocket = 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();} }

25  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  Issues related to stream communication:  Matching of data items  Blocking  Threads  TCP Stream Communication

27  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  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 import java.net.*; import java.io.*; public class TCPServer { public static void main (String args[]) { try{ int serverPort = 7896; ServerSocket listenSocket = 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 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  Introduction  The API for the Internet Protocol  External data representation and marshalling  Multicast communication  Network virtualization: Overlay networks  Case Study: MPI

32  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  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  Marshalling and unmarshalling activities is usually performed automatically by middleware layer.  Marshalling is likely error-prone if carried out by hand.

35  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

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

38  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  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, int aYear) { name = aName; place = aPlace; year = aYear; } //followed by methods for accessing the instance variables }  Java Object Serialization

40  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 ObjectOutputStream and invoking its writeObject method with the object name as rgument.  ObjectInputStream class is opened on a stream of data to deserialize an object from that stream using the readObject method.  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

42  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  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  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 Smith London 1984

45  Parsing and well-formed documents  Well-formed documents – matching tags and nested  Example: …. …. ….  Visit this website to develop and parse your own XML  http://www.xmlfiles.com/examples/tryit.asp?filename=note _parsertest 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 :  Extensible Markup Language

46  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 http://www.cdk5.net/person Smith London 1984

47  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

48  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  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 Internet addressport numbertimeobject number interface of remote object 32 bits

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

51  The pairwise exchange of messages is not the best model for a group communication  A multicast operation is more appropriate  Multicast operation is an operation that sends a single message from one process to each of the members of a group of processes.  The simplest way of multicasting, provides no guarantees about message delivery or ordering.  Group Communication

52  Multicasting has the following characteristics:  Fault tolerance based on replicated services  A replicated service consists of a group of servers.  Client requests are multicast to all the members of the group, each of which performs an identical operation.  Finding the discovery servers in spontaneous networking  Multicast messages can be used by servers and clients to locate available discovery services in order to register their interfaces or to look up the interfaces of other services in the distributed system.  Group Communication

53  Better performance through replicated data  Data are replicated to increase the performance of a service.  Propagation of event notifications  Multicast to a group may be used to notify processes when something happens.  Group Communication

54  IP multicast is built on top of the Internet protocol, IP.  IP multicast allows the sender to transmit a single IP packet to a multicast group.  A multicast group is specified by class D IP address for which first 4 bits are 1110 in IPv4.  The membership of a multicast group is dynamic.  A computer belongs to a multicast group if one or more processes have sockets that belong to the multicast group.  IP Multicast

55  The following details are specific to IPv4:  Multicast IP routers  IP packets can be multicast both on local network and on the wider Internet.  Local multicast uses local network such as Ethernet.  To limit the distance of propagation of a multicast datagram, the sender can specify the number of routers it is allowed to pass- called the time to live, or TTL for short.  Multicast address allocation  Multicast addressing may be permanent or temporary.  Permanent groups exist even when there are no members.  Multicast addressing by temporary groups must be created before use and cease to exit when all members have left.  The session directory (sd) program can be used to start or join a multicast session.  session directory provides a tool with an interactive interface that allows users to browse advertised multicast sessions and to advertise their own session, specifying the time and duration.  IP Multicast

56  The Java API provides a datagram interface to IP multicast through the class MulticastSocket, which is a subset of DatagramSocket with the additional capability of being able to join multicast groups.  The class MulticastSocket provides two alternative constructors, allowing socket to be creative to use either a specified local port, or any free local port.  Java IP to IP Multicast

57 import java.net.*; import java.io.*; public class MulticastPeer{ public static void main(String args[]){ // args give message contents and destination multicast group (e.g. "228.5.6.7") MulticastSocket s =null; try { InetAddress group = InetAddress.getByName(args[1]); s = new MulticastSocket(6789); s.joinGroup(group); byte [] m = args[0].getBytes(); DatagramPacket messageOut = new DatagramPacket(m, m.length, group, 6789); s.send(messageOut); byte[] buffer = new byte[1000]; for(int i=0; i< 3;i++) {// get messages from others in group 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()); }finally {if(s != null) s.close();} }  Java IP to IP Multicast Multicast peer joins a group and sends and receives datagrams

58  A process can join a multicast group with a given multicast address by invoking the joinGroup method of its multicast socket.  A process can leave a specified group by invoking the leaveGroup method of its multicast socket.  The Java API allows the TTL to be set for a multicast socket by means of the setTimeToLive method. The default is 1, allowing the multicast to propagate only on the local network.  Java IP to IP Multicast

59  Introduction  The API for the Internet Protocol  External data representation and marshalling  Multicast communication  Network virtualization: Overlay networks  Case Study: MPI

60  Problem with the current Internet communication protocol  A growing range of different classes of applications (e.g., P2P file sharing, skype) coexist in the Internet  The IP transport service is implemented over a large and ever increasing number of network technologies  Solution: network virtualization  Construction of virtual networks over an existing network such as the Internet  Each virtual network can be designed to support a particular distributed application  Introduction

61  A virtual network consisting of nodes and virtual links, which sits on top of the underlying network (such as an IP network) and offer:  A service that is tailored towards the needs of a class of application –e.g., multimedia content distribution  More efficient operation in a given networked environment – e.g. routing  Secure feature  Overlay Networks

62  Advantages:  Enable new network services to be defined without requiring changes to the underlying network  Encourage experimentation with network services and the customization of services to particular classes of application  Multiple overlay can be defined and can coexists  Disadvantages  Introduce an extra level of indirection  Add to the complexity of network services  Overlay Networks

63

64

65  Skype is an example of overlay network  A P2P application offering VoIP, instant messaging, video conferencing and telephony service  Overlay networks

66  Introduction  The API for the Internet Protocol  External data representation and marshalling  Multicast communication  Network virtualization: Overlay networks  Case Study: MPI

67  MPI was introduced in 1994 by the MPI forum (http://www.mpi-forum.org)http://www.mpi-forum.org  MPI forum was intended to enhance the portability of the standard through presenting a standardized interface independent of the OS or programming-language-specific socket interface  Message Passing Interface Standard

68

69

70


Download ppt "Source: George Colouris, Jean Dollimore, Tim Kinderberg & Gordon Blair (2012). Distributed Systems: Concepts & Design (5 th Ed.). Essex: Addison-Wesley."

Similar presentations


Ads by Google