Você está na página 1de 22

ELECTION ALGORITHM

PREPARED BY,
P.PON RADHA.
Definition

An algorithm for choosing a unique process


to play a to particular role is called an
election algorithm.
Election algorithms
Assumption: each process has a unique ID
Goal: find the noncrashed process with the
highest ID

There are two types of Election Algorithm.


They are:
Ring algorithm
Bully algorithm
ELECTION ALGORITHM
A process can call for at most one election at a time.
Multiple processes can call an election simultaneously.
Each process has
Variable called elected
An attribute value called attr, e.g., id, MAC address,
Network address,Process number.
T he process with the highest ID number will be the
new cooridnator
The requriments for election
algorithms

safety: only the process with the largest id


can send an elected message
liveness: every process in the ring
eventually participates in the election.
Ring based Election Algoithmn
1) All the process have unique id and arranged in a logical
ring
2) Each process knows its neighbors
Select process with highest ID
3)All messages are sent clockwise around the r ing
4) Assume that no failures occur,and system is asynchronous
5) The ultimate goal is to elect a single process cordinator
which has the largest identifier
Example-1: for Ring Based Algorithm
Example-2: for Ring Based Algorithm

Initiation:
1. Process 4 sends an
ELECTION message to its
successor (or next alive
process) with its ID
Initiation:
2. Each process adds its own ID
and forwards the ELECTION
message
Leader Election:
3. Message comes back to initiator, here the
initiator is 4.
4. Initiator announces the winner by sending
another message around the ring
Steps in Ring based election process

Intially,every process is marked as non-paticipant.Any


process can begin an election.
The starting process marks itself as participant and place
its identifier in a message to its neighbour
A process receives a message and compares it with its
own.If the arrived identifier is larger,it passes on the
message.
If arrived identifier is smaller and receiver is not a
participant, substitute its own identifier in the message and
If It does not forward the message if it is already a
partipicant
Performance Evaluation

The worst-case scenario occurs when the


counter-clockwise neighbor has the
highest identifier.
A total of N-1 messages is required to
reach the nearest neighbour.
Turnaroundtime=3N-1 sequential
message transmission time
Bully Algorithm

This algorithm allows process to crash


during an election,although it assumes the
message delivery between process is
reliable.
Assume that the system is synchronous to
use timeouts to detect a process failure and
each process knows which processes have
higher identifiers and that it can
communicate with all such processes.
Bully Algorithm
Key Idea: select process with highest ID

3 message types: election, answer, coordinator.


O(n2) messages required with n processes
In this algorithm,there are three types of messages:
Election message:This is sent to announce an
election message.
Answermessage:This is sent in response to
an election message.
Coordinatormessage:This is sent to announce
the identity of the elected process
timeout T = 2Ttransmitting (max transmission
delay) +Tprocessing (max processing delay)
Steps in Bully Algorithm Details
Any process P can initiate an election
P sends Election messages to all process with higher IDs
and awaits OK messages
If no OK messages, P becomes coordinator and sends
Coordinator messages to all processes with lower IDs
If it receives an OK, it drops out and waits for an Coordinator
message
If a process receives an Election message
Immediately sends Coordinator message if it is the process
with
highest ID
Otherwise, returns an OK and starts an election
If a process receives a Coordinator message, it treats
sender as the coordinator
1 1
5 5
2 2
election OK
6 6
4 election OK
4
election
3 3
0 0
7 7

Process p sends an election message to all higher-


numbered processes in the system.
If no process responds, then p becomes the coordinator.
If a higher-level process (q) responds, it sends p a
message that terminates ps role in the algorithm
The process q now calls an election (if it
1
has not already done so). 5
2 election
Repeat until no higher-level process
responds. The last process to call an 6
election wins the election. 4 election
The winner sends a message to other election
processes announcing itself as the new 0 3
coordinator. 7

1
5 1
2 OK 5
2
4 6 coordinator 6
4

0 3 3
0
7 7
If 7 comes back on line, it will call an election
1 1 1
5 5 5
2 2 2 election
election OK
6 6 6
4 election OK 4
4 election
election election
3 3 3
0 0 0
7 7 7

1
5 1
2 OK 5
2
4 6 coordinator 6
4

0 3 3
0
7 7
Figure 6-20
Performance of Bully Algorithm
Analysis
Best case scenario: The process with the second highest id
detect the failure .
N-2 coordinator messages are sent.
Turnaround time is one message transmission time.
Worst case scenario: When the process with the least id
detects the failure.
The message overhead is O(N2).
Turnaround time is approximately 5 message
transmission times if there are no failures during the
run: election, answer, election, answer, coordinator
THANK YOU

Você também pode gostar