GHS is an algorithm to elect a leader in the arbitrary network. It is based on building a minimal spanning tree (MST) of the network, and then based on it electing a leader.
Algorithm for building MST is very similar to the Kruskal's algorithm, although it has some specifics for the nodes distributed in the arbitrary networks. For example, the nodes have to communicate with each other in order to detect connected components, merge etc. After the MST is built, one of the nodes is chosen to be a leader. The notification is sent to all other nodes in the MST.
Basically, the goal of this algorithm is to identify the nodes in the network, and the elect a leader in the known field.
Showing posts with label leader election. Show all posts
Showing posts with label leader election. Show all posts
Leader Election: LeLann, Chang and Roberts algorithm (LCR)
This algorithm is for ring networks. Each message goes in the network from one process to another, ie no broadcasting. This means that each process knows exactly about only one other process - it's neighbor. This could be imagined as linked list.
Algorithm complexity is better than in bully algorithm, because its worst case is
Algorithm complexity is better than in bully algorithm, because its worst case is
O(N^2)
, which happens only if hosts are organized into the network using by increasing (or decreasing, depends on the what extreme is used) order of their UIDs.Leader Election: Bully Algorithm
Only the process with largest (smallest) UID becomes the leader. If some process sees that it's UID is extremal to the current leader UID, it will initiate leader election.
The are 3 types of messages:
The are 3 types of messages:
- election message - sent to announce election
- answer message - response to the election message
- coordinator message - sent to announce the identity of the elected leader
- Some process
P
finds that leader is not available (or coordinator is down). P
initiates a new leader election by broadcasting election message.- Each process replies with own UID
- If
P
finds a process with higher UID, it waits a bit and if there is no reply with higher UID, it will promote that host to leader. - However, if
P
receives a coordinator message with new leader, which UID is lower thanP
's UID, it will initiate another election.
N^2 + N
messages, as at any moment any process can try to start election, thus send election message, handle N answer messages and send coordinator message. As an optimization, the process can send messages to the processes with larger UID only, this will give us N^2 / 2 + N
messages, which is better, but not ideal.
Leader Election in Distributed System
One of the important problems of distributed computing is electing a leader process. Leader process is needed for multiple reasons: it could be used to make a final decision, it could be used to run any task that has to be run only by single process at a time (like finding a next task to execute and spreading execution between other hosts, acquiring a lock etc.), it may contain authoritative data and provide them to other nodes etc.
There are multiple leader election algorithms. Almost always, for most of the tasks it's possible to find the solution where there is no need of single leader:
There are multiple leader election algorithms. Almost always, for most of the tasks it's possible to find the solution where there is no need of single leader:
- for task scheduling the list of tasks, tasks could be partitioned and with locking spread over multiple hosts
- for making final decision, it's possible to come up with some consensus (like paxos algorithm)
- distributed locking could help other systems to avoid having a leader (again it might be based on some consensus algorithm like paxos or raft)
Subscribe to:
Posts (Atom)