Lecture 2 – Distributed
Systems
Inter-process communication
• Interprocess communication (IPC) is a set of programming interfaces
that allow a programmer to coordinate activities among different
program processes that can run concurrently in an operating system
• Consists of two Models :message passing and shared memory
• In shared memory model a region of memory is shared by the
cooperating process. Processes can then exchange information by
reading and writing data to the shared region.
• In the message-passing model, communication takes place by means
of messages exchanged between the cooperating processes.
• Message passing is easier to implement in a distributed system than
shared memory.
• The shared memory is faster than that of message passing.
Shared memory example
• A producer process produces information that is consumed by a
consumer process.
• To allow producer and consumer processes to run concurrently, we
must have available a buffer of items that can be filled by the
producer and emptied by the consumer.
• This buffer will reside in a region of memory that is shared by the
producer and consumer processes.
• A producer can produce one item while the consumer is consuming
another item.
IPC
• Message passing between a pair of processes supported by two
communication operations: send and receive
• In order for one process A to communicate with another process B:
• A sends a message (sequence of bytes) to a destination
• Another process at the destination (B) receives the message
• This activity involves the communication of data from the sending
process to the receiving process and may involve the synchronization
of the two processes
Sending VS Receiving
• A queue is associated with each message destination
• Sending processes cause messages to be added to remote queues
• Receiving processes remove messages from local queues
Message Destinations?
• Usually take the form (address, local port)
• For instance, in the Internet protocols messages are sent to (Internet address,
local port) pairs
• Local port: message destination within a computer, specified as an
integer. It is commonly used to identify a specific service (ftp, ssh, .
• A port has exactly one receiver but can have many senders
• Processes may use multiple ports from which to receive messages
• Any process that knows the number of a port can send a message to
it
Socket Abstraction
• At the programming level, message destinations can usually be
defined by means of the concept of socket
A socket is an abstraction which provides an endpoint for
communication between processes
• A socket address is the combination of an IP address (the location of
the computer) and a port (a specific service) into a single identity
• Interprocess communication consists of transmitting a message
between a socket in one process and a socket in another process
• Messages sent to a particular Internet address and port number can
be received only by a process whose socket is associated with that
Internet address and port number
• Processes may use the same socket for sending and receiving
messages
• Any process may make use of multiple ports to receive messages, BUT
a process cannot share ports with other processes on the same
computer
• Each socket is associated with a particular protocol, either UDP or TCP
• For instance, consider online shopping sites - each
component involved (user interface, product database
server, payment gateway) needs to interact efficiently
with others in real-time; hence efficient IPC via message
passing becomes critical for smooth functioning and
user experience
Message Passing in Distributed Systems
• It involves the sending process creating and enqueuing
a message to be delivered to the receiving process
• The receiving process then dequeues and handles the
message accordingly.
• This method provides an asynchronous way of
communicating between different components of a
distributed operating system.
Example
• If two processes p1 and p2 want to communicate with each other,
they proceed as follows:
• Establish a communication link (if a link already exists, no need to establish it
again.)
• Start exchanging messages using basic primitives.
• We need at least two primitives
• send(message, destination) or send(message)
• receive(message, host) or receive(message)
• The message size can be of fixed size or of variable size. If it is of fixed
size, it is easy for an OS designer but complicated for a programmer
and if it is of variable size then it is easy for a programmer but
complicated for the OS designer.
• A standard message can have two parts: header and body.
• The header part is used for storing message type, destination id,
source id, message length, and control information. The control
information contains information like what to do if runs out of buffer
space, sequence number, priority.
• Generally, message is sent using FIFO style.
Message Passing through
Communication Link
• It can be direct or indirect
• Always consider:
• How are links established?
• Can a link be associated with more than two processes?
• How many links can there be between every pair of communicating
processes?
• What is the capacity of a link? Is the size of a message that the link
can accommodate fixed or variable?
• Is a link unidirectional or bi-directional?
• A link has some capacity that determines the number of messages
that can reside in it temporarily for which every link has a queue
associated with it which can be of zero capacity, nonzero capacity or
unbounded capacity.
• In zero capacity, the sender waits until the receiver informs the
sender that it has received the message.
• In non-zero capacity cases, a process does not know whether a
message has been received or not after the send operation.
• Implementation of the link depends on the situation, it can be either
a direct communication link or an in-directed communication link
• Direct Communication links are implemented when the processes
uses a specific process identifier for the communication, but it is hard
to identify the sender ahead of time. Example?
• In-direct Communication is done via a shared mailbox (port), which
consists of a queue of messages. The sender keeps the message in
mailbox and the receiver picks them up example?
Types of Message Passing
• There are two main types of message passing in
distributed systems, namely synchronous and
asynchronous
• Synchronous Message Passing:
This type of message passing ensures that the sending process
blocks until the receiver receives the message. It is suitable for
situations where synchronization is important and requires an
immediate response. Project managing software(videos)
• Asynchronous Message Passing:
In this type of message passing, the sending process does not
wait for the receiver to receive the message or respond to it
immediately example?
Instead, it continues with its work, assuming that the message
will be delivered correctly
• Asynchronous messaging is useful in situations where a
delay in receiving a response from the receiver is
acceptable or when dealing with large volumes of data.
• By understanding these different types of message
passing, developers can make informed decisions on
which approach to use based on their specific needs
and requirements.
Common issues with IPC by
Message Passing
Issues continued….
Features of Good Message Passing in
Distributed System
• Reliability
Reliability is one of most important features of message
passing in distributed systems. Messages should be
delivered to intended recipient, even in presence of
failures, network delays, and other issues.
A reliable message passing system should provide
guarantees that messages will be delivered in a timely
manner, without being lost, duplicated, or reordered
Several techniques can be used to achieve reliable
message delivery:
Features
Continued…
• Scalability
Scalability is another important feature of message
passing in distributed systems. A scalable message
passing system should be able to handle increasing
amounts of data, traffic, and users without degrading
performance or reliability. Several techniques can be
used to achieve scalability −
Scalability techniques
• Flexibility
Flexibility is another feature of good message passing in
distributed systems. A flexible message passing system
should allow for different types of messages, data
formats, and protocols, to accommodate needs of
different applications and users. Several techniques can
be used to achieve flexibility
• Security
Security is a critical feature of message passing in
distributed systems. A secure message passing system
should protect messages from unauthorized access,
interception, or modification. Several techniques can be
used to achieve security
• Fault tolerance
Fault tolerance is a key feature of good message passing
in distributed systems. system should be able to handle
failures of nodes, networks, and other components,
without losing messages or data. Several techniques can
be used to achieve fault tolerance −
Shared memory
• Shared memory is a memory shared between all processes
by two or more processes established using shared memory.
• This type of memory should protect each other by
synchronizing access between all processes.
• Both processes, like A and B, can set up a shared memory
segment and exchange data through this shared memory
area. Shared memory is important for these reasons-
• It is a way of passing data between processes.
• Shared memory is much faster and more reliable.
• Shared memory allows two or more processes to share the same
copy of the data
• Suppose process A wants to communicate with
process B and needs to attach its address space to this
shared memory segment.
• Process A will write a message to the shared memory,
and Process B will read that message from the shared
memory.
• So, processes are responsible for ensuring
synchronization so that both processes do not write to
the same location at the same time
TCP
• TCP guarantees delivery of data and also guarantees that packets will
be delivered in the same order in which they were sent.
• TCP is a connection-oriented protocol, which means a connection is
established and maintained until the application programs at each
end have finished exchanging messages
–its uses
• HTTP:-The Hypertext Transfer Protocol is used for communication
between web browsers and web servers.
• FTP: The File Transfer Protocol allows directories on a remote
computer to be browsed and files to be transferred from one
computer to another over a connection.
• Telnet: Telnet provides access by means of a terminal session to a
remote computer.
• SMTP: The Simple Mail Transfer Protocol is used to send mail between
computers
Summary
• In conclusion, IPC by message passing is an essential component of
distributed systems that enables efficient communication between
subsystems. However, it also presents various challenges such as
synchronization issues, failure handling, and security concerns.
• To address these issues, proper protocol design for reliable messaging
and implementation of synchronization techniques are necessary.
• Additionally, ensuring secure message passing is crucial to prevent
any unauthorized access to the system. As technology advances in the
future, addressing these correctness issues will be even more
important in building robust and scalable distributed systems that can
effectively handle increasing network loads and data processing
requirements.