Inter Process Commonication. 2 Introduction The java API for interprocess communication in the...

115
Inter Process Commonication

Transcript of Inter Process Commonication. 2 Introduction The java API for interprocess communication in the...

Page 1: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Inter Process Commonication

Page 2: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

2

Introduction The java API for interprocess communication in the

internet provides both datagram and stream communication.

The two communication patterns that are most commonly used in distributed programs:

Client-Server communication The request and reply messages provide the basis for

remote method invocation (RMI) or remote procedure call (RPC).

Group communication The same message is sent to several processes

Page 3: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

3

Introduction This chapter is concerned with

middleware.

Figure 1. Middleware layers

Page 4: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

4

Introduction Remote Method Invocation (RMI)

It allows an object to invoke a method in an object in a remote process.

E.g. CORBA and Java RMI Remote Procedure Call (RPC)

It allows a client to call a procedure in a remote server.

Page 5: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

5

Introduction The application program interface

(API) to UDP provides a message passing abstraction.

Message passing is the simplest form of interprocess communication.

API enables a sending process to transmit a single message to a receiving process.

The independent packets containing theses messages are called datagrams.

In the Java and UNIX APIs, the sender specifies the destination using a socket.

Page 6: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

6

Introduction Socket is an indirect reference to a

particular port used by the destination process at a destination computer.

The application program interface (API) to TCP provides the abstraction of a two-way stream between pairs of processes.

The information communicated consists of a stream of data items with no message boundaries.

Page 7: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

7

Introduction Request-reply protocols are designed to

support client-server communication in the form of either RMI or RPC.

Group multicast protocols are designed to support group communication.

Page 8: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

8

Introduction Group multicast is a form of interprocess

communication in which one process in a group of processes transmits the same message to all members of the group.

Page 9: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

9

The API for the Internet Protocols The CHARACTERISTICS of INTERPROCESS

COMMUNICATION SOCKET UDP DATAGRAM COMMUNICATION TCP STREAM COMMUNICATION

Page 10: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

10

The Characteristics of Interprocess Communication

Synchronous and asynchronous communication

In the synchronous form, both send and receive are blocking operations.

In the asynchronous form, the use of the send operation is non-blocking and the receive operation can have blocking and non-blocking variants.

SYSTEM MODEL

Page 11: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

11

The Characteristics of Interprocess Communication

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.

Page 12: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

12

The Characteristics of Interprocess Communication

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.

Page 13: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

13

The Characteristics of Interprocess Communication

Ordering Some applications require that messages

be delivered in sender order.

Page 14: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

14

Sockets 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).

Page 15: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

15

Sockets 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).

Page 16: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

16

Sockets Both forms of communication, UDP and

TCP, use the socket abstraction, which provides and endpoint for communication between processes.

Interprocess communication consists of transmitting a message between a socket in one process and a socket in another process.

(Figure 2)

Page 17: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

17

Sockets

Figure 2. Sockets and ports

Page 18: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

18

UDP Datagram Communication 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

Page 19: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

19

UDP Datagram Communication Receive method

It returns Internet address and port of sender, plus message.

Page 20: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

20

UDP Datagram Communication 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.

Page 21: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

21

UDP Datagram Communication 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

Page 22: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

22

UDP Datagram Communication Timeout Receive from any

Page 23: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

23

UDP Datagram Communication UDP datagrams suffer from following

failures: Omission failure Messages may be dropped occasionally, Ordering

Page 24: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

24

Java API for UDP Datagrams The Java API provides datagram

communication by two classes:DatagramPacket

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.

array of bytes containing message | length of message| Internet address | port number|

Page 25: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

25

Java API for UDP DatagramsDatagramSocket

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.

DatagramSocket methods are:• send and receive• setSoTimeout• connect

Page 26: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

26

Java API for UDP DatagramsExample– The process creates a socket, sends a message

to a server at port 6789 and waits to receive a reply.

(Figure 3)

Page 27: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

27

Java API for UDP Datagramsimport java.net.*;import java.io.*;public class UDPClient{public static void main(String args[]){// args give message contents and destination hostnametry {DatagramSocket aSocket = new DatagramSocket(); // create socketbyte [] m = args[0].getBytes();InetAddress aHost = InetAddress.getByName(args[1]); // DNS lookupint serverPort = 6789;DatagramPacket request =new DatagramPacket(m, args[0].length(), aHost, serverPort);aSocket.send(request); //send nessagebyte[] buffer = new byte[1000];DatagramPacket reply = new DatagramPacket(buffer, buffer.length);aSocket.receive(reply); //wait for replySystem.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());}} finally{if (aSocket !=null)aSocket.close()}}}

Figure 3. UDP client sends a message to the server and gets a reply

Page 28: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

28

Java API for UDP DatagramsExample– The process creates a socket, bound to its server

port 6789 and waits to receive a request message from a client.

(Figure 4)

Page 29: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

29

Java API for UDP datagramsimport 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()}}}

Figure 4. UDP server repeatedly receives a request and sends it back to the client

Page 30: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

30

TCP Stream Communication 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

Page 31: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

31

TCP Stream Communication Issues related to stream communication:

Matching of data items Blocking Threads

Page 32: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

32

TCP Stream Communication 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)

Page 33: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

33

TCP Stream Communication 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.

Page 34: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

34

Java API for UDP DatagramsExample– The client process creates a socket, bound to the

hostname and server port 6789.(Figure 5)

Page 35: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

35

Java API for UDP DatagramsExample– The server process opens a server socket to its

server port 6789 and listens for connect requests.(Figure 6,7)

Page 36: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

36

TCP Stream Communicationimport 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());}}}

Figure 6. TCP server makes a connection for each client and then echoes the client’s request

Page 37: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

37

TCP Stream Communicationclass 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*/}}}}

Figure 7. TCP server makes a connection for each client and then echoes the client’s request

Page 38: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication The client-server communication is designed to

support the roles and message exchanges in typical client-server interactions.

In the normal case, request-reply communication is synchronous because the client process blocks until the reply arrives from the server.

Asynchronous request-reply communication is an alternative that is useful where clients can afford to retrieve replies later.

Page 39: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication Often built over UDP datagrams Client-server protocol consists of

request/response pairs, hence no acknowledgements at transport layer are necessary

Avoidance of connection establishment overhead

No need for flow control due to small amounts of data are transferred

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

Page 40: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication The request-reply protocol was based on a trio

of communication primitives: doOperation, getRequest, and sendReply shown in Figure 12.

Page 41: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication The request-reply protocol is shown in Figure 12.

Figure 12. Request-reply communication

Page 42: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication The designed request-reply protocol matches requests to

replies. If UDP datagrams are used, the delivery guarantees

must be provided by the request-reply protocol, which may use the server reply message as an acknowledgement of the client request message.

Figure 13 outlines the three communication primitives.

Page 43: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication

Figure 13. Operations of the request-reply protocol

Page 44: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication The information to be transmitted in a request

message or a reply message is shown in Figure 14.

Figure 14. Request-reply message structure

Page 45: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication In a protocol message

The first field indicates whether the message is a request or a reply message.

The second field request id contains a message identifier.

The third field is a remote object reference . The forth field is an identifier for the method to be

invoked.

Page 46: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication Message identifier

A message identifier consists of two parts: A requestId, which is taken from an

increasing sequence of integers by the sending process

An identifier for the sender process, for example its port and Internet address.

Page 47: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication Failure model of the request-reply protocol

If the three primitive doOperation, getRequest, and sendReply are implemented over UDP datagram, they have the same communication failures.

Omission failure Messages are not guaranteed to be

delivered in sender order.

Page 48: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

• Assume that you are developing a client-server application:– How to let the two processes (client and server)

located on two machines communicate with each other?

• Socket programming: using functions like connect(sd, (struct sockaddr *)&sin, sizeof(sin)), write(sd, buf, strlen(buf)) etc.

Client-Server Communication

Page 49: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Remote Procedure Calls (RPC)

• Avoid explicit message exchange between processes• Basic idea is to allow a process on a machine to call

procedures on a remote machine– Make a remote procedure possibly look like a local one

• Original paper on RPC:– A. Birrell, B Nelson, “Implementing Remote Procedure

Calls”, ACM Symposium on Operating System Principles, 1984

Page 50: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

RPC Features

• RPC as a primary communication mechanism for distributed application due to following features:

• Simple• Familiar semantics• Well defined interface• Ease of use• Generality• Efficiency

Page 51: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

RPC Model

Page 52: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

MarshallingValues must cross the networkMachine formats differ

– Integer byte order• Little-endian or big-endian

– Floating point format• IEEE 754 or not

Marshalling transferring data structure used in remote procedure call from one address space to another.

Define a “network format”, for example following XDR (eXternal Data Representation) standard http://www.ietf.org/rfc/rfc1832.txt

Page 53: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Steps of Marshelling

Page 54: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

• Transparency of RPC Trasparent RPC mechanism is one in which

loacal procedures and remote procedures are indistinguishable to programmer

– Syntactic Transparency– Semantic Transparency

Page 55: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Syntactic Transparency

• Syntactic transparency means that a remote procedures call should have exactly the same syntax as a local procedure call.

Page 56: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Semantic transparency

• Semantic transparency is close to impossible• Unlike local procedure calls with remote procedure call ,

the called procedure is executed in an address space that is disjoint from calling program’s address space

• Remote procedure call are more vulnerable to failure than local procedure call due to two different processes and network and two different computer on different location

• RPC consume much more time then local procedure call

Page 57: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

RPC: The basic mechanism

Client routines

Client stub

RPC runtime

Networkroutines

Source: R. Stevens, Unix Network Programming (IPC) Vol 2, 1998

Server routines

Server stub

RPC runtime

Network routines

Processkernel

Processkernel

Client process Server process 1. Client calls a local procedure on the client stub

2. The client stub acts as a proxy and marshalls the call and the args.

3. The client stub send this to the remote system (via TCP/UDP)

4. The server stub unmarshalls the call and args from the client

5. The server stub calls the actual procedure on the server

6. The server stub marshalls the reply and sends it back to the client

1

2

3

4

5

6

Page 58: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Steps of a Remote Procedure Call1. Client procedure calls client stub in normal way2. Client stub builds message, calls local OS3. Client's OS sends message to remote OS4. Remote OS gives message to server stub5. Server stub unpacks parameters, calls server6. Server does work, returns result to the stub7. Server stub packs it in message, calls local OS8. Server's OS sends message to client's OS9. Client's OS gives message to client stub10. Stub unpacks result, returns to client

Page 59: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

RPC Implementation (Birrel et al.)

work

Caller Callee

Callpacket

Result

UserUserstub

RPCruntime

RPCruntime

Serverstub Server

call pckargs

xmitrcv unpk call

returnpckresultxmitrcvunpk

resultreturn

Page 60: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Implementing RPC •Extra compiler pass on code generates stubs– Client/server terminology & thinking

Page 61: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Passing Value Parameters (1)

• Steps involved in doing remote computation through RPC

2-8

Page 62: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client & Server StubStub: • A stub in distributed computing is a piece of code used for converting

parameters passed during a Remote Procedure Call.

• The client and server may also use different data representations even for simple parameters. Stubs are used to perform the conversion of the parameters, so a RemoteFunction Call looks like a local function call for the remotecomputer

RPC Runtime• Hide existence and functional details of underlying n/w and encryption• Responsible for retransmission ,ack, packet routing and encryption• Failure handling rutine

Page 63: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client & Server Stub

Client Stub: Used when read is a remote procedure. Client stub is put into a

library and is called using a calling sequence. It calls for the local operating system. It does not ask for the local operating system to give data, it asks the server and then blocks itself till the reply comes.

Server Stub: when a message arrives, it directly goes to the server stub.

Server stub has the same functions as the client stub. The stub here unpacks the parameters from the message and then calls the server procedure in the usual way.

Page 64: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Stub GenerationManually In this method, the RPC implementer provides a set of

translation functions from which a user can construct his or her own stubs. This method is simple to implement and can handle very complex parameter types.

Automatically: It uses Interface Definition Language (IDL) that is used to define

the interface between a client and a server. An interface definition is mainly a list of procedure namessupported by the interface, together with the types of theirarguments and results.

Page 65: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

RPC Call Msg Format

Msg Identifier Msg Type ArgumentProcedure

NumberVersion number

Client idenifier

Program number

Remote Procedure identifier

Page 66: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Call MessageA call message is used to request execution of a particular remote procedure the two

basic components necessary in a call message are as follows :1. The identification information of the remote procedure to be executed.2. The arguments necessary for the execution of the procedure.

In addition to these two fields, a call message normally has the following fields.3. A message identification field that consists of a sequence number. This field is useful of

two ways – for identifying lost messages and duplicate messages in case of system failures and for properly matching reply messages to outstanding call messages, especially in those cases when the replies of several outstanding call messages arrive out of order.

4. A message type field that is used to distinguish call messages from reply messages. For example, in an RPC system, this field may be set to 0 for all call messages and set to 1 for all reply messages.

5. A client identification field that may be used for two purposes –to allow the server of the RPC to identify the client to whom the reply message has to be returned and to allow the server to check the authentication of the client process for executing the

concerned procedure.

Page 67: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

RPC Reply Msg Format

• Successful msg

• UNSuccessful msg

Msg Identifier Msg Type

Reply status

(successfulResult

Msg Identifier Msg Type

Reply status

(Unsuccessful )

Reason for failure

Page 68: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Marshaling Arguments and result1. Taking the arguments (of a client process) or the result (of a server

process) that will form the message data to be set to the remote process.

2. Encoding the message data of step 1 above on the sender’s computer. This encoding process involves the conversion of program objects into a stream form that is suitable for transmission and placing them into a message buffer.

3. Decoding of the message data on the receiver’s computer. This decoding process involves the reconstruction of program objects from the message data that was received in stream form.

• Order and representation method used to marshal argument and result must be known to both the client and server of the RPC

Page 69: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Server management

Based on the style of implementation used, servers may be of two types

• Stateful • Stateless

Page 70: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Stateful Server

A stateful server maintains clients’ state information from one remote procedure call to the next. That is, in case of two subsequent calls by a client to a stateful server, some state information pertaining to the service performed for the client as a result of the first call execution is stored by the server process.

Page 71: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Stateful File server

Page 72: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Stateless Server

Page 73: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Binding a Client to a Server (1)

• Registration of a server makes it possible for a client to locate the server and bind to it.

• Server location is done in two steps:1.Locate the server’s machine.

2.Locate the server on that machine.

Page 74: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Binding a Client to a Server

Page 75: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

call semantics

• Possibly or may be cal semantics• Last one call• Last of many call• At least once• Exactly once

Page 76: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Call semantics

• Call Semantics of RPC determines how often the remote procedure may be executed unde fault condition depends on this part of RPC runtime

Page 77: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Call Semantics

• Last –one call Semantics

• Last- of- many

• At -least -once

• Exactly- once

• At-Most once

Page 78: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

RPC Semantics 1

• Delivery guarantees.• “Maybe call”:

– Caller waits until a predetermined timeout period and continues with its execution

– Clients cannot tell for sure whether remote procedure was executed or not due to message loss, server crash, etc.

– Usually not acceptable.– Weakest semantics

Page 79: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

RPC Semantics 2

• “At-least-once” call:– Remote procedure executed at least once, but

maybe more than once.– Retransmissions but no duplicate filtering.– Idempotent operations OK; e.g., reading data that

is read-only.

Page 80: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

RPC Semantics 3

• “exactly-once” call– Most appropriate for non-idempotent operations.– Remote procedure executed 0 or 1 time, ie, exactly once or

not at all.– Use of retransmissions and duplicate filtering.– Example: Birrel et al. implementation.

• Use of probes to check if server crashed.

Page 81: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Call Semantics

• At-most-once call semantics

– When a RPC returns, it can assumed that the remote procedure (RP) has been called exactly once or not at all.

– Implemented by the server's filtering of duplicate requests (which are caused by retransmissions due to IPC failure, slow or crashed server) and caching of replies (in reply history, refer to RRA protocol).

Page 82: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

• Last-One Call Semantics– Killing all orphan calls before restarting a new call

• Last-of-Many Call Semantics– Neglecting all orphan calls using identifiers

Page 83: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication RPC exchange protocols

Three protocols are used for implementing various types of RPC.

The request (R) protocol. The request-reply (RR) protocol. The request-reply-acknowledge (RRA)

protocol.(Figure 15)

Page 84: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication

Figure 15. RPC exchange protocols

Page 85: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication In the R protocol, a single request message is

sent by the client to the server. The R protocol may be used when there is no

value to be returned from the remote method. The RR protocol is useful for most client-server

exchanges because it is based on request-reply protocol.

RRA protocol is based on the exchange of three messages: request-reply-acknowledge reply.

Page 86: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

RRA Protocol

• In the RRA protocol, there is a possibility that the acknowledgement message may itself get lost. • Therefore implementation of the RRA protocol requires that

the unique message identifiers associated with request messages must be ordered.

• Each reply message contains the message identifier of the corresponding request message, and each acknowledgement message also contains the name same message identifier.

• This helps in matching a reply with its corresponding request and an acknowledgement with its corresponding reply.

Page 87: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

COMMUNICATION PROTOCOLS FOR RPCS

Page 88: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication HTTP: an example of a request-reply

protocol HTTP is a request-reply protocol for the

exchange of network resources between web clients and web servers.

Page 89: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication HTTP protocol steps are:

Connection establishment between client and server at the default server port or at a port specified in the URL

client sends a request server sends a reply connection closure

Page 90: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication HTTP 1.1 uses persistent connections.

Persistent connections are connections that remains open over a series of request-reply exchanges between client and server.

Resources can have MIME-like structures in arguments and results.

Page 91: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication A Mime type specifies a type and a

subtype, for example: text/plain text/html image/gif image/jpeg

Page 92: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication HTTP methods

GET Requests the resource, identified by URL as

argument. If the URL refers to data, then the web server replies

by returning the data If the URL refers to a program, then the web server

runs the program and returns the output to the client.

Figure 16. HTTP request message

Page 93: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication HEAD

This method is similar to GET, but only meta data on resource is returned (like date of last modification, type, and size)

Page 94: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication POST

Specifies the URL of a resource (for instance, a server program) that can deal with the data supplied with the request.

This method is designed to deal with:• Providing a block of data to a data-handling

process• Posting a message to a bulletin board, mailing

list or news group.• Extending a dataset with an append operation

Page 95: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication PUT

Supplied data to be stored in the given URL as its identifier.

DELETE The server deletes an identified resource by

the given URL on the server. OPTIONS

A server supplies the client with a list of methods.

It allows to be applied to the given URL

Page 96: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication TRACE

The server sends back the request message

Page 97: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Client-Server Communication A reply message specifies

The protocol version A status code Reason Some headers An optional message body

Figure 17. HTTP reply message

Page 98: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Group Communication

• RPC can have one-to-one communication (unicast) one-to-many communication (multicast) and one-to-all communication (broadcast).

• Multicasting can be implemented using broadcast. Each machine receives a message. If the message is not for this machine, then discard.

Page 99: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Group Communication

• Closed groups: only the member of the group can send messages to the group. Outsiders cannot.

• Open groups: any process in the system can send messages to the group.

• Peer group: all the group members are equal. Advantage: symmetric and has no single point of failure. Disadvantage: decision making is difficult. A vote has to be taken.

• Hierarchical group: coordinatorAdvantage and disadvantage: opposite to the above

Page 100: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Group Communication The pairwise exchange of messages is not

the best model for communication from one process to a group of other processes.

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.

Page 101: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Group Communication The simplest way of multicasting, provides

no guarantees about message delivery or ordering.

Multicasting has the following characteristics:

Fault tolerance based on replicated services

A replicated service consists of a group of servers.

Page 102: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Group Communication 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.

Page 103: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Group Communication 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.

Page 104: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Group Communication IP multicast

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.

Page 105: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Group Communication 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.

Page 106: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Group Communication 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.

Page 107: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Group Communication 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.

Page 108: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Group Communication Java API to IP multicast

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.

(

Page 109: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Group Communication 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.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

Page 110: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Group Membership Management

• Centralized way: group server maintains a complete data base of all the groups and their exact membership.

Advantage: straightforward, efficient, and easy to implement.Disadvantage: single point of failure.

• Distributed way: an outsider sends to message to all group members to join and sends a goodbye message to everyone to leave.

Page 111: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Group Addressing

• A process just sends a message to a group address and it is delivered to all the members. The sender is not aware of the size of the group or whether communication is implemented by multicasting, broadcasting, or unicasting.

• Require the sender to provide an explicit list of all destinations (e.g., IP addresses).

• Each message contains a predicate (Boolean expression) to be evaluated. If it is true, accept; If false, discard.

Page 112: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Send and Receive Primitives

• If we wish to merge RPC and group communication, to send a message, one of the parameters of send indicates the destination. If it is a process address, a single message is sent to that one process. If it is a group address, a message is sent to all members of the group.

Page 113: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Atomicity

• How to guarantee atomic broadcast and fault tolerance?

• The sender starts out by sending a message to all members of the group. Timers are set and retransmissions sent where necessary. When a process receives a message, if it has not yet seen this particular message, it, too, sends the message to all members of the group (again with times and retransmissions if necessary). If it has already seen the message, this step is not necessary and the message is discarded. No matter how many machines crash or how many packets are lost, eventually all the surviving processes will get the message.

Page 114: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Message Ordering

• Use global time ordering, consistent time ordering.

Page 115: Inter Process Commonication. 2 Introduction  The java API for interprocess communication in the internet provides both datagram and stream communication.

Overlapping Groups

• Overlapping groups can lead to a new kind of inconsistency.

A

C

B

D

12

34

Group 1 Group 2