0% found this document useful (0 votes)
6 views14 pages

Bully Algorithm

The document outlines several algorithms for coordinator election and mutual exclusion in distributed systems, including the Bully, Ring, Raft Consensus, Ricart-Agrawala, and Lamport's algorithms. Each algorithm has its own mechanism for selecting a coordinator or managing access to critical sections, emphasizing aspects like fault tolerance, message complexity, and scalability. Key features, advantages, and drawbacks of each algorithm are discussed, highlighting their applicability in distributed environments.

Uploaded by

agamjot.kaur888
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)
6 views14 pages

Bully Algorithm

The document outlines several algorithms for coordinator election and mutual exclusion in distributed systems, including the Bully, Ring, Raft Consensus, Ricart-Agrawala, and Lamport's algorithms. Each algorithm has its own mechanism for selecting a coordinator or managing access to critical sections, emphasizing aspects like fault tolerance, message complexity, and scalability. Key features, advantages, and drawbacks of each algorithm are discussed, highlighting their applicability in distributed environments.

Uploaded by

agamjot.kaur888
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/ 14

Algorithms

1) Bully Algorithm
2) Ring Algorithm
3) Raft Consensus Algorithm
4) Ricart’s Agarwala’s Algorithm
5) Lamport’s Algorithm

Bully Algorithm
Bully Algorithm starts its process of selecting of coordinator when a working
process notices that the coordinator is not responding to it and then initiates
an election. The selection of a coordinator sends an election message to all the
other available processes.
 If none of the process responds to its message the process itself wins the
election and becomes the coordinator.
 Meanwhile, if any process that has a higher ID than the initiating process
answers, it takes charge of initiating the process.
 In this algorithm, the bully guy that is the participating process that has
the highest ID becomes the coordinator. This approach is efficient in
terms of fault tolerance but complex to implement.
Ring Algorithm
Ring Algorithm starts its process of selecting of coordinator once any process
connected in the ring notices that the coordinator is not functioning. The
initiating process then prepares an election message that contains its own
process number and then sends this message to its successor in the ring. If the
successor is not functioning then it kills that successor and sends it to the next
one.
 Every next process then adds its process number to the message and
delivers the message to the next process connected in the ring.
 It continues until the message again reaches the initiating process.
 Now the message consists of the process number of all the functioning
processes.
 The process that has the highest ID wins the election. The initiating process
then sends another message in the ring about the winning process.

Ring Algorithm
Raft Consensus Algorithm
The Raft Consensus Algorithm is a leader-based protocol used in distributed
systems to ensure that all nodes within a cluster agree on a single state of data,
even in the event of node failures.
By electing a designated leader who manages the replication of logs across all
nodes and makes decisions on behalf of the cluster; essentially, it allows a
group of computers to reach consensus on a value by electing a leader to
coordinate the decision-making process.
Making it a reliable way to manage data consistency in distributed systems.

Key points about Raft:


 Leader Election:
A primary function of Raft is to elect a leader from among the nodes in the
cluster, who is responsible for managing the replication of data across all
nodes.
 Log Replication:
The leader maintains a log of all operations (like writes or updates) and
replicates this log to all followers (other nodes in the cluster) to ensure
consistency.
 Three Roles:
Each node in a Raft cluster can be in one of three states: Leader, Follower, or
Candidate.
 Heartbeat Mechanism:
Leaders periodically send "heartbeat" messages to followers to maintain their
leadership status.
 Election Timeout:If a follower does not receive a heartbeat from the
leader within a certain time frame, it initiates a new leader election
process.
How Raft works:
1. Initial State: All nodes start as followers.
2. Leader Election: If no leader is currently active, a node becomes a
candidate and sends "Request Vote" messages to other nodes to solicit
votes.
3. Leader Selection: The candidate with a majority of votes becomes the
leader.
4. Log Replication: The leader appends new log entries to its log and sends
them to followers.
5. Committing Entries: Once a majority of followers have acknowledged
receiving a log entry, the leader considers it committed and applies it to
its state machine.
6. State Machine Application: All nodes in the cluster apply committed log
entries to their local state machines in the same order, ensuring
consistency.
Benefits of Raft:
 Easy to Understand: Compared to other consensus algorithms like Paxos,
Raft is considered relatively simple to implement and understand.
 Fault Tolerance: Raft can handle node failures by electing a new leader
when the current leader becomes unavailable.
 Scalability: Raft can be used in large distributed systems with many
nodes.
Ricart–Agrawala Algorithm in Mutual
Exclusion in Distributed System

Ricart–Agrawala algorithm is an algorithm for mutual exclusion


in a distributed system proposed by Glenn Ricart and Ashok
Agrawala. This algorithm is an extension and optimization of
Lamport’s Distributed Mutual Exclusion Algorithm. Like Lamport’s
Algorithm, it also follows permission-based approach to ensure
mutual exclusion. In this algorithm:

 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 the critical section.
 A site send a REPLY message to another site to give its
permission to enter the critical section.
 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 send a
timestamped REQUEST message to all
other sites.

o When a site Sj receives


a REQUEST message from site Si, It sends
a REPLY message to site Si if and only if
o Site Sj is neither requesting nor
currently executing the critical
section.
o In case Site Sj is requesting,
the timestamp of Site Si‘s
request is smaller than its own
request.
 To execute the critical section:
o Site Si enters the critical section if it has
received the REPLY message from all other
sites.
 To release the critical section:
o Upon exiting site Si sends REPLY message
to all the deferred requests.
Message Complexity: Ricart–Agrawala algorithm requires
invocation of 2(N – 1) messages per critical section execution.
These 2(N – 1) messages involves
 (N – 1) request messages
 (N – 1) reply messages

Advantages of the Ricart-Agrawala Algorithm:


 Low message complexity: The algorithm has a low
message complexity as it requires only (N-1) messages to
enter the critical section, where N is the total number of
nodes in the system.
 Scalability: The algorithm is scalable and can be used in
systems with a large number of nodes.
 Non-blocking: The algorithm is non-blocking, which
means that a node can continue executing its normal
operations while waiting to enter the critical section.

Drawbacks of Ricart–Agrawala algorithm:


 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.
Performance:
 Synchronization delay is equal to maximum message
transmission time
 It requires 2(N – 1) messages per Critical section
execution

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.

A 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:
How does Lamport’s algorithm ensure mutual
exclusion in a distributed system?

 Lamport’s algorithm uses a permission-based approach and


timestamps to order critical section requests and resolve
any conflicts between them.

 Each process sends a request message to all other


processes to enter the critical section, and the request is
placed in the request queue of each process in the order of
its timestamp.

 A process can enter the critical section if it has received a


reply message from all other processes with a timestamp
greater than its own, and its own request is at the top of its
request queue.

What is the message complexity of Lamport’s algorithm?


Lamport’s algorithm requires 3(N-1) messages per critical section
execution, where N is the number of processes in the system.
These messages involve (N-1) request messages, (N-1) reply
messages,
and (N-1) release messages.

Is Lamport’s algorithm fault-tolerant?


No, Lamport’s algorithm does not provide any fault tolerance
mechanism. If a process fails or crashes, it may cause the entire
system to fail or become unstable.

You might also like