Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 30

Universitè Dr.

tahar moulay de saida

Bully Algorithm
Présenter par:
Ms:bouhafs daoui
MS: khlef abdelkrim
MS: Fattah soufiane
Operating Systems play a critical role in managing
and coordinating the activities of a computer
system. In distributed systems, where multiple
computers work together to achieve a common goal,
the issue of node/process failure becomes a
significant concern. To ensure the reliability and fault
tolerance of a distributed system, leader election
algorithms come to the rescue. In this article, we will
discuss the leader election algorithm (Bully
algorithm) and understand how it guarantees the
election of a new coordinator when the current
coordinator fails
Leader Understanding Election Algorithm:
The election algorithm is based on the following assumptions:

1. Each process has a unique priority number.


2. All processes in the system are fully connected.
3. The process with the highest priority number will be
elected as coordinator.
4. Each process knows the process number of all other processes.
5. What the process doesn’t know is which process is up or down.
6. During recovery, the failed process can take appropriate
steps to resume the set of active processes.
Note: The goal of the election algorithm is to ensure the following factors:
There should be only one leader among the processes.
All Processes agree on who is the leader.
We have two election algorithms for two different configurations of
a distributed system.
1. Bully
Algorithm
2. Ring
Algorithm
Bully Algorithm
It follows all the assumptions discussed above in the
Election Algorithm.
Let’s say there are 6 Processes P0, P1, P2, P3, P4, P5
written in ascending order of their Process ID (i.e.,0,
1,2,3,4,5).
The Bully Algorithm operates on the
principle
of higher priority.
Messages in Bully Algorithm

There can be three types of


messages that processes exchange
with each other in the bully algorithm:
1. Election message: Sent to announce election.
2. OK (Alive) message: Responds to the Election message
3. Coordinator (Victory) message: Sent by winner

of the election to announce the new coordinator.

6
Steps Involved in Bully Algorithm
Step 1: Suppose Process P2 sends a message to coordinator P5 and P5 doesn’t
respond in a desired time t ( possible reason could be crash ; down

Step 2: Then process P2 , sends an election message to all processes with Process ID greater
than P2 (i.e. P3, P4 & P5) and awaits a response from the processes
Step 3: If no one responds, P2 wins the election and become the coordinator.
Step 4: If any of the processes with Process ID higher than 2 responds
with OK, P2’s job is done and
this Process will take over.
Step 5: It then restarts and initiates an election
message
Step 6: Process P4 responds to P3 with an OK message to confirm its alive state and Process
P4 figures out that process 5
has crashed, and the new process with the highest ID is process 4.
Step 7: The process that receives an election message sends a coordinator message if
it is the Process with
the highest ID (in this case it is P4).

P4 wins the election and becomes the new coordinator


Step 8: If a Process which was previously down (i.e. P5) comes back, it holds an election and
if it has the highest
Process Id
then it will become the new coordinator and sends message to all other processes.

P5 is the highest priority process , hence


became the coordinator
Practical Applications of the Bully Algorithm

•Leader Election: Electing leaders or coordinators


in distributed databases, server clusters, and fault-
tolerant systems.
The Bully Algorithm finds applications in various
distributed systems, including:
•Cluster Management: Ensuring that a single node
effectively manages cluster-wide tasks.
•Resource Allocation: Coordinating resource
allocation or access among multiple Processes.
Pros of the Bully algorithme

Simple: The bully algorithm is easy to understand


and implement.
Effective in small networks: The bully algorithm
has low overhead in smaller distributed systems.
Fault-tolerant: The bully algorithm can elect a
new leader if the current leader fails.
Cons of the Bully algorithme

Inefficient in large networks: The bully algorithm can introduce


message overhead and delays in larger distributed systems.
•Risk of starvation: Lower-ranked nodes may never become leaders in
some cases.
•Initialization challenges: The bully algorithm requires accurate
Process rankings, which can be difficult to achieve in practice.
•Lack of preemption: The bully algorithm is non-preemptive,
meaning that the current leader cannot be preempted by a
higher-ranked Process.
Conclusion
In distributed systems, the Bully Algorithm is a simple and
fault-tolerant leader election
technique. It performs well in small- to medium-sized networks,
maintaining order
in the event of a leader failure. However, it lacks preemption capabilities and its
efficiency can drop in larger networks.

Whether you're preparing for your first job interview or aiming to up skill
in this e
ver.-evolving tech landscape, GeeksforGeeks Courses are your key to success.
We provide
top-quality content at affordable prices, all geared towards accelerating your
growth in a time-bound manner.
Join the millions we've already empowered, and we're here to do
the same for you. D'ont miss out
The algorithme
The algorithme assumes That each processus has a Unique Iden
(UID) and That the processus Can arrange the selves in a
unidirectional ring with a communication Channel coing from e
process to the clockwise neighbour. The two part algorithme ca
described as follows:
1.Initially each process in the ring is marked as non-participant.

2.A process that notices a lack of leader starts an election.


It creates an election message containing its UID. It then sends t
message clockwise to its neighbour.

3-Every time a process sends or forwards an election message,


process also marks itself as a participant.
4-When a process receives an election message it compares
the UID in the message with its own UID.
1.If the UID in the élection message Is smaller, and the process Is not yet
a participant, the processus replaces the UID in
the message with its own UID, sends the update élection message in
a clockwise direction.
2-If the UID in the élection message Is smaller, and the
process Is already a participant
(i.e., the process has already sent out an élection message with
a UID at. least as large as its own UID), the process discards the élection mess
3-If the UID in the incoming élection message Is the same as the UID
of the process, That process stars acting as the leader.
4-If the UID in the élection message Is larger, the process unconditionally
forwards the élection message in a clockwise direction.
When a process starts acting as the leader, it begins the
second stage of the algorithm.
1. The leader process marks it self as non-participant and sends an
elected message to its neighbour announcing its election and UID.
.
2-When a process receives an elected message, it marks it self
as non-participant, records the elected UID,
and forwards the elected message unchanged.

3-When the elected message reaches the newly elected leader, the leader
discards That message, and the élection is over.

Assuming There are no failures this algorithm will finish.


The algorithm Works for any number of processes N,
and does not require any process to know how many processes are in the ring
Properties
The algorithm respects safety: a process will receive an elected message with its own
UID only if his UID is greater than others',
and only When all processes agrée on the same UID. The algorithm also respects
liveness. "Participant" and "not participant«
states are used so That When multiple processes start an élection at. roughly the same
time, only a single winner will be announced.
When there's a single process starting the élection, the algorithm requires 3N-1 sequenti
messages, in the worst case. Worst case is when the process starting the election is the
immédiate following to the one with greatest UID: it takes N-1 messages for the élection
message to reach it, then N messages for it to get back its own UID, then other N messag
send everyone in the ring the elected message.
This algorithm is not very fault tolerant. Fault tolerance Can be increased If every process
the whole topology, by introducing ACK messages and skipping faulty nodes on sending
messages.
See also
•Distributed computing
•Leader election
•Bully algorithm
•HS algorithm

You might also like