Lecture 5:
Interprocess Communication
Week 4
Dr Solomon Mensah
Reference
Chapter 4
of
Coulouris G., Dollimore J., Kindberg T., Blair G., “Distributed
Systems: Concepts and Design”, 5 th Edition, Addison-Wesley,2012
Learning Outcomes
While this lecture does not exactly conform to the learning
outcomes mentioned below (as in module specification), it forms
basis for achieving them
• Understand the client -server paradigm and the role of
middleware technology and be able to relate these to the
concepts introduced in the practical stream
• Have a good understanding of RPC, its role in middleware,
issues in its design (e.g. transparency), and how it is
implemented
• Compare the RPC service with alternatives such as publish -
subscribe or distributed sharedmemory
Introduction
• We study the communication aspects of middleware, while the
principles discussed are more widely applicable
Characteristics of interprocess
communication
• Message passing between a pair of processes is achieved by
two operations; send and receive
• A queue is associated with each message destination.
• Sending processes cause messages to be added to remote
queues and receiving processes remove messages from their
local queues
SENDER RECEIVER
process process
Characteristics of interprocess
communication
• Communication between a pair of processes mayeither be
synchronous or asynchronous.
• Synchronous: both send and receive are blocking operations
• Asynchronous: send is non-blocking and receive can be blocking
or non-blocking (complex to implement, rarely used)
. send() .
send()
. . .
continue
. . .
.
blocked .
. receive() receive()
.
. blocked blocked
continue . .
. . .
. . .
Synchronous communication Asynchronous communication (blocking receive)
Characteristics of interprocess
communication
• Message destinations:
Messages are sent to <Internet address, local port> pairs
A local port is a message destination within a computer,
specified as an integer
A port has one receiver (unlike in multicasting) but can have
many senders
Processes may use multiple ports to receive messages
Servers generally publicize their port numbers for use by clients
• Client programs refer to services by name and use a name
server or binder to translate it into server location at runtime
Characteristics of interprocess
communication
• Reliability:
Reliable Communication Unreliable Communication
maintains maintains
Validity Integrity No Integrity
No validity
Guaranteed Uncorrupted, Corrupted,
delivery not
delivery No duplication duplication
guaranteed
despite
even with
‘reasonable’
single packet
number of
loss
packet loss
Characteristics of interprocess
communication
• Ordering:
Some applications require that messages be delivered in sender
order
The delivery of messages out of sender order is regarded asa
failure by such applications
Sockets
• Programming abstraction
• Endpoint for communication between processes
• A socket is associated with either UDP or TCP
• To receive messages, socket must be bound to a local port and
one of the Internet addresses of the computer on which it runs
• Processes may use the same socket for sending and receiving
messages
Sockets
Sockets and ports
Internet Protocols (Transport):
UDP andTCP
• TCP and UDP provide the communication capabilities of the
Internet in a form that is useful for application programs
• IP (Network layer) supports communication between pairs of
computers (identified by their IP addresses)
• TCPand UDP (transport layer) provide process-to-process
communication by means of ports
UDPcommunication
• A datagram is transmitted between processes when
one process sends it and another receives it
• Sockets are created by processes to send and receive
datagrams
• A server will bind its socket to a server port
• A client binds its socket to any free local port
• The receive method returns the Internet address and port of
the sender, in addition to the message, allowing the recipient to
send a reply
• No acknowledgement or retries
UDPcommunication
• Issues:
Message Size: Abyte array of particular size must be specified
by the receiving process. Larger messages are fragmented
Blocking: Sockets normally provide non-blocking sends and
blocking receives for datagram communication
Timeouts: To avoid indefinite blocking of a process that has
invoked a receive operation timeouts can be set on sockets
Receive from any: An invocation of receive gets a message
addressed to its socket from any origin.
UDPcommunication
• Failure Model:
• UDP suffer from omission failures and ordering failures
• Omission: Messages may be dropped occasionally, either
because of a checksum error or because no buffer space is
available at the source (send-omission) or destination (receive-
omission)
• Ordering: Messages may be delivered out of sender order
• Applications using UDP can provide their own checks to achieve
the quality of reliable communication
• Use of acknowledgements is a solution to construct reliable
delivery service from the one suffering from omission failure
UDPcommunication
• Uses:
UDP is used where occasional omission failures are acceptable
– e.g. DNSservice, Voice Over IP(VOIP)
Do not suffer from the overheads associated with guaranteed
delivery
– the need to store state information at thesource and destination
– the transmission of extra messages
– latency for the sender
TCPstream communication
• Provides the abstraction of a stream of bytes to which data
may be written and from which data may be read
• During the process of establishing a connection, one of the
processes plays the client role and the other the server role
• Once the connection is established they could be peers
• The client creates a stream socket bound to any port and then
makes a connect request to a server at its server port.
• The server creates a listening socket bound to a server port and
waiting for clients to request connections
• Upon accepting a connection, a new stream socket is created
by server to communicate with a client
TCPstream communication
• One of the pair of processes can send information to the other
by writing to its output stream, and the other process obtains
the information by reading from its input stream
• When an application closes a socket, this indicates that it will
not write any more data to its output stream
• When a process exits or fails, all of its sockets are eventually
closed and any process attempting to communicate with it
will discover that its connection has been broken
TCPstream communication
• The following characteristics of the network are hidden by
the stream abstraction
– Message sizes: Application can choose the amount of data it
writes to a stream or reads from it
– Lost messages: TCP uses an acknowledgement. After a timeout
for acknowledgement the message is retransmitted
– Flow control: TCP attempts to match the speeds of the
processes that read from and write to a stream
– Message duplication and ordering: Uses message identifiers in IP
packet to detect and reject duplicates, or to reorder messages
that do not arrive in sender order
– Message destinations: Once a connection is established, the
processes need not use Internet addresses and ports
TCP stream communication
• Issues:
Matching of data items: Processes need to agree upon the
contents of the data transmitted over a stream
Blocking: When a process attempts to read data from an input
channel, it will get data from the queue or it will block until
data becomes available. The process that writes data to a
stream may be blocked by the TCP flow-control mechanism
Threads: When a server accepts a connection, it generally
creates a new thread to communicate with the new
client
TCPstream communication
• Failure model:
Integrity: TCPstreams use checksums to detect and reject
corrupt packets and sequence numbers to detect and reject
duplicate packets
Validity: TCPstreams use timeouts and retransmissions to
deal with lost packets. So, messages are guaranteed to be
delivered
Non-receipt of acknowledgements by the TCPsoftware
responsible for sending messages after a time, makes it to
declare the connection as broken.
TCP stream communication
• Uses:
• Many frequently used services run over TCPconnections,
with reserved port numbers;
– HTTP: Used for communication between web browsers and web
servers
– FTP: Allows directories on a remote computer to be browsed
and files to be transferred from one computer to another
– Telnet: Provides access by means of a terminal session to a
remote computer
– SMTP: Used to send mail between computers
TCP vs UDP
Description TCP UDP
Full form Transmission Control Protocol User Datagram Protocol
Connection oriented, Stream Connectionless, datagram
Type
based based
Header Size 20 Bytes 8 Bytes
Data transfer Slower Faster
Reliable (delivery guaranteed Unreliable
Reliability by retransmission, sequencing, (delivery not guaranteed
flow control, checksum) except optional checksum)
Communication Unicasting
Unicast Multicast Broadcast
Application Email, Web browsing VoIP, Music streaming
https://www.diffen.com/difference/TCP_vs_UDP
External data representation and
marshalling
• Marshaling is the process of transforming the memory representation of an object
to a data format suitable for storage or transmission, and it is typically used when
data must be moved between different parts of a computer program or from one
program to another.
• The data to be transferred between a pair of hostsmay be
– stored in different orders
e.g. big-endian and little-endian order for integers
– represented in differentways
e.g. different architectures use different floating -point number
representations
– using different set of codes for characterrepresentation
e.g. ASCII, Unicode
• Irrespective of the form of communication used, the data structures must be
flattened (converted to a sequence of bytes) before transmission and rebuilt on
arrival
External data representation and
marshalling
• One of the following methods can be used toenable any two
computers to exchange binary data values:
– The values are converted to an agreed external format before
transmission and converted to the local form on receipt; if the
two computers are known to be the same type, the conversion
to external format can be omitted
– The values are transmitted in the sender’s format, together with
an indication of the format used, and the recipient converts the
values if necessary
• An agreed standard for the representation of data structures
and primitive values is called an external data representation
External data representation and
marshalling
• Marshalling is the process of taking a collection of data items
(primitive type or data structures) and assembling them into a
form suitable for transmission (external data representation) in
a message
• Unmarshalling is the process of disassembling them on arrival
to produce an equivalent collection of dataitems at the
destination
External data representation and
marshalling
• Design issues for marshalling:
– Compactness of the marshalled data
– Whether marshalled data should include information concerning
the type of its contents
• e.g. CORBA’s representation includes just the values of the objects
transmitted and both Java serialization and XML includes type
information
• Two more approaches to external data representation called
protocol buffers (used by Google) and JSON(JavaScript Object
Notation) are also in use
External data representation and
marshalling
Java ObjectSerialization:
• In Java RMI, both objects and primitive data valuesmay be
passed as arguments and results of method invocations
• Serialization refers to flattening of an object (or a connected
set of objects) into a serial form that is suitable for storing on
disk or transmitting in a message
• Deserialization consists of restoring the state of an object or a
set of objects from their serialized form
A Java class has to implement Serializable interface for allowing
its instances to beserialized
External data representation and
marshalling
Java ObjectSerialization:
• Serialized form of an object contains it’s class name and a
version number, used by the recipient to load the appropriate
class during deserialization
• After the class information, the types and names of the object’s
instance variables are written recursively
• When an object is serialized, all the objects that itreferences
are serialized together with it as handles
Multicast communication
• Multicasting involves sending a single message from one
process to a group of processes
• Group membership of a process is transparent to the sender
• Useful when a service is implemented as a number of different
processes in different computers
• What is the difference between Multicasting and Broadcasting?
Multicast communication
Useful for constructing distributed systems thatrequire
• Fault tolerance based on replicated services
• Discovering services in spontaneous networking
• Better performance through replicated data
• Propagation of event notifications
Multicast communication
IP multicast:
• IP multicast is built on top of the Internet Protocol (IP)
• Allows the sender to transmit a single IP packet to a set of
computers that form a multicast group
• The sender is unaware of the identities of the individual
recipients and of the size of the group
• IP multicast is available only via UDP
• Datagrams multicast over IP multicast have the same failure
characteristics as UDP datagrams – that is, they suffer from
omission failures (may result in unreliable multicast)
• The JavaAPI provides a datagram interface to IP multicast with
the class MulticastSocket, a subclass of DatagramSocket
Network Virtualization
• Network virtualization is concerned with the construction of
many different virtual networks over an existing network such
as the Internet
• Each virtual network can be designed to support a particular
distributed application
– e.g. one virtual network might support multimedia streaming and
coexist with another that supports a multiplayer online game,
both running over the same underlying network
• Each virtual network has its own particular addressing scheme,
protocols and routing algorithms, but redefined to meet the
needs of particular application classes
Network Virtualization:
Overlay Networks
• An overlay network is a virtual network consisting of nodes and
virtual links, which sits on top of an underlying network (such
as an IP network) and offers something that is not otherwise
provided
• Example services:
– a service that is tailored towards the needs of a class of
application or a particular higher-level service – for example,
multimedia content distribution
– more efficient operation in a given networked environment – for
example routing in an ad hoc network;
– an additional feature – for example, multicast or secure
communication.
Casestudy
• Skype (peer-to-peer) example for overlay network
• Message Passing Interface (MPI) for the concepts of
interprocess communication
Questions and Discussion…
Thank you