Unit 5 Distributed Systems
Unit 5 Distributed Systems
o RNi[j]: The largest sequence number received by site Si from site Sj via
a REQUEST message. This reflects the most recent request made by Sj
o LN[j]: The sequence number of the most recently executed request for
the critical section from site Sj . This is updated when a site releases the
critical section.
3. Queue Q
o The queue holds the IDs of sites that are waiting for the token. These
are processes that have outstanding requests but are yet to receive the
token.
Algorithm Steps:
If a site Si wants to enter the critical section but does not hold the token, it follows
these steps:
o This indicates that Si is making a new request for the critical section.
o This ensures that SjS_jSj tracks the most recent request from Si.
Once a site Si receives the token, it can enter the critical section immediately and
execute its critical section code.
After finishing execution in the critical section, the site Si releases the critical section
by performing the following:
1. Update LN[i]:
o This update indicates that the request associated with RNi[i] has now
been executed.
o For every site Sj whose ID is not in the token queue QQQ, Si appends
Sj's ID to QQQ if: RNi[j]=LN[j]+1RNi[j] = LN[j] + 1RNi[j]=LN[j]+1
o This condition indicates that Sj has made an outstanding request for the
critical section.
o If the queue QQQ is non-empty, Si pops a site ID from the queue and
sends the token to the site indicated by the popped ID.
o If the queue QQQ is empty, Si keeps the token for future use.
Message Complexity
1. Zero messages:
o If the site already holds the idle token when it requests entry into the
critical section, no messages need to be exchanged. The site can directly
enter the CS.
2. Maximum N messages:
o If the requesting site does not have the token, a total of N messages
are exchanged:
Thus, in the worst-case scenario, it takes N messages per critical section execution.
Models of Deadlocks
• In this model, a process can have at most one outstanding request for a
single unit of a resource.
2. AND Model
• A process becomes active only after receiving a message from each process in
its dependent set.
• The out-degree of a node in the WFG for this model can be more than 1.
• A cycle in the WFG indicates a deadlock, but a process may still be deadlocked
even if it's not part of a cycle.
3. OR Model
• A process can make requests for multiple resources, and the request is fulfilled
if any one of the resources is granted.
• In this model, the presence of a cycle in the WFG does not necessarily imply a
deadlock.
1. It is blocked.
4. p-out-of-q Model
• This is a variation of the AND-OR model, where a request can be fulfilled by
obtaining any k resources from a pool of n resources.
5. Unrestricted Model
• This model is the most general and allows a separation of concerns between
the properties of the problem (e.g., stability and deadlock) and the actual
computations of the distributed system(models of deadlocks).
A deadlock occurs when a set of processes is stalled because each process is holding
a resource and waiting for another process to acquire another resource. In the diagram
below, for example, Process 1 is holding Resource 1 while Process 2 acquires Resource
2, and Process 2 is waiting for Resource 1.
The system model for deadlock detection in distributed systems provides a framework
for understanding how processes, resources, and communication interact in order to
detect and resolve deadlocks. In distributed systems, resources are distributed across
multiple nodes, and processes may request resources from remote nodes, making
deadlock detection more complex than in centralized systems. The system model is
defined by the following key components:
• Resources are distributed across nodes, and these resources can be shared by
processes running on different nodes. Resources may include hardware devices,
files, or memory, among others.
• A process can request one or more resources, and it can proceed only when all
the requested resources are granted. If any of the requested resources are
unavailable, the process waits.
• Each node has its own local resource manager that handles resource allocation
for processes on that node. The local resource manager tracks which resources
are held by which processes and manages resource requests and releases.
• When a process requests a resource that is not available (i.e., the resource is
already allocated to another process), the requesting process is placed in a
waiting state until the resource becomes available.
• Each node maintains a local Resource Allocation Graph (RAG) to track the
state of resource allocations and waiting processes.
• The local RAG can be simplified into a Wait-For Graph (WFG), where:
o Nodes represent processes.
• Local Deadlock Detection: Each node has a local deadlock detector that
checks its local WFG for cycles, which indicate potential deadlocks. This
detection mechanism runs periodically to ensure timely detection.
• Global Deadlock Detection: Since deadlocks may span multiple nodes, the
system must coordinate to detect global deadlocks. This is done by collecting
information from each node’s local WFG and combining it into a global Wait-
For Graph (global WFG).
Deadlock Resolution:
• Once a deadlock is detected, the system must resolve it. There are several
approaches for deadlock resolution in distributed systems:
o Rollback: Some processes are rolled back to a safe state before they
made their request, freeing up resources for other processes.
Continuous Monitoring and Verification:
1.Deadlock Prevention:
This approach ensures that the system is structured in such a way that deadlocks
cannot occur by avoiding at least one of the four necessary conditions (mutual
exclusion, hold and wait, no preemption, circular wait).
Techniques include:
2.Deadlock Avoidance:
This strategy involves making runtime decisions about resource allocation to avoid
deadlock. A well-known algorithm is Banker’s Algorithm, which assesses if resource
allocation leads to a safe state.
The system examines each request to ensure it will not result in a deadlock before
granting resources.
3.Deadlock Detection and Recovery:
The system allows deadlocks to occur but periodically checks for them using
algorithms that detect cycles in Wait-For Graphs (WFGs).
Process Termination: One or more processes involved in the deadlock are killed.
Resource Preemption: Resources held by some processes are forcibly taken away and
allocated to others to resolve the deadlock.
4.Deadlock Ignorance:
Some systems, like most operating systems, use a "deadlock avoidance by ignoring"
strategy, where deadlocks are assumed to be rare and left unchecked. This is known
as the ostrich algorithm, where the system ignores deadlocks and may require
manual intervention if they occur.
1.False Positives:
2.Communication Overhead:
Collecting local wait-for graphs (WFGs) from different nodes and constructing a global
WFG incurs communication overhead. Frequent communication between nodes
increases network traffic and may degrade system performance.
3.Synchronization Issues:
As the number of processes and nodes increases, the size and complexity of the global
WFG also increase. This can make deadlock detection more computationally
expensive, reducing scalability in large systems.
5.Recovery Complexity:
Once a deadlock is detected, determining the most efficient recovery strategy (e.g.,
choosing which process to terminate or which resources to preempt) can be
complicated. Choosing an optimal recovery strategy without affecting other
processes significantly is challenging.
6.Detection Latency:
3.A) Examine Lamport’s snapshot recording algorithm for determining the global
states of distributed systems?
A process could record it own local state at a given time but the messages that are in
transit (on its way to be delivered) would not be included in the recorded state and
hence the actual state of the system would be incorrect after the time in transit
message is delivered.
The main idea behind proposed algorithm is that if we know that all message
that have been sent by one process have been received by another then we can record
the global state of the system.
Any process in the distributed system can initiate this global state recording algorithm
using a special message called MARKER. This marker traverse the distributed system
across all communication channel and cause each process to record its own state. In
the end, the state of entire system (Global state) is recorded. This algorithm does not
interfere with normal execution of processes.
Algorithm:
o If process Q has not yet recorded its own local state then
• A site send a REQUEST message to all other site in its request set or quorum to
get their permission to enter critical section.
• A site send a REPLY message to requesting site to give its permission to enter
the critical section.
• A site send a RELEASE message to all other site in its request set or quorum
upon exiting the critical section.
The construction of request set or Quorum: A request set or Quorum in Maekawa’s
algorithm must satisfy the following properties:
∀i ∀j : i ≠ j, 1 ≤ i, j ≤ N :: Ri ⋂ Rj ≠ ∅
1. i.e there is at least one common site between the request sets of
any two sites.
∀i : 1 ≤ i ≤ N :: Si ∊ Ri
∀i : 1 ≤ i ≤ N :: |Ri| = K
Algorithm:
o When a site Sj receives the request message REQUEST(i) from site Si, it
returns a REPLY message to site Si if it has not sent a REPLY message to
the site from the time it received the last RELEASE message. Otherwise,
it queues up the request.
o In case queue is empty, site Sj update its status to show that it has not
sent any REPLY message since the receipt of the last RELEASE message
Detailed Example:
Let’s consider a distributed system with 9 processes P1,P2,…,P9P_1, P_2, \dots, P_9P1
,P2,…,P9. Quorums (request sets) for each process could be structured like this:
• RS1={P1,P2,P3}
• RS2={P2,P4,P5}
• RS3={P3,P6,P7}.
1. Request Phase:
Once P1P_1P1 receives votes from all members of its request set, it enters its
critical section.
3. Release Phase:
• √N request messages
• √N reply messages
• √N release messages
• Two type of messages ( REQUEST and REPLY) are used and communication channels
are assumed to follow FIFO order.
• A site send a REQUEST message to all other site to get their permission to enter
critical section.
• A site send a REPLY message to other site to give its permission to enter the critical
section.
• A timestamp is given to each critical section request using Lamport’s logical clock.
• The execution of critical section request is always in the order of their timestamp.
Message Complexity:
• (N – 1) request messages
• (N – 1) reply messages
• Unreliable approach: failure of any one of node in the system can halt the progress
of the system. In this situation, the process will starve forever. The problem of failure
of node can be solved by detecting failure after some timeout.
• Nodes: Each node in the graph represents a process running at that particular
site.
Functionality:
• The local WFG simplifies deadlock detection within the node, allowing the
system to detect local deadlocks. If a cycle is detected in the local WFG, it
indicates that a deadlock has occurred among the processes at that node.
• Local WFGs are maintained and periodically checked by local deadlock
detectors at each node. However, they provide only a partial view of the
system's overall state because they do not account for inter-node
dependencies.
Limitations:
• Nodes: Each node in the global WFG represents a process, regardless of which
node it is running on.
• Edges: Directed edges represent waiting relationships both within and across
nodes. An edge from process Pi on node A to process Pj on node B indicates
that Pi is waiting for a resource held by Pj on a different node.
Functionality:
• The global WFG is crucial for detecting global deadlocks, which occur when
processes from different nodes form a circular dependency.
• To construct a global WFG, the local WFGs are combined with information
about inter-node dependencies. This is often done by exchanging messages
between nodes, where each node sends its local WFG to a global deadlock
detector or to other nodes.
• The global WFG is analyzed for cycles, which indicate the presence of
deadlocks that span multiple nodes. If a cycle is found in the global WFG, it
signals that processes across different nodes are involved in a deadlock.
• The detection of global deadlocks can be more complex and costly because it
requires inter-node communication and coordination between local and
global detectors.
Comparison of Local and Global WFGs:
Deadlock
Detects local deadlocks only Detects global deadlocks
Detection
5.B) What are the requirements for mutual exclusion in Distributed systems?
Explain about various metrics used for evaluating the performance of mutual
exclusion algorithms in Distributed systems.
In distributed systems, mutual exclusion ensures that only one process at a time can
access a shared resource or critical section (CS). The key requirements for mutual
exclusion in distributed systems are:
Mutual Exclusion:
At any given time, only one process is allowed to access the critical section. No two
processes can be in the critical section simultaneously.
The system must be free from deadlock, meaning no set of processes should block
each other indefinitely while waiting to access the critical section.
Freedom from Starvation:
Every process that requests access to the critical section must eventually be granted
access, ensuring fairness. No process should be indefinitely postponed or denied
entry to the critical section.
Fault Tolerance:
The algorithm must be able to handle failures in the system, such as process crashes
or communication failures, without violating the mutual exclusion property.
Fairness:
The algorithm should ensure that all processes get a fair chance to enter the critical
section, with requests being granted based on some priority (e.g., timestamp or
request order). There should be no undue advantage for any process.
Distributed systems typically lack a global clock, so algorithms must rely on local
timestamps or logical clocks to enforce ordering.
Low Overhead:
Various metrics are used to evaluate the performance of mutual exclusion algorithms
in distributed systems. These metrics help assess the efficiency and scalability of the
algorithms in terms of communication, time complexity, and system load.
1. Message Complexity
Synchronization delay measures the time a process waits to enter the critical section
after receiving permission to do so. It reflects how quickly a process can proceed after
permission is granted. Reducing synchronization delay ensures faster access to the
critical section, improving the system's overall responsiveness. In scenarios where the
system requires multiple rounds of communication or global coordination,
synchronization delays can be high, slowing down the system. In contrast, token-
based algorithms typically have low synchronization delays because once a process
acquires the token, it can immediately enter the critical section. An ideal algorithm
minimizes this delay, allowing processes to access the shared resource as soon as they
have permission.
3. Response Time
Response time refers to the total time elapsed between when a process requests
access to the critical section and when it actually gains access. A shorter response time
indicates that the algorithm efficiently handles requests and provides quicker access
to shared resources. Minimizing response time is vital in systems where processes
frequently compete for the critical section, as long delays can lead to reduced system
performance and high contention. Algorithms that require multiple message
exchanges or that suffer from resource contention will generally exhibit higher
response times. To improve performance, an ideal algorithm should keep the response
time as low as possible, enabling prompt access to the critical section without
unnecessary delays.
4. Bandwidth Utilization
Scalability evaluates how well the algorithm performs as the number of processes in
the system increases. In distributed systems, the algorithm should be able to handle a
growing number of processes without a significant increase in overhead or
performance degradation. Algorithms that rely on centralized coordination often
struggle to scale because a single coordinator becomes a bottleneck as the system
grows. In contrast, token-based algorithms scale well because only one message (the
token) is passed around, regardless of the number of processes. An ideal mutual
exclusion algorithm should exhibit linear or sub-linear scaling, ensuring that the
system remains efficient even as it expands.
6. Fault Tolerance
Fairness refers to the algorithm’s ability to ensure that all processes have an equal
chance to access the critical section, and starvation freedom guarantees that no
process is indefinitely delayed or denied access. This is critical in maintaining the
integrity and performance of distributed systems, especially when multiple processes
are contending for the same resource. An ideal algorithm should provide fair access
to the critical section, typically by granting access in the order of requests or based on
timestamps. For example, algorithms using Lamport’s logical clock ensure fairness by
prioritizing processes with smaller timestamps. Without fairness and starvation
freedom, certain processes could monopolize resources, leading to performance
degradation and system inefficiency.
In the Single Resource Model, each process can make only one outstanding request
for a single unit of a resource at a time. The goal of the algorithm is to detect deadlocks
where processes are waiting for resources held by other processes in a system where
each process is only allowed to request one resource at a time. This model can be
represented using a Wait-For Graph (WFG), which is a directed graph used to track
dependencies between processes and the resources they are waiting for.
1. Initial State:
• There is only one token in the system, and initially, one process holds it,
allowing it to access the critical section.
• Each process keeps track of the state of the token: whether it holds the token
or has requested it from another process.
When a process, say Process PiP_iPi, wants to enter the critical section:
• If it does not hold the token, it sends a request message to the process that
currently holds the token.
• The request includes the process ID and a timestamp (usually based on logical
clocks) to ensure fairness and avoid starvation. The timestamp is used to
prioritize requests.
• The process that holds the token, when it receives a request message from
another process, must decide whether to pass the token or hold on to it.
• If the current process is not in the critical section or has finished its critical
section, it passes the token to the requesting process with the oldest request
(i.e., the one with the smallest timestamp).
• While the process holds the token, no other process can access the critical
section because the token is required to do so.
• After completing its work in the critical section, the process checks if there are
any pending requests for the token.
• If there are pending requests, it passes the token to the process with the oldest
request.
• If there are no requests, the process keeps the token and can reuse it the next
time it wants to enter the critical section.
• Each process maintains a queue of pending requests it has received from other
processes.
• The queue helps the process decide which request to prioritize when passing
the token after exiting the critical section.
• Requests are ordered by their timestamps, ensuring that the system gives
priority to earlier requests.
Mitchell and Merritt’s Algorithm provides an efficient solution for achieving mutual
exclusion in distributed systems with a single shared resource. Its use of a token-
based approach ensures that only one process can access the critical section at a time,
preventing both deadlock and starvation
6.A) Distinguish about AND model and OR Model?
Strong consistency required (all nodes Eventual consistency (any node can
Consistency
must agree) succeed)
Lower fault tolerance; must meet all Higher fault tolerance; success if
Fault Tolerance
conditions to succeed any condition is met
Concurrency Requires synchronization between all Can continue with partial success
Control participants inconcurrent environments
Consistency Guara Strong consistency, but can result in Weaker consistency (eventual consi
ntees more frequent blockages stency) but more fault-tolerant
Resource Locking High risk of deadlocks if resources are Reduced risk of deadlocks, as resou
in Deadlock locked by all nodes rces are less strictly locked