1 Leader Election in Rings
2 A Ring Network
Sense of direction left right
Links are bi-directional for messages At most one message in each direction
Anonymous Ring
6 Eponymous (non-anonymous) Ring
7 Leader Election Initial stateFinal state leader
8 Leader election algorithms are affected by: Anonymous Ring Eponymous Ring The size of the network is known The size of the network is not known Synchronous Algorithm Asynchronous Algorithm
9 Synchronous Anonymous Rings Every processor runs the same algorithm Every processor does exactly the same execution
10 Initial stateFinal state leader If one node is elected a leader, then every node is elected a leader
11 Final state leader Conclusion 1: Leader election cannot be solved in synchronous anonymous rings
12 Final state leader Conclusion 2: Leader election cannot be solved in asynchronous anonymous rings either Why? The asynchronous ring may behave Like the synchronous ring
13 Asynchronous Eponymous Rings The maximum id node is elected leader
Each node sends a message with its id to the left neighbor
If: message received id current node id Then: forward message
If: message received id current node id 8 7 Then: forward message
If: message received id current node id 8 7 Then: forward message
If: message received id current node id 8 Then: forward message
If: a node receives its own message 8 Then: it elects itself a leader
If: a node receives its own message Then: it elects itself a leader leader
leader The leader sends a message in the network declaring itself as the “leader of the ring”
leader Time complexity: nodes
23 1 n-1 n-3 2 n-2 n Message complexity:nodes worst case scenario:
24 1 n-1 n-3 2 n-2 n Message complexity:nodes messages
25 1 n-1 n-3 2 n-2 n Message complexity:nodes messages
26 1 n-1 n-3 2 n-2 n Message complexity:nodes messages
27 1 n-1 n-3 2 n-2 n Message complexity:nodes Total messages:
28 Notes: does not need to be known to the algorithm The algorithm can be converted to asynchronous
29 An O(n log n) Mess. Algorithm Again, the maximum id node is elected leader
nodes
Phase 1: send id to 1-neighborhood
32 If: received id current id Then: send a reply
33 If: a node receives both replies Then: it becomes a temporal leader
Phase 2: send id to 2-neighborhood
If: received id current id Then: forward the message
36 If: received id current id Then: send a reply At second step:
If: a node receives both replies Then: it becomes a temporal leader
Phase 3: send id to -neighborhood
If: received id current id Then: forward the message
If: received id current id Then: send a reply At the step:
If: a node receives both replies Then: it becomes the leader
leader
leader nodesphases In general:
leader Phase i: send id to -neighborhood
45 Time complexity The leader spends time in Phase 1: 2 Phase 2: 4 … Phase i: … Phase log n: Total time:
46 Phase 1: 4 Phase 2: 8 … Phase i: … Phase log n: Message complexity Messages per leader Max #leaders
47 Phase 1: 4 Phase 2: 8 … Phase i: … Phase log n: Total messages: Messages per leader Max #leaders
48 Notes: The algorithm does not need to know It can be converted to an asynchronous algorithm
49 An Mess. Synchronous Algorithm The node with smallest id is elected leader There are rounds: If in round there is a node with id this is the new leader the algorithm terminates is known
50 Round 1 ( time steps): no message sent nodes
nodes Round 2 ( time steps): no message sent
nodes Round 9 9 new leader
nodes Round 9 ( time steps): messages sent 9 new leader
nodes Round 9 ( time steps): messages sent 9 new leader Algorithm Terminates
nodes Round 9 ( time steps): messages sent 9 new leader Total number of messages:
56 Another Synchronous Algorithm The node with smallest id is elected leader is not known
57 The algorithm: Each node injects a message with its id Message with id is injected and transferred with rate Nodes which have seen smaller id absorb higher id messages
Time 1 0 Transfer rate
Time rate
Time 3 0 1
Time 4 0 1
Time 5 0
Time 6 0
Time 8 0
65 Time New leader
66 Message complexity Assume leader has (smallest) id Total time of algorithm: Note that if then algorithm is exponentially slow
67 Take the node with immediately higher id Total number of messages:
68 Take the node with immediately higher id Total number of messages:
69 id messages lower higher Total messages:
70 An Lower Bound Assume we have algorithms in which: the maximum identifier is elected leader all the nodes must know the leader We will prove: at least messages are needed the size of the network is not known to elect a leader the network is asynchronous
71 open edge no messages cross it There is a possible asynchronous execution with an open edge (i.e. a very slow edge) Messages may be pending to cross open edge
72 open edge If the edge remains open, then the execution will eventually reach a quiescent state where not more messages cross the ring Messages pending to cross open edge Quiescent State
73 open edge Messages pending to cross open edge Quiescent State In the quiescent state, a node can send a message only after it receives a message (thus no messages cross the ring)
74 This may cause a propagation of messages until the algorithm terminates Suppose that the edge closes Time t
75 This may cause a propagation of messages until the algorithm terminates Time t+1
76 This may cause a propagation of messages until the algorithm terminates Time t+2
77 Time t+k k k After k time steps the affected radius is k
78 Time t+x Eventually, the ring stabilizes with a leader
79 We will show, that there is an execution with nodes such that: there is an open edge at least messages are received where
80 x y basis case If then is the leader should know about this Therefore a message is sent: Proof by induction
81 x y open edge The message can be sent on one edge
82 The case From induction hypothesis, we have an execution: open edge Messages sent nodes
83 The case open edges Messages sent nodes From induction hypothesis, we have an execution:
84 Observation: If no message is sent along then ring cannot distinguish the two scenarios (similarly for ring )
85 Messages sent nodes Therefore, the same number of messages have to be sent in sub-rings True open edge True open edge
86 max id All nodes in should learn about (assume that max id is in ) open edge
87 max id All nodes in should learn about Thus, after the open edges close, at least messages are sent (At least one of these is sent)
88 max id Suppose edges close at time At least one message is sent
89 max id time At least one message is sent
90 max id time At least messages have been sent since
91 max id time radius At least messages have been sent since
92 max id time radius At least messages have been sent since Independent areas
93 max id time radius At least messages have been sent in one area Independent areas Messages
94 max id time radius open edge Since areas are independent, we could have closed only one edge Messages
95 max id time radius open edge Messages Induction Hypothesis Total Messages