Download presentation
Presentation is loading. Please wait.
Published byIsabel Sherman Modified over 9 years ago
1
Leader Election
2
Leader Election: the idea We study Leader Election in rings
3
Why rings? historical reasons –original motivation: regenerate lost token in token ring networks illustrates techniques and principles good for lower bounds and impossibility results
4
Outline Specification of Leader Election YAIR Leader election in asynchronous rings: An O(n 2 ) algorithm An O(nlog(n)) algorithm The revenge of the lower bound! Leader election in synchronous rings Breaking the (nlog(n)) barrier
5
Message passing: Model n processors p 0,…p n-1 connected by bi-directional communication channels topology represented by undirected graph p0p0 p2p2 p3p3 p4p4 p1p1 some links may be missing
6
Processors Each p i is a state machine state set Q i distinguished initial states could be infinite p i ’s state includes outbuf i [l]: set of messages sent on l-th channel and not yet delivered inbuf i [l]: set of messages delivered on l-th channel and not yet processed inbuf i initially empty outbuf i not accessible
7
State Transitions A state transition: input: accessible state of p i (doesn’t depend on outbuf i ) consumes all messages in inbuf i outputs at most a message per channel
8
Terminology Definition: A configuration is a vector C = (q 0,…,q n-1 ) each q i is a state of p i set of outbuf i are messages in transit In an initial configuration each q i is an initial state of p i Definition: An event is a computation event comp(i) a delivery event del(i,j,m) Definition: An execution is an infinite sequence C 0, 0,C 1, 1,… where C 0 is an initial configuration each C i is a configuration each i is an event Definition: A schedule for the above execution is the sequence of events 0, 1,…
9
Safety and Liveness Safety property : “nothing bad happens” holds in every finite execution prefix –Windows™ never crashes –if one general attacks, both do –a program never terminates with a wrong answer Liveness property: “something good eventually happens” no partial execution is irremediable –Windows™ always reboots –both generals eventually attack –a program eventually terminates Admissible executions satisfy safety and liveness properties for a particular system type.
10
A really cool theorem Every property is a combination of a safety property and a liveness property (Alpern and Schneider)
11
Asynchronous Message-Passing Systems if k = del(i,j,m) in C k-1 –m is in outbuf i [l], where l is p i ’s label for channel {p i, p j } in C k, –remove m from outbuf i [l] –add m to outbuf i [h], where h is p i ’s label for channel {p i, p j } if k = comp(i) p i changes state according to its transition function empties inbuf i in C k-1 might add messages to outbuf i in C k C 0, 0,C 1, 1,C 2 … Admissible if: Every processor takes an infinite number of computation steps Every message sent is eventually delivered
12
Synchronous Message-Passing Systems C 0, 0,C 1, 1,C 2 … all asynchronous constraints, plus execution partitioned into disjoint rounds one delivery event for every message in every outbuf followed by one computation event for every processor Remarks not realistic, but good for algorithm design good for lower bounds
13
Complexity TIME each processor’s state set includes terminated states termination: –all processors in terminated states –no messages in transit Synchronous: count number of rounds until termination Asynchronous: set unit of time as maximum message delay SPACE Count maximum total number of messages
14
The Problem Final states of processes partitioned in two classes: electednon-elected In every admissible execution, exactly one process (the leader) enters an elected state. All remaining enter a non- elected state Once entered a state, always in that state
15
Lots of variations... The ring can be unidirectional or bidirectional The number n of processors may be known or unknown Processors can be identical or can be somehow distinguished Communication may be synchronous or asynchronous
16
Uni- vs. Bidirectional In unidirectional rings, messages can only be sent in a clockwise direction
17
Can processors be distinguished? If no, anonymous algorithms Processors have no UID Formally: identical automata Can distinguish between left and right.
18
Can processors be distinguished? If yes: processors have unique IDs chosen from some large totally ordered space of ids (e.g. N + ) no constraint on which ID are used (e.g. integers may not be consecutive) IDs can be either manipulated only by certain operations (e.g. comparison) or by unrestricted operations
19
Is n known? If no, uniform algorithms Algorithm cannot use information about ring size
20
Communication: Asynchronous vs. Synchronous Asynchronous: no upper bound on message delivery time no centralized clock no bound on relative speed of processes Synchronous: communication in rounds In a round a process: –delivers all pending messages –takes an execution step (which may involve sending one or more messages) if no failures, every message sent is eventually delivered
21
An Impossibility Result Theorem There is no deterministic solution to the leader election problem for a synchronous, non-uniform, anonymous bidirectional ring. Proof Suppose that a solution exists for a system A of n > 1 processes. Each process of A starts in the same state Lemma The states of all processors at the end of the each round of the execution of A are the same. Proof By induction on number of rounds k Base case: k = 0 Easy, since processes start in same state. Inductive step: Lemma holds for k = t-1 –processors are identical up to round k = t-1 –send same messages to left and right neighbors every processors receives identical messages on left and right channel – all processors apply same transition function to identical states in round t – all processors have identical states at the end of round t Then, if one enters leader state, all do!
22
Observations What are the implication for asynchronous rings? What are the implication for uniform rings?
23
Outline Specification of Leader Election YAIR Leader election in asynchronous rings: An O(n 2 ) algorithm An O(nlog(n)) algorithm The revenge of the lower bound! Leader election in synchronous rings Breaking the (nlog(n)) barrier
24
The LCR Algorithm LeLann (1977), Chang and Roberts (1979) unidirectional asynchronous non anonymous: every process has uid uniform (does not depend on n) 3: upon receiving m from right 4:case 5: m.uid > uid i : 6:send m to left 7: m.uid < uid i : 8:discard m 9: m.uid = uid i : 10:leader := i 11:send to left 12:terminate endcase 13: upon receiving from right neighbor 14:leader := i 15:send to left 16:terminate 1: upon receiving no message 2:send uid i to left (clockwise)
25
Correctness messages from process with highest ID are never discarded therefore the correct leader is elected no other processor ID can traverse the entire ring therefore no one else is elected
26
Complexity Message complexity: O(n2)O(n2) Time complexity: O(n)O(n) Can we do better? This bound is tight… 0 1 2 n-1n-2
27
The HS algorithm Hirschenberg and Sinclair (1980) Ring is bidirectional Each process p i operates in phases In each phase l, p i sends out “tokens” containing uid i in both directions Tokens are intended to travel distance 2 l and return to p i Phase 2 Phase 0 Phase 1 Phase 2 However, tokens may not make it back Token continues outbound only if greater than tokens on path Otherwise discarded All processes always forward tokens moving inbound If p i receives its own token while it is going outbound, p i is the leader
28
The Protocol 1: upon receiving no message 2:if asleep then asleep := false send to left and right 12: upon receiving from right 13:case 14:uid j > uid i and h>1: 15:send to left 16:uid j > uid i and h=1: 17:send to right 18: uid j = uid i 19:leader := i 20:endcase 3: upon receiving from left 4:case 5:uid j > uid i and h>1 : 6:send to right 7:uid j > uid i and h=1 : 8:send to left 9: uid j = uid i : 10:leader := i 11:endcase 21: upon receiving from right 22:send to left 23:upon receiving from left 24:send to right 25: upon receiving from left and right 26:phase := phase +1 27:send (uid i,out,2 phase ) to left and 28:right 0:Init: asleep := true
29
Correctness Same as LCR: messages from process with highest ID are never discarded therefore the correct leader is elected no other processor ID can traverse the entire ring therefore no one else is elected
30
– Winners in phase l > 0 – Tokens travel distance – Total number of messages sent in phase l is bounded by Total number of phases No. of messages bound by which is Communication Complexity Every processor sends a token in phase 0 4n messages For phase l > 0, –the only processors to send a tokens are those who “won” in phase l-1 –There is a winner for every processors O(n log n) 2 l-1 +1 2l2l
31
Time Complexity Time for each phase l Final phase takes Next to last phase is Total time complexity excluding last phase Time complexity is at most 2 · 2 l = 2 l+1 n (tokens only traveling outbound) 3n to 5n
32
The revenge of the lower bound So far we have seen: a simple O(n 2 ) algorithm a more clever O(n log n) algorithm focus on message complexity Facts: (n log n) lower bound in asynchronous networks (n log n) lower bound in synchronous networks when using only comparisons
33
Outline Specification of Leader Election YAIR Leader election in asynchronous rings: An O(n 2 ) algorithm An O(nlog(n)) algorithm The revenge of the lower bound! Leader election in synchronous rings Breaking the (nlog(n)) barrier The rise and fall of randomization
34
Leader Election with fewer than O(n log n) messages Synchronous rings UID are positive integers Can be manipulated using arbitrary arithmetic operations TimeSlice n is known to all processors unidirectional communication O(n) messages VariableSpeeds n is not known to all processors unidirectional communication O(n) messages What about Time complexity?
35
What is special about synchronous rings? Can convey information by not sending a message “when your phone doesn’t ring, it’s me”
36
TimeSlice Runs in phases each phase consists of n rounds in phase i 0 –if no one elected yet –processor with id i –declares itself the leader –sends token with its UID around Message complexity: Time complexity: n · UID min n
37
VariableSpeeds Each process p i initiates a token Different tokens travel at different speeds: for token carrying UID v, 1 message every rounds (each process waits rounds after receiving the token before sending it out) Each process keeps track of smallest UID seen Discard token with UID greater than smallest UID
38
Complexity Analysis By the time UID min goes around the ring, the second smallest UID has gone only half way, third smallest a fourth of the way, etc. Forwarding the token carrying UID min has caused more messages than all the other tokens combined Message complexity bound by Time Complexity 2n2n
39
Variable start times Processors can start at protocol different times processors that wake up spontaneously (participants) send token with UID around ring processors that wake up on receiving a UID (relays) do not initiate their own token
40
A message life cycle A message is in phase one until it is received by an awake processor forwarded immediately A message is in phase two once received by an awake processor forwarded after rounds
41
The New Algorithm When participant receives a message from p i : if UID i larger than minimal seen (including own), swallow it otherwise, delay for rounds When relay receives a message from p i : if UID i larger than minimal seen (not including own), swallow it otherwise, delay for rounds
42
Correctness Lemma: Only the participant processor with the smallest identifier receives its token back Proof: Let p i be participating processor with smallest UID No processor can swallow UID i All tokens must go through p i, and will be swallowed No other processor can receive token back
43
Complexity Three categories of messages: phase one messages phase two messages sent before the message of eventual leader enters its second phase phase two messages sent after the eventual leader enters its second phase
44
Complexity Lemma: The total number of messages in the first category is at most n. Proof The lemma follows because at most one phase one message is forwarded by each processor Suppose p i forwards two phase 1 messages, carrying UID j and UID k Assume, WLOG, that p j closer to p i than p k. Them, phase 1 message with UID k must go through p j If p j awake, then it becomes a phase 2 message Otherwise, p j becomes a relay and does not send its UID
45
Complexity Lemma: The total number of messages in the second category is at most n Proof After the first process awakens, it takes at most n rounds before message with UID min reaches a participant During this time, token with UID v is responsible for messages at most Max number of messages obtained when UIDs are small (0,1,…,n-1) Max number of messages in second category:
46
Complexity Lemma: The total number of messages in the third category is at most 2n Proof: analogous to complexity analysis for Variable Speeds In summary: Message Complexity: At most 4n Time complexity
47
And now for something completely different... RANDOMIZATION
48
Randomized Algorithms Extend transition function to accept as input a random number from a bounded range under some fixed distribution
49
Why is it important? The bad news: randomization alone does not generally affect impossibility results –leader election in anonymous network still impossible! worst case bounds The good news: randomization + weakening of problem statement does
50
Example: Randomized Leader Election Impossibility in anonymous rings still holds but can now elect a leader with some probability So weaken LE as follows Safety: In every configuration of every admissible execution, at most one processor is in an elected state Liveness: At least one processor is elected with some non-zero probability Behaviors allowed by weakened specification: terminate without a leader never terminate
51
Back to Leader Election Use randomization to have processes generate a pseudo identifier Use a deterministic leader election algorithm to work with pseudo identifiers Not just any deterministic LE algorithm: needs to work correctly if multiple processes generate same pseudo id a plus is the ability to detect if no leader elected
52
A first result Assume synchronous ring non-uniform ring processor can randomly choose identifiers Theorem There is a randomized algorithm which, with probability c > 1/e, elects a leader in a synchronous ring; the algorithm sends O(n 2 ) messages
53
The Algorithm Initially 0: pid i := 1: send pid i to left 2: upon receiving from right 3:if |S| = n then 4:if pid i is unique max(S) then 5:elected := true 6:else 7:elected := false 8:else 9:send to left Observations: randomization used once one execution for each element of = {1,2} n Code for processor p i
54
{R : exec(R) satisfies P} exec(R): execution of R in Given a predicate P on executions Pr[P]: probability of event Definitions
55
Analysis What is the probability that the algorithm terminates with a leader? Message Complexity: O(n2)O(n2)
56
Not good enough? Trade off more time and messages for higher probability of success if |S| = n and p i detects no single max in S –choose new pid i –restart algorithm becomes a set of n-tuples each of which is a possibly infinite sequence over {1,2}
57
Analysis Probability of success in iteration k (1-c) k-1 · c Time complexity: worst-case number of iterations: expected number of iterations: Expected value of T: Expected message complexity: O(n2)O(n2)
58
Impossibility of Uniform Algorithms Theorem There is no uniform randomized algorithm for leader election in a synchronous anonymous ring that terminates in even a single execution for a single ring size
59
Summary No deterministic solution for anonymous rings No solution for uniform anonymous rings (even when using randomization) Protocols with O(n 2 ) and O(n logn) messages for uniform rings (n log n) lower bound on message complexity for practical protocols O(n) message complexity for uniform synchronous rings
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.