Distributed Algorithms (CAS 769) : Dr. Borzoo Bonakdarpour
Distributed Algorithms (CAS 769) : Dr. Borzoo Bonakdarpour
Distributed Algorithms (CAS 769) : Dr. Borzoo Bonakdarpour
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 1/43
Acknowledgments
Most of the contents of these slides are obtained from the
following:
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 2/43
Presentation outline
Leader Election
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 3/43
Leader Election
Goal
In an election algorithm, each computation should terminate in a
configuration where one process is the leader.
Assumptions
I All processes have the same local algorithm.
I The algorithm is decentralized: The initiators can be any non-empty set
of processes.
I Process id’s are unique, and from a totally ordered set.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 4/43
Election in Rings
We start with election algorithms in rings. In all these algorithms, the initiators
determine among themselves which one has the highest ID.
Initially, the initiators are active and all nominators are passive.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 5/43
Chang-Roberts Algorithm
Consider a directed ring. The idea of the algorithm is that only the message
with the highest id completes one round in the ring.
I Each initiator sends a message, tagged with its id.
I When p receives q with q < p, it purges the message.
I When p receives q with q > p, it becomes passive, and passes on the
message.
I When p receives p, it becomes the leader.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 6/43
Chang-Roberts Algorithm - Example
2 1
I Clockwise:
0 N(N + 1)
2
I Counter clockwise: 2N − 1
N −2 N −1
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 7/43
Franklin’s Algorithm
Each active process p repeatedly compares its own id with the id’s of its
nearest active neighbors on both sides.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 8/43
Franklin’s Algorithm
I Initially, initiators are active, and non-initiators are passive. Each active
process sends its id to its neighbors on either side.
I Let active process p receive q and r
I if max{q, r } < p, then p sends its id again
I if max{q, r } > p, then p becomes passive
I if max{q, r } = p, then p becomes the leader
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 9/43
Franklin’s Algorithm
In each round, at least half of the active processes become passive. So there
are at most log2 N rounds.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 10/43
Franklin’s Algorithm - Example
0 4
5 2
1 3
Franklin’s Algorithm - Example
0 4
5 2
1 3
Franklin’s Algorithm - Example
0 4
5 2
1 3
Franklin’s Algorithm - Example
0 4
5 2
1 3
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 11/43
Franklin’s Algorithm - Example
1
I after 1 round only node N − 1 is
2
active
I after 2 rounds node N − 1 is the
leader
0 Suppose this ring is directed with a
clockwise orientation.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 12/43
Dolev-Klawe-Rodeh Algorithm
Each active process p cannot easily compar its id with its nearest active
neighbors q and r .
This is resolved by performing this comparison not at p, but at its next (in the
direction of the ring) active neighbor r . I.e., the ids of p, q, and r are collected
at r :
I If p is larger than q and r , then r remains active and progresses to the
next round, where it assumes the id of r .
I If p is smaller than q or r , then r becomes passive.
I If p equals q and r , then r becomes the leader.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 13/43
Dolev-Klawe-Rodeh’s Algorithm - Details
−→ s −→ q −→ p −→ r −→ t −→
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 14/43
Dolev-Klawe-Rodeh Algorithm - Example
1 3
5 2
0 4
Dolev-Klawe-Rodeh Algorithm - Example
5
1 3
5 3
2
0
4 4
Dolev-Klawe-Rodeh Algorithm - Example
5
1 3
5 5
3
2
0
4 4
Dolev-Klawe-Rodeh Algorithm - Example
5
1 3
5 5
3
2
0
4 4
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 15/43
Leader Election in Trees
Let the two deciding processes determine which one of them becomes the
leader (e.g. the one with the largest id).
The Idea
Each process p collects ids from its children, computes the maximum of
these ids and its own, and passes on this maximum to its parent.
Later, p receives the overall maximum of the ids in the network from its
parent, which p passes on to its children.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 16/43
Leader Election in Trees - Wake-up phase
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 17/43
Leader Election in Trees - The Algorithm
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 18/43
Leader Election in Trees - Example
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 19/43
Echo Algorithm with Extinction
Idea
We let each process to start a run of the echo algorithm tagged with it id.
Only the wave started by the initiator with the largest id complete, after which
the initiator become the leader.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 20/43
Echo Algorithm with Extinction - Details
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 21/43
Presentation outline
Leader Election
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 22/43
Anonymous Networks
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 23/43
Election in Anonymous Networks
Impossibility Result
Theorem: There is no leader election algorithm for anonymous rings that
always terminates.
A configuration is symmetric if all processes are in the same state and all
channels carry the same messages.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 24/43
Election in Anonymous Networks
Fairness
An execution is strongly fair, if each event that is applicable in infinitely many
configurations, occurs infinitely often in the execution.
Election algorithm for anonymous rings have fair infinite executions. This is
because in transition γ0 → γ1 , it does not matter which event is used; we can
always build the transition sequence to the symmetric configuration γN . This
in turn means no event is ignored.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 25/43
Election in Anonymous Networks
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 26/43
Probabilistic Algorithms
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 27/43
Probabilistic Algorithms
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 28/43
Itai-Rodeh Election Algorithm
Assumptions
An anonymous, directed ring, where all processes know the ring size N.
The Idea
Each initiator selects a random id from {1, . . . , N}.
Challenge: Different processes may select the same id.
If several processes select the same largest id, they will start a new election
round, with a higher number.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 29/43
Itai-Rodeh Election Algorithm
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 30/43
Itai-Rodeh Election Algorithm
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 31/43
Itai-Rodeh Election Algorithm - Example
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 32/43
Election in Arbitrary Anonymous Networks
The echo algorithm with extinction, with random selection of id’s, can be used
for election in anonymous undirected networks in which all processes know
the network size.
The Idea
I The algorithm works in rounds and round number is used to recognize
messages from previous rounds.
I Each process randomly selects an id and runs the echo algorithm.
I When a process is hit by a wave with a higher round number than it
current wave, or with the same round number but a higher id, the
process becomes passive and moves to the other wave.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 33/43
Election in Arbitrary Anonymous Networks
Algorithm Details
Initially, initiators are active in round 0, and non-initiators are passive.
Each active process selects a random id ∈ {0, . . . , N}, and starts a wave,
tagged with its id and round number 0.
Let process p in wave i of round n be hit by wave j of round n0 :
I if n0 > n, or n0 = n and j > i, then p adopts wave j of round n0 , and treats
the message according to the echo algorithm
I if n0 < n, or n0 = n and j < i, then p purges the message
I if n0 = n and j = i , then p treats the message according to the echo
algorithm
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 34/43
Election in Arbitrary Anonymous Networks
Thus, each message sent upwards in the constructed tree reports the size
of its subtree.
Else, it selects a new id, and initiates a new wave, in the next round.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 35/43
Election in Arbitrary Anonymous Networks
The echo algorithm with extinction, with random selection of id’s is a Las
Vegas algorithm that terminates with probability one.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 36/43
Election in Arbitrary Anonymous Networks - Example
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 37/43
Election in Arbitrary Anonymous Networks - Example
The process at the left computes size 6, and becomes the leader.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 38/43
Computing the Size of an Anonymous Network
Impossibility Result
Theorem: There is no Las Vegas algorithm to compute the size
of an anonymous ring.
Because when a leader is known, the network size can be computed using a
wave algorithm.
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 39/43
Computing the Size of an Anonymous Network
Consider the ring p0 , . . . , p2N−1 build as follows where each pi0 is a copy of pi :
p1 p0
0
pN−1 pN−1
p00 p10
Each process p maintains an estimate estp of the ring size. Initially estp = 2.
(Always estp ≤ N.)
p initiates an estimate round (1) at the start of the algorithm, and (2) at each
update of estp .
Each round, p selects a random idp in {1, . . . , R}, sends (estp , idp , 1), and
waits for a message (est, id, h). (Always h ≤ est.)
I If est < estp , then p purges the message.
I Let est > estp .
I If h < est, then p sends (est, id, h + 1), and estp ← est
I If h = est, then estp ← est + 1.
I Let est = estp .
I If h < est, then p sends (est, id, h + 1).
I If h = est
I 6 idp , then estp ← est + 1.
If id =
I If id = idp , then p purges the message (possibly its own message returned).
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 41/43
Itai-Rodeh Ring Size Algorithm
When the algorithm terminates, estp ≤ N for all p. Also, espp converges to
the same value for all p. Why?
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 42/43
Itai-Rodeh Ring Size Algorithm
When the algorithm terminates, estp ≤ N for all p. Also, espp converges to
the same value for all p. Why?
This happens when in a round with an estimate est < N, all processes at
distance est from each other happen to select the same id.
j, 2
j, 2
i, 2 i, 2
k, 2
Itai-Rodeh Ring Size Algorithm - Example
j, 3
l, 2
i, 2 i, 2
k,
l, 32
Itai-Rodeh Ring Size Algorithm - Example
j, 3
l, 2
i, 3
l, 2 m,
i, 23
k,
l, 32
Itai-Rodeh Ring Size Algorithm - Example
j, 4
i,
l, 2
3
j,
i, 4
l, 2
3 m,
j, 23
i, 4
n,
l, 34
k, 2
Dr. Borzoo Bonakdarpour Distributed Algorithms (CAS 769) - McMaster University 43/43