1
1
Communication Networks:
Local Area Network (LAN): Connects nodes in a limited geographical area, such as a single
building or campus.
Wide Area Network (WAN): Spans a larger geographic area, connecting nodes across cities,
countries, or continents.
Internet: A global network of interconnected networks, enabling communication between nodes
worldwide.
Intranet: A private network within an organization that uses internet technologies for internal
communication.
Wireless Networks: Use radio waves or infrared signals for communication, including Wi-Fi,
Bluetooth, and cellular networks.
Satellite Networks: Communication through satellites, suitable for remote or geographically
dispersed areas.
Sensor Networks: Networks of interconnected sensors that collect and transmit data from the
physical world.
Overlay Networks: Virtual networks created on top of existing networks to provide specific
services, such as content delivery networks (CDNs).
Peer-to-Peer Networks: Nodes communicate directly with each other, without a central server,
common in P2P file-sharing systems.
Understanding these communication primitives and networks is crucial for designing and
implementing effective distributed systems, ensuring efficient and reliable communication
between nodes. The choice of communication mechanisms depends on factors like system
requirements, latency constraints, fault tolerance, and scalability needs.
Top of Form
Take the starting value as 1, since it is the 1st event and there is no incoming value at the starting
point:
e11 = 1
e21 = 1
The value of the next point will go on increasing by d (d = 1), if there is no incoming value i.e.,
to follow [IR1].
e12 = e11 + d = 1 + 1 = 2
e13 = e12 + d = 2 + 1 = 3
e14 = e13 + d = 3 + 1 = 4
e15 = e14 + d = 4 + 1 = 5
e16 = e15 + d = 5 + 1 = 6
e22 = e21 + d = 1 + 1 = 2
e24 = e23 + d = 3 + 1 = 4
e26 = e25 + d = 6 + 1 = 7
When there will be incoming value, then follow [IR2] i.e., take the maximum value
between Cj and Tm + d.
e17 = max (7, 5) = 7, [e16 + d = 6 + 1 = 7, e24 + d = 4 + 1 = 5, maximum among 7 and 5 is 7]
e23 = max (3, 3) = 3, [e22 + d = 2 + 1 = 3, e12 + d = 2 + 1 = 3, maximum among 3 and 3 is 3]
e25 = max (5, 6) = 6, [e24 + 1 = 4 + 1 = 5, e15 + d = 5 + 1 = 6, maximum among 5 and 6 is 6]
Limitation:
In case of [IR1], if a -> b, then C(a) < C(b) -> true.
In case of [IR2], if a -> b, then C(a) < C(b) -> May be true or may not be true.
C
// C program to illustrate the Lamport's
// Logical Clock
#include <stdio.h>
// Function to find the maximum timestamp between 2 events
int max1(int a, int b)
{
// Return the greatest of the two
if (a > b)
return a;
else
return b;
}
// Driver Code
int main ()
{
int e1 = 5, e2 = 3, m[5][3];
Vector Clock
Vector Clock is an algorithm that generates partial ordering of events and detects causality
violations in a distributed system. These clocks expand on Scalar time to facilitate a causally
consistent view of the distributed system; they detect whether a contributed event has caused
another event in the distributed system. It essentially captures all the causal relationships. This
algorithm helps us label every process with a vector (a list of integers) with an integer for each
local clock of every process within the system. So for N given processes, there will be vector/
array of size N.
Working of vector clock algorithm:
Initially, all the clocks are set to zero.
Every time, an Internal event occurs in a process, the value of the processes’ logical clock in the
vector is incremented by 1
Also, every time a process sends a message, the value of the processes’ logical clock in the
vector is incremented by 1.
Every time, a process receives a message, the value of the processes’ logical clock in the vector
is incremented by 1, and moreover, each element is updated by taking the maximum of the value
in its own vector clock and the value in the vector in the received message (for every element).
Example: Consider a process (P) with a vector size N for each process: the above set of rules
mentioned are to be executed by the vector clock:
The above example depicts the vector clocks mechanism in which the vector clocks are updated
after execution of internal events, the arrows indicate how the values of vectors are sent in
between the processes (P1, P2, P3).
To sum up, Vector clocks algorithms are used in distributed systems to provide a causally
consistent ordering of events but the entire Vector is sent to each process for every message sent,
in order to keep the vector clocks in sync.
How to achieve mutual exclusion with non-token based algorithms for distributed systems?
Achieving mutual exclusion in a distributed system without using tokens (token-based
algorithms often involve passing a special token among processes to control access to a critical
section) can be challenging but is certainly possible. Non-token-based algorithms typically rely
on other mechanisms, such as logical clocks or timestamps, to coordinate processes and enforce
mutual exclusion. Here's an overview of two well-known non-token-based algorithms for
achieving mutual exclusion:
Ricart-Agrawala Algorithm: Proposed by Glenn Ricart and Ashok Agrawala, this algorithm is
designed to achieve mutual exclusion in a distributed system without using tokens.
It is based on the concept of requesting and receiving permission from other processes before
entering a critical section.
Algorithm Steps:
Requesting Permission: When a process wants to enter the critical section, it sends a request to
all other processes in the system. The request includes the process's timestamp or logical clock
value.
Receiving Permission: When a process receives a request, it replies with permission if it is not
currently in its critical section or if the requesting process has a higher priority (determined by
timestamp or logical clock). If the process is currently in the critical section, it queues the
incoming request.
Entering Critical Section: A process can enter the critical section when it has received replies
from all other processes, granting permission.
Exiting Critical Section: After completing the critical section, the process sends release messages
to all queued requests, allowing them to enter their critical sections.
Properties:
Mutual exclusion is achieved because a process can only enter the critical section when it has
received permission from all other processes.
Deadlock-free, but it assumes a reliable communication network.
Maekawa's Algorithm: Proposed by M. Maekawa, this algorithm is designed to achieve mutual
exclusion with a reduced number of messages compared to Ricart-Agrawala. It uses a voting
mechanism among a subset of processes.
Algorithm Steps:
Requesting Votes: When a process wants to enter the critical section, it sends a request to a
subset of processes. The subset is determined based on a predefined set of relationships between
processes.
Voting: Each process in the subset votes on whether the requesting process can enter the critical
section. A majority of positive votes are required for permission.
Entering Critical Section: The requesting process can enter the critical section if it receives a
majority of positive votes.
Exiting Critical Section:
After completing the critical section, the process sends release messages to the processes that
voted positively, allowing them to enter their critical sections.
Properties:
Mutual exclusion is achieved through a voting mechanism.
Reduces the number of messages compared to Ricart-Agrawala.