0% found this document useful (0 votes)
32 views24 pages

Distributed System 2

Uploaded by

Sahil Chourasiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views24 pages

Distributed System 2

Uploaded by

Sahil Chourasiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Mutual exclusion is a concurrency control property which is introduced to prevent race

conditions. It is the requirement that a process can not enter its critical section while
another concurrent process is currently present or executing in its critical section i.e only
one process is allowed to execute the critical section at any given instance of time.

Mutual exclusion in single computer system Vs. distributed system: In single


computer system, memory and other resources are shared between different processes.
The status of shared resources and the status of users is easily available in the shared
memory so with the help of shared variable (For example: Semaphores) mutual exclusion
problem can be easily solved. In Distributed systems, we neither have shared memory nor
a common physical clock and therefore we can not solve mutual exclusion problem using
shared variables. To eliminate the mutual exclusion problem in distributed system
approach based on message passing is used. A site in distributed system do not have
complete information of state of the system due to lack of shared memory and a common
physical clock.

Requirements of Mutual exclusion Algorithm:


 No Deadlock: Two or more site should not endlessly wait for any message that will
never arrive.
 No Starvation: Every site who wants to execute critical section should get an
opportunity to execute it in finite time. Any site should not wait indefinitely to execute
critical section while other site are repeatedly executing critical section
 Fairness: Each site should get a fair chance to execute critical section. Any request to
execute critical section must be executed in the order they are made i.e Critical section
execution requests should be executed in the order of their arrival in the system.
 Fault Tolerance: In case of failure, it should be able to recognize it by itself in order to
continue functioning without any disruption.
Some points are need to be taken in consideration to understand mutual exclusion fully :
1) It is an issue/problem which frequently arises when concurrent access to shared
resources by several sites is involved. For example, directory management where
updates and reads to a directory must be done atomically to ensure correctness.
2) It is a fundamental issue in the design of distributed systems.
3) Mutual exclusion for a single computer is not applicable for the shared resources since
it involves resource distribution, transmission delays, and lack of global information.

Solution to distributed mutual exclusion: As we know shared variables or a local


kernel can not be used to implement mutual exclusion in distributed systems. Message
passing is a way to implement mutual exclusion. Below are the three approaches based
on message passing to implement mutual exclusion in distributed systems:
1. Token Based Algorithm:
 A unique token is shared among all the sites.
 If a site possesses the unique token, it is allowed to enter its critical section
 This approach uses sequence number to order requests for the critical section.
 Each requests for critical section contains a sequence number. This sequence number
is used to distinguish old and current requests.
 This approach insures Mutual exclusion as the token is unique
Example : Suzuki–Kasami Algorithm
2. Non-token based approach:
 A site communicates with other sites in order to determine which sites should execute
critical section next. This requires exchange of two or more successive round of
messages among sites.
 This approach use timestamps instead of sequence number to order requests for the
critical section.
 When ever a site make request for critical section, it gets a timestamp. Timestamp is
also used to resolve any conflict between critical section requests.
 All algorithm which follows non-token based approach maintains a logical clock. Logical
clocks get updated according to Lamport’s scheme
Example : Ricart–Agrawala Algorithm

3. Quorum based approach:


 Instead of requesting permission to execute the critical section from all other sites,
Each site requests only a subset of sites which is called a quorum.
 Any two subsets of sites or Quorum contains a common site.
 This common site is responsible to ensure mutual exclusion

Non-Token Based
S.No. Token Based Algorithms Algorithms

In the Token-based algorithm, a In Non-Token based algorithm,


unique token is shared among all the there is no token even not any
sites in Distributed Computing concept of sharing token for
1. Systems. access.

Here, two or more successive


Here, a site is allowed to enter the rounds of messages are
Critical Section if it possesses the exchanged between sites to
token. determine which site is to enter
2. the Critical Section next.

Non-Token based algorithm uses


The token-based algorithm uses the
the timestamp (another concept)
sequences to order the request for the
to order the request for the
Critical Section and to resolve the
Critical Section and to resolve the
conflict for the simultaneous requests
conflict for the simultaneous
for the System.
3. requests for the System.
Non-Token Based
S.No. Token Based Algorithms Algorithms

Non-Token based Algorithm


The token-based algorithm produces
produces more message traffic as
less message traffic as compared to
compared to the Token-based
Non-Token based Algorithm.
4. Algorithm.

They are free from deadlock (i.e. here


there are no two or more processes
They are not free from the
are in the queue in order to wait for
deadlock problem as they are
messages that will actually can’t
based on timestamp only.
come) because of the existence of
5. unique token in the distributed system.

Here, it is ensured that requests are


Here there is no surety of
executed exactly in the order as they
execution order.
6. are made in.

Token-based algorithms are more


scalable as they can free your server Non-Token based algorithms are
from storing session state and also less scalable than the Token-
they contain all the necessary based algorithms because server
information which they need for is not free from its tasks.
7. authentication.

8.

Token-based algorithms make Non-Token based algorithms


9. authentication quite easy. can’t make authentication easy.

Examples of Token-Based Algorithms


Examples of Non-Token Based
are:
Algorithms are:
(i) Singhal’s Heuristic
(i) Lamport’s Algorithm
Algorithm
(ii) Ricart-Agarwala
(ii) Raymonds Tree Based
Algorithm
Algorithm
(iii) Maekawa’s Algorithm
10. (iii) Suzuki-Kasami Algorithm

Types of Mutual Exclusion


Diverse mutual exclusion mechanisms are employed in distributed systems. Below are a few
typical examples −

 Lock-Based Mechanism − Locks are used in lock-based mechanisms that impose


mutual exclusion. Prior to obtaining a shared asset or essential section, procedures or
nodes obtain a lock. Locks can be either divulged (more than a single procedure may
obtain the lock at once, but no restricted lock can be obtained) or restricted (just a single
procedure can gain the lock at a time). The provisioning and releasing of locks among
distributed nodes are coordinated by distributed lock managers.
 Token-Based Mechanism − In order to regulate the availability of materials, token-
based mechanisms depend on the transfer of tokens within operations. The key
component of communal assets can only be accessed by an operation that is in
possession of the token. After completing its task, the process transfers the token in an
established sequence to the following eligible procedure. Token passing maintains mutual
exclusion by making sure just a single procedure has access to the material at once.
 Time-Stamped Mechanism − The chronological sequence of gaining access to
communal assets is determined by timestamp-based mechanisms, which allocate distinct
records of the timestamp for operations or transactions. While methods that have shorter
timestamps have to wait, those that have greater timestamps have importance and are
able to use the resource in question right away. Operations are able to utilize materials in
an ordered and mutually reinforcing behavior thanks to timestamp-requesting rules and
regulations.
 Quorum-Based Mechanism − The idea of quorums, which are segments of nodes in a
distributed system, is used by quorum-based mechanisms. A method needs approval
from a majority of nodes in order to gain entry to a resource that is shared. In order to
achieve mutual exclusion, quorum-based protocols like the Quorum Consensus Protocol
(QCP) or the Paxos algorithm guarantee only those methods with overlaid quorums can
access the resource simultaneously.

Lamport’s Algorithm for Mutual Exclusion in Distributed


System
Lamport’s Distributed Mutual Exclusion Algorithm is a permission based
algorithm proposed by Lamport as an illustration of his synchronization scheme
for distributed systems. In permission based timestamp is used to order critical
section requests and to resolve any conflict between requests. In Lamport’s
Algorithm critical section requests are executed in the increasing order of
timestamps i.e a request with smaller timestamp will be given permission to
execute critical section first than a request with larger timestamp. In this
algorithm:
 Three type of messages ( REQUEST, REPLY and RELEASE) 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 requesting site to give its permission to
enter the critical section.
 A site send a RELEASE message to all other site upon exiting the critical
section.
 Every site Si, keeps a queue to store critical section requests ordered by their
timestamps. request_queuei denotes the queue of site Si
 A timestamp is given to each critical section request using Lamport’s logical
clock.
 Timestamp is used to determine priority of critical section requests. Smaller
timestamp gets high priority over larger timestamp. The execution of critical
section request is always in the order of their timestamp.
Algorithm:
 To enter Critical section:
o When a site Si wants to enter the critical section, it sends a request
message Request(tsi, i) to all other sites and places the request
on request_queuei. Here, Tsi denotes the timestamp of Site Si
o When a site Sj receives the request message REQUEST(tsi, i) from
site Si, it returns a timestamped REPLY message to site Si and places
the request of site Si on request_queuej
 To execute the critical section:
o A site Si can enter the critical section if it has received the message
with timestamp larger than (tsi, i) from all other sites and its own
request is at the top of request_queuei
 To release the critical section:
o When a site Si exits the critical section, it removes its own request
from the top of its request queue and sends a
timestamped RELEASE message to all other sites
o When a site Sj receives the timestamped RELEASE message from
site Si, it removes the request of Si from its request queue
Message Complexity: Lamport’s Algorithm requires invocation of 3(N – 1)
messages per critical section execution. These 3(N – 1) messages involves
 (N – 1) request messages
 (N – 1) reply messages
 (N – 1) release messages
Drawbacks of Lamport’s Algorithm:
 Unreliable approach: failure of any one of the processes will halt the
progress of entire system.
 High message complexity: Algorithm requires 3(N-1) messages per critical
section invocation.
Performance:
 Synchronization delay is equal to maximum message transmission time
 It requires 3(N – 1) messages per CS execution.
 Algorithm can be optimized to 2(N – 1) messages by omitting
the REPLY message in some situations.
Advantages of Lamport’s Algorithm for Mutual Exclusion in Distributed System:
1. Simplicity: Lamport’s algorithm is relatively easy to understand and
implement compared to other algorithms for mutual exclusion in distributed
systems.
2. Fairness: The algorithm guarantees fairness by providing a total order of
events that is used to determine the next process that can enter the critical
section.
3. Scalability: Lamport’s algorithm is scalable because it only requires each
process to communicate with its neighbors, rather than all other processes in
the system.
4. Compatibility: The algorithm is compatible with a wide range of distributed
systems and can be adapted to different network topologies and
communication protocols.

Disadvantages of Lamport’s Algorithm for Mutual Exclusion in


Distributed System:

1. Message Overhead: The algorithm requires a lot of message passing


between processes to maintain the total order of events, which can lead to
increased network traffic and latency.
2. Delayed Execution: The algorithm can lead to delays in the execution of
critical sections because a process may have to wait for messages to arrive
from other processes before entering the critical section.
3. Limited Performance: The algorithm may not perform well in systems with
a high number of processes because of the increased message overhead and
delayed execution.
4. No Fault Tolerance: The algorithm does not provide any fault tolerance
mechanism, which means that if a process fails or crashes, it may cause the
entire system to fail or become unstable.
FAQs:

Use Cases of Mutual Exclusion in distributed


systems
n database systems, multiple users or programs can access a shared database simultaneously.
Mutual exclusion is needed during important operations like writing to the database to maintain
data consistency and prevent conflicts. Techniques like two-phase locking or timestamp-based
protocols are used to ensure that only one user can modify the data at a time.

In file-sharing systems, many users may try to access or edit the same file at once. To avoid
conflicts and ensure data integrity, mutual exclusion ensures that only one user can write to a file
at a time. Distributed file-locking mechanisms or decision-making techniques are used to control
access.
In distributed resource scheduling, processes may compete for shared resources like memory,
CPU, or network bandwidth. Mutual exclusion ensures that only one task can use a resource at a
time, preventing resource conflicts. Techniques like distributed keys or resource allocation rules
help manage access.

In distributed transaction processing, where multiple nodes or databases handle a single


transaction, mutual exclusion ensures data consistency and integrity. Algorithms like two-phase
commit or three-phase commit help coordinate actions across nodes, ensuring all nodes agree to
commit or roll back the transaction, preventing inconsistencies.

4o

Distributed System – Types of Distributed Deadlock


Last Updated : 17 Dec, 2021



A Deadlock is a situation where a set of processes are blocked because each


process is holding a resource and waiting for another resource occupied by
some other process. When this situation arises, it is known as Deadlock.

Deadlock

A Distributed System is a Network of Machines that can exchange information


with each other through Message-passing. It can be very useful as it helps in
resource sharing. In such an environment, if the sequence of resource allocation
to processes is not controlled, a deadlock may occur. In principle, deadlocks in
distributed systems are similar to deadlocks in centralized systems. Therefore,
the description of deadlocks presented above holds good both for centralized
and distributed systems. However, handling of deadlocks in distributed systems
is more complex than in centralized systems because the resources, the
processes, and other relevant information are scattered on different nodes of
the system.
Three commonly used strategies to handle deadlocks are as follows:
 Avoidance: Resources are carefully allocated to avoid deadlocks.
 Prevention: Constraints are imposed on the ways in which processes
request resources in order to prevent deadlocks.
 Detection and recovery: Deadlocks are allowed to occur and a detection
algorithm is used to detect them. After a deadlock is detected, it is resolved
by certain means.
Types of Distributed Deadlock:
There are two types of Deadlocks in Distributed System:
Resource Deadlock: A resource deadlock occurs when two or more processes
wait permanently for resources held by each other.
 A process that requires certain resources for its execution, and cannot
proceed until it has acquired all those resources.
 It will only proceed to its execution when it has acquired all required
resources.
 It can also be represented using AND condition as the process will execute
only if it has all the required resources.
 Example: Process 1 has R1, R2, and requests resources R3. It will not execute
if any one of them is missing. It will proceed only when it acquires all
requested resources i.e. R1, R2, and R3.
figure 1: Resource Deadlock

Communication Deadlock: On the other hand, a communication deadlock


occurs among a set of processes when they are blocked waiting for messages
from other processes in the set in order to start execution but there are no
messages in transit between them. When there are no messages in transit
between any pair of processes in the set, none of the processes will ever receive
a message. This implies that all processes in the set are deadlocked.
Communication deadlocks can be easily modeled by using WFGs to indicate
which processes are waiting to receive messages from which other processes.
Hence, the detection of communication deadlocks can be done in the same
manner as that for systems having only one unit of each resource type.
 In Communication Model, a Process requires resources for its execution and
proceeds when it has acquired at least one of the resources it has requested
for.
 Here resource stands for a process to communicate with.
 Here, a Process waits for communicating with another process in a set of
processes. In a situation where each process in a set, is waiting to
communicate with another process which itself is waiting to communicate
with some other process, this situation is called communication deadlock.
 For 2 processes to communicate, each one should be in the unblocked state.
 It can be represented using OR conditions as it requires at least one of the
resources to continue its Process.
 Example: In a Distributed System network, Process 1 is trying to
communicate with Process 2, Process 2 is trying to communicate with Process
3 and Process 3 is trying to communicate with Process 1. In this situation,
none of the processes will get unblocked and a communication deadlock
occurs.

figure 2: Communication Deadlock

In distributed systems, deadlocks are considered the major problem, where the resources
requested by the process are not available due to other processes holding onto it. A distributed
system contains a set of processes p1,p2,p3…pn that do not share a common memory, and
communication is made only by passing messages through the network. This does not have a
global clock for instant access and communication medium. Each process has two states such as
a running state where the process contains all the resources and is ready for execution and
another state a blocked state where the process is in a waiting state needing some resources.

Below are the four conditions that need to be met for the deadlock to occur −

Hold and wait − one process holds the resources that are needed for another process to use.

Mutual exclusion − when only one process is allowed to use one resource at a time.
No preemption − No process cannot be preempted until it completes the execution of a task.

Circular wait − The process needs to wait for the required resource in a cyclic manner, where
the last process in the queue waits for the resource used by the first process.

ResourceDeadlock
Resource deadlock occurs when a process is waiting for the set of resources that is held by
another process and it waits to receive all the resources requested before it becomes unblocked.
So, the process set which waits for resources is said to be in a resource deadlock state. Consider
an example when two processes P1 and P2 and are in need of resources X and Y. In this case, P1
waits for resource Y where P2 holds resource Y, and P2, in turn, waits for resource X which has to
be released by P1 holding it. So, in a

closed manner, P1 needs resource Y and waits for P2 to release it, and P2 needs X, and waits for
P2 to release it.

The above figure is said to be in a resource deadlock since each process waits for another
process to acquire all the needed sets of resources. Distributed deadlocks are more difficult to
handle because resources and the input process are distributed and cannot be detected at a
commonplace. Few approaches are used to handle distributed deadlocks such as detection,
prevention, avoidance, and ostrich problem (avoidance).

Explore our latest online courses and learn new skills at your own pace. Enroll and become a
certified expert to boost your career.
Communication deadlock
Communication deadlock happens among process which needs to communicate and waits for
another process for its task. The process which is in a waiting state can unblock itself when it
receives communication requests from other processes in the group. When each process in the
set waits for another process to communicate, at this time no other process starts other
communication until it receives further communication from the initial process.

Consider a scenario when process X waits for messages from process Y and process Y in turn
waits for messages from another process called Z. Then process Z waits for the initial process.
This deadlock occurs when communication among the process is locked by each other

The table below defines the major differences between resource and communication deadlock:

Basis of
differenc Resource Deadlocks Communication Deadlocks
e

The process waits for the The process waits for another process
Definition several resources that are on in the group to initiate communication
hold by other processes with one another

A process that is waiting for The process will not enter into an
Process needed resources cannot execution state till it receives a
state continue to its execution state communication message from another
until acquiring all of it. process.

Waiting The process waits for resources The process waits for the messages
for to perform its task. from another process.

No information is known about The process can identify which


Transacti
the dependency between the process to communicate before
on
transactions beginning the transaction

When each process in a When each process in the group waits


specific set needs multiple for communication from another
resources from another process and during this phase, no
Deadlock
process, and initial process has other process initiates new
occurrenc
to unblock itself by fetching the communication until it receives the
e
needed resources. Then these same from the needed process, these
set of processes are inside processes are now in a deadlock
resource deadlock phase.

Examples Process P1 waits for resource X Process X waits for a message from
and P2 waits for resource Y and process Y, which in turn waits for
each process holds and waits process Z and Z waits for initial
for each of the resources. process X.

Deadlock Prevention And Avoidance


Last Updated : 26 Jun, 2024



When two or more processes try to access the critical section at the same time
and they fail to access simultaneously or stuck while accessing the critical
section then this condition is known as Deadlock.
Deadlock prevention and avoidance are strategies used in computer systems to
ensure that different processes can run smoothly without getting stuck waiting
for each other forever. Think of it like a traffic system where cars (processes)
need to move through intersections (resources) without getting into a gridlock.
In this article, we are going to discuss deadlock prevention and avoidance
strategies in detail.
Deadlock Characteristics
The deadlock has the following characteristics:
 Mutual Exclusion
 Hold and Wait
 No Preemption
 Circular Wait
Deadlock Prevention
We can prevent a Deadlock by eliminating any of the above four conditions.
Eliminate Mutual Exclusion: It is not possible to dis-satisfy the mutual
exclusion because some resources, such as the tape drive and printer, are
inherently non-shareable.
Eliminate Hold and Wait: Allocate all required resources to the process before
the start of its execution, this way hold and wait condition is eliminated but it
will lead to low device utilization. for example, if a process requires a printer at a
later time and we have allocated a printer before the start of its execution
printer will remain blocked till it has completed its execution. The process will
make a new request for resources after releasing the current set of resources.
This solution may lead to starvation.
Eliminate No Preemption : Preempt resources from the process when
resources are required by other high-priority processes.
Eliminate Circular Wait : Each resource will be assigned a numerical number.
A process can request the resources to increase/decrease. order of
numbering. For Example, if the P1 process is allocated R5 resources, now next
time if P1 asks for R4, R3 lesser than R5 such a request will not be granted, only
a request for resources more than R5 will be granted.
Detection and Recovery: Another approach to dealing with deadlocks is to
detect and recover from them when they occur. This can involve killing one or
more of the processes involved in the deadlock or releasing some of the
resources they hold.
Deadlock Avoidance

Resource Allocation Graph


The resource allocation graph (RAG) is used to visualize the system’s current
state as a graph. The Graph includes all processes, the resources that are
assigned to them, as well as the resources that each Process requests.
Sometimes, if there are fewer processes, we can quickly spot a deadlock in the
system by looking at the graph rather than the tables we use in Banker’s
algorithm. Deadlock avoidance can also be done with Banker’s Algorithm.
Banker’s Algorithm
Bankers’s Algorithm is a resource allocation and deadlock avoidance
algorithm which test all the request made by processes for resources, it checks
for the safe state, and after granting a request system remains in the safe
state it allows the request, and if there is no safe state it doesn’t allow the
request made by the process.
Inputs to Banker’s Algorithm
 Max needs of resources by each process.
 Currently, allocated resources by each process.
 Max free available resources in the system.
The request will only be granted under the below condition
 If the request made by the process is less than equal to the max needed for
that process.
 If the request made by the process is less than equal to the freely available
resource in the system.
Timeouts: To avoid deadlocks caused by indefinite waiting, a timeout
mechanism can be used to limit the amount of time a process can wait for a
resource. If the help is unavailable within the timeout period, the process can be
forced to release its current resources and try again later.
Example:
Total resources in system:
A B C D
6 5 7 6
The total number of resources are
Available system resources are:
A B C D
3 1 1 2
Available resources are
Processes (currently allocated resources):
A B C D
P1 1 2 2 1
P2 1 0 3 3
P3 1 2 1 0
Maximum resources we have for a process
Processes (maximum resources):
A B C D
P1 3 3 2 2
P2 1 2 3 4
P3 1 3 5 0
Need = Maximum Resources Requirement – Currently Allocated
Resources.
Need = maximum resources - currently allocated resources.
Processes (need resources):
A B C D
P1 2 1 0 1
P2 0 2 0 1
P3 0 1 4 0

In the centralized approach of deadlock detection, two techniques are used namely:
Completely centralized algorithm and Ho Ramamurthy algorithm (One phase and Two-
phase).
 Completely Centralized Algorithm –
In a network of n sites, one site is chosen as a control site. This site is responsible for
deadlock detection. It has control over all resources of the system. If a site requires a
resource it requests the control site, the control site allocates and de-allocates
resources, and maintains a wait-for graph. And at a regular interval of time, it checks
the wait-for graph to detect a cycle. If the cycle exits then it will declare the system as
deadlock otherwise the system will continue working. The major drawbacks of this
technique are as follows:
1. A site has to send requests even for using its own resource.
2. There is a possibility of phantom deadlock.
 HO Ramamurthy (Two-Phase Algorithm) –
In this technique a resource status table is maintained by the central or control site, if a
cycle is detected then the system is not declared deadlock at first, the cycle is checked
again as the system is distributed some of the other resources is vacant or freed by
sites at every instant of time. Now, after checking if a cycle is detected again then, the
system is declared as deadlock. This technique reduces the possibility of phantom
deadlock but on the other hand time consumption is more.

 HO Ramamurthy (One Phase Algorithm) –


In this technique a resource status table and a process table is maintained by the
central or control site if the cycle is detected in both processes and resource tables
then, the system is declared as deadlock. This technique reduces time consumption
but space complexity increases.

Advantages:
 Centralized deadlock detection techniques are easy to implement as they require only
one site to be responsible for deadlock detection.
 These techniques can efficiently detect deadlocks in large and complex distributed
systems.
 They can prevent the wastage of resources in a system due to deadlocks.
Disadvantages:
 Centralized deadlock detection techniques can lead to a single point of failure as the
control site can become a bottleneck in the system.
 These techniques can cause high network traffic as all the requests and responses are
sent to the control site.
 Centralized deadlock detection techniques are not suitable for systems where
resources are widely distributed.

What are Deadlocks in Distributed Systems?


In distributed systems, a deadlock occurs when a set of processes are unable to proceed
because each is waiting for a resource that another holds, creating a circular wait
condition. This situation causes the involved processes to become stuck, unable to
continue or complete their tasks. Key Characteristics of Deadlocks include:
 Mutual Exclusion: At least one resource is held in a non-shareable mode, meaning
only one process can use it at a time.
 Hold and Wait: Processes holding resources can request additional resources without
releasing their current ones.
 No Preemption: Resources cannot be forcibly taken from a process; they must be
released voluntarily.
 Circular Wait: A closed loop of processes exists where each process is waiting for a
resource held by the next process in the loop.
Importance of Deadlock Detection in Distributed Systems
Deadlock detection in distributed systems is crucial for maintaining system reliability and
performance. Below is why it is important:
 Prevents System Stagnation: Deadlocks cause processes to be stuck indefinitely,
leading to a halt in system operations. Effective detection helps prevent such
stagnation and ensures continuous system functionality.
 Ensures Resource Utilization: Detecting and resolving deadlocks helps optimize
resource use, avoiding situations where resources are wasted due to processes being
stuck in a deadlock.
 Improves System Reliability: By identifying and handling deadlocks promptly, the
system can recover gracefully, reducing the likelihood of prolonged outages and
improving overall reliability.
 Enhances Performance: Timely deadlock detection prevents performance
degradation caused by processes waiting indefinitely, thereby maintaining system
responsiveness and efficiency.
 Facilitates Scalability: As distributed systems scale, the complexity of deadlock
scenarios increases. Efficient detection mechanisms are essential to manage this
complexity and ensure smooth operation as the system grows.
 Supports Fault Tolerance: Deadlock detection is integral to fault tolerance strategies,
allowing systems to handle and recover from issues that could otherwise lead to
service disruptions or failures.
 Improves User Experience: Ensuring that processes can complete their tasks without
being stuck in deadlocks contributes to a better user experience by minimizing delays
and ensuring reliable service.
Types of Deadlocks in Distributed Systems
In distributed systems, deadlocks can arise in various forms, depending on the nature of
resource contention and process interactions. The primary types of deadlocks are:
 Resource Deadlocks:
o Occur when processes compete for limited resources and each process
holds some resources while waiting for additional ones held by others,
leading to a circular wait condition.
o A printer (resource) is held by Process A, which is waiting for a disk
(resource) held by Process B, which in turn is waiting for the printer.
 Communication Deadlocks:
o Arise from processes waiting indefinitely for messages or signals from other
processes, often due to incorrect communication protocols or synchronization
issues.
o Process A waits for a response from Process B before proceeding, while
Process B is waiting for a response from Process A, leading to a deadlock.
 Livelocks:
o A special case where processes keep changing states in response to each
other but never make progress. Unlike traditional deadlocks, processes are
active but fail to reach a state where they can continue.
o Two processes repeatedly attempt to acquire the same set of resources in a
way that keeps them perpetually in a state of mutual exclusion without
making any progress.
 Deadlock in Database Systems:
o Occurs when transactions or queries wait for locks on database resources
that are held by other transactions, creating a situation where none of the
transactions can proceed.
o Transaction T1 holds a lock on Table A and waits for a lock on Table B held
by Transaction T2, which in turn waits for a lock on Table A.
 Deadlock in Distributed File Systems:
o Happens when file locks are held across multiple nodes or servers, leading to
a situation where nodes or processes are waiting for locks held by each
other, causing a deadlock.
o Node A has a lock on File X and waits for a lock on File Y, which is held by
Node B, while Node B is waiting for the lock on File X.
Deadlock Detection Techniques in Distributed Systems
Deadlock detection techniques in distributed systems aim to identify and resolve
deadlocks by analyzing the system’s state. The primary techniques include:
1. Centralized Deadlock Detection
 A single central coordinator is responsible for detecting deadlocks in the system.
 How It Works: The coordinator collects information about resource allocation and
process states from all nodes. It then constructs a global wait-for graph or other
relevant data structures to detect cycles indicating deadlocks.
 Advantages: Simplifies management and reduces the complexity of detection.
 Disadvantages: Can become a bottleneck and a single point of failure.
2. Distributed Deadlock Detection
 Each node in the system participates in the detection process, with no single point of
control.
 Key Approaches:
o Wait-for Graphs: Nodes exchange information to construct and maintain
local wait-for graphs, which are periodically checked for cycles.
o Chandy-Misra-Haas Algorithm: Uses a variant of wait-for graphs where
nodes exchange messages to build a global view of process dependencies. It
involves a detection phase and a resolution phase.
o Wound-Wait Algorithm: Detects deadlocks based on priority and
transaction timestamps, using the concept of “wounding” (forcing a lower-
priority process to abort) to break deadlocks.
 Advantages: Scales better as it distributes the workload.
 Disadvantages: More complex to implement and manage, as it requires coordination
between nodes.
3. Hybrid Approaches
 Combine elements of centralized and distributed techniques to balance their strengths
and weaknesses.
 Example: Use a central coordinator for certain aspects of detection and resolution,
while employing distributed algorithms to gather and disseminate information.
 Advantages: Can leverage the benefits of both approaches, such as reducing
bottlenecks while improving scalability.
 Disadvantages: May inherit complexities from both techniques.
4. Banker’s Algorithm for Deadlock Detection
 Primarily used for deadlock avoidance, but can also be adapted for detection in certain
contexts.
 How It Works: The algorithm assesses whether granting a resource request might lead
to a deadlock by evaluating the state of resources and processes in a way similar to
banking transactions.
 Advantages: Provides a systematic way to avoid deadlock by evaluating resource
requests.
 Disadvantages: Not well-suited for highly dynamic or large-scale distributed systems.
5. Detection Based on Resource Allocation Graphs
 Uses graphs to represent the allocation and request of resources.
 How It Works: Construct and analyze resource allocation graphs to identify cycles. A
cycle in this graph indicates the presence of a deadlock.
 Advantages: Provides a clear visual representation of resource dependencies.
 Disadvantages: Graph construction and analysis can be complex in large systems.
Performance Considerations for Deadlock Detection in
Distributed Systems
Performance considerations for deadlock detection in distributed systems are crucial for
ensuring that detection mechanisms are effective without overly burdening the system.
Below are key aspects to consider:
1. Overhead and Complexity
 Communication Overhead: Techniques involving distributed detection often require
frequent communication between nodes, which can introduce significant network
overhead. Minimizing message passing and optimizing communication patterns is
essential.
 Computational Complexity: The algorithms used for detection can be computationally
intensive, especially for large systems. The complexity of constructing and analyzing
wait-for graphs or other data structures must be balanced against system performance.
2. Scalability
 Scaling Challenges: As the number of nodes and processes increases, the detection
mechanism should scale accordingly. Distributed algorithms should be designed to
handle growing numbers of processes and resources efficiently.
 Partitioning and Aggregation: Hybrid approaches and partitioning of the system into
manageable segments can help address scalability issues, allowing for localized
detection and resolution before global coordination.
3. Detection Time and Frequency
 Real-Time Detection: The time it takes to detect a deadlock is critical. Techniques
must be able to identify deadlocks promptly to minimize the impact on system
performance.
 Detection Interval: For methods that involve periodic checking, such as those using
wait-for graphs, the frequency of checks should be balanced with system performance
to avoid excessive resource consumption.
4. Accuracy and False Positives
 False Positives: Detection mechanisms should minimize false positives, where non-
deadlock situations are incorrectly identified as deadlocks. This can lead to
unnecessary resource reallocation or process terminations.
 Accuracy: Ensuring accurate detection is vital to avoid misidentification of deadlocks,
which could otherwise lead to system instability or performance issues.
Challenges of Deadlock Detection in Distributed Systems
Deadlock detection in distributed systems poses several challenges due to the inherent
complexity and scale of such environments. Key challenges include:
 Lack of Global View
o Challenge: Distributed systems lack a centralized view of all resources and
processes, making it difficult to construct a complete global state of the
system.
o Implication: Accurate deadlock detection requires aggregating information
from multiple nodes, which can be complex and prone to inconsistencies.
 Communication Overhead
o Challenge: Deadlock detection often involves significant communication
between nodes to exchange information about resource allocations and
process states.
o Implication: High communication overhead can impact network performance
and overall system efficiency, especially in large-scale or high-latency
networks.
 Scalability
o Challenge: As the number of processes and resources increases, the
complexity of detecting deadlocks grows exponentially.
o Implication: Detection algorithms must scale efficiently with system size to
avoid excessive computational and communication costs.
 Dynamic System Changes
o Challenge: Distributed systems are often dynamic, with processes and
resources frequently added or removed.
o Implication: Detection mechanisms need to adapt to changes in the system
without introducing additional overhead or complexity.

Path pushing algorithms in distributed systems are a class of algorithms designed to propagate
information across a network efficiently. These algorithms rely on the idea of "pushing"
information along paths from a source to other nodes in the network. They are commonly used in
scenarios like distributed graph algorithms, routing, and information dissemination. Here's a
detailed explanation:

Core Concept

Path pushing algorithms are built around the notion that each node in a distributed system can:

1. Receive information from neighboring nodes.


2. Process or update the information locally.
3. Forward the information to its neighbors.

The propagation continues until all nodes in the relevant subset of the network have the required
information or a termination condition is met.
Key Features

 Localized Operations: Nodes only interact with their immediate neighbors.


 Iterative Process: Information spreads through repeated rounds of communication.
 Asynchronous or Synchronous Execution: Can operate in both synchronous and asynchronous
systems.

Common Use Cases

1. Shortest Path Algorithms:


o Algorithms like Bellman-Ford in distributed systems use path pushing to calculate the
shortest path from a source to all other nodes. Each node updates its distance estimate
based on the distances received from its neighbors.

2. Routing Protocols:
o Used in network routing, where nodes update and share routing tables until
convergence (e.g., Distance Vector Routing).

3. Spanning Tree Construction:


o Constructing minimum spanning trees (e.g., Prim's or Kruskal's algorithms) in distributed
systems relies on propagating information about edge weights.

4. Broadcast and Multicast:


o Disseminating messages to all or a subset of nodes in a distributed system.

5. Consensus Algorithms:
o Algorithms like Paxos or Raft use path pushing to propagate agreement proposals
among nodes.

How It Works

A typical path pushing algorithm proceeds in the following steps:

1. Initialization:
o A source node begins with a piece of information (e.g., distance, state, message).
o It pushes this information to its immediate neighbors.

2. Propagation:
o Each receiving node processes the information and updates its local state.
o If the new information is relevant or leads to an improvement (e.g., shorter path, better
route), it is forwarded to its neighbors.

3. Termination:
o The process ends when no more updates are propagated, achieving convergence.

Challenges

1. Scalability:
o Large networks may lead to excessive message passing, increasing overhead.

2. Staleness:
o Nodes might act on outdated information if updates are not properly synchronized.

3. Fault Tolerance:
o Handling failures (e.g., node or link failures) is critical to ensure the correctness of the
algorithm.

4. Convergence Time:
o Some algorithms may take a long time to converge, especially in asynchronous systems.

Example: Distributed Bellman-Ford Algorithm

 Goal: Compute the shortest paths from a source node to all other nodes.
 Process:
1. Source node initializes its distance to 0 and all others to infinity.
2. It sends distance updates to its neighbors.
3. Neighbors update their distances if the received distance is shorter than their current
estimate.
4. They forward the updated distances to their neighbors.

This continues until no updates are possible.

Edge Chasing Algorithm

The Edge Chasing Algorithm is a method used in distributed systems to detect deadlocks by
analyzing a Wait-For Graph (WFG).

1. Basic Idea:
Each process sends a probe message along the edges of the WFG to check if a cycle
exists. If the probe returns to the originator, a deadlock is detected.
2. Steps:
o A process (P) that suspects a deadlock initiates the algorithm by sending a probe.
o The probe contains:
 The initiator's ID.
 The current process's ID.
 The destination process's ID.
o Each process receiving the probe:
 Forwards it to the next process it is waiting for, according to the WFG.
 If the probe returns to the initiator, it confirms a deadlock.
o If no probe returns, there is no deadlock.

3. Key Points:
o Simple and effective for distributed systems.
o Can be used dynamically, as the WFG changes.
o Relies on detecting cycles in the dependency graph.

Path Pushing Algorithm

The Path Pushing Algorithm is another method for detecting deadlocks in distributed systems.
It works by exchanging information about dependencies between processes.

1. Basic Idea:
Instead of sending probes, processes exchange dependency information (paths) to detect
cycles in the WFG.
2. Steps:
o Each process maintains a record of its dependencies (a path list).
o When a process P requests a resource held by another process Q:
 P sends its current dependency path to Q.
 Q merges this path with its own dependencies and checks for cycles.
o If a cycle is found in the combined path, a deadlock is detected.
o If no cycle is found, the dependency path is forwarded further.

3. Key Points:
o More detailed than edge chasing since it tracks entire dependency paths.
o Requires more communication and storage overhead compared to edge chasing.
o Useful for detecting deadlocks proactively by sharing global dependency information.

Comparison:
Feature Edge Chasing Path Pushing

Method Sends probes along edges . Shares full dependency paths.

Cycle Detection Based on returning probes. Based on merged paths.


Feature Edge Chasing Path Pushing

Overhead Lower communication. Higher communication/storage.

Use Case Simple deadlock detection . Detailed and proactive detection.

You might also like