Open In App

Bully Algorithm in Distributed System

Last Updated : 28 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Understanding Leader 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.

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, etc.)

Step1

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.

Initiation of Election by P2

Initiation of Election by P2

Step 3: If no one responds, P2 wins the election and become the coordinator.

Step3

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.

Step4

Step 5: It then restarts and initiates an election message.

Re-initialization of Election

Re-initialization of Election

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.

Step6

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

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.

P5 is the highest priority process , hence became the coordinator.

Practical Applications of the Bully Algorithm

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.
  • Leader Election: Electing leaders or coordinators in distributed databases, server clusters, and fault-tolerant systems.

Pros of the Bully algorithm

  • 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 algorithm

  • 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.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads