Distributed Leader Election Algorithms in Synchronous Ring Networks Valia Mitsou National Technical University of Athens
Distributed Computing Distributed computing is decentralised and parallel computing, where two or more processors communicate over a network to accomplish a common task. The collaborating processors are often identical. One of the central problems is…
Leader Election Given a network of processors, exactly one processor should output the decision that it is the leader. It is usually required that all non-leader processors are informed of the leader’s election. Βοηθάει στο να σπάει η συμμετρία και να μπορούμε να τρέχουμε centralized αλγόριθμους σε decentralized network.
The Synchronous Network Model
Network representation Directed Graph G(V,E), |V|= n Nodes represent processors Edges represent (directed) communication channels Message Passing System Global Clock (for every tic a step of the algorithm is executed)
Processor’s fields Every processor consists of the following: statesi (a not necessarily finite set of states) starti (the initial state) msgsi (a message generation function) transi (a state transition function) Κάθε επεξεργαστής αποτελείται από τα εξής πεδία: Ένα σύνολο καταστάσεων από το οποίο επιλέγει την τρέχουσα κατάστασή του κάθε φορά, δηλαδή τι τιμές θα έχουν κάθε στιγμή της οι μεταβλητές που θα χρησιμοποιήσει για την εκτέλεση του αλγόρίθμου. Η αρχική του κατάσταση είναι μια από το σύνολο καταστάσεων με την οποία ξεκινά την εκτέλεση (πώς αρχικοποιούνται οι μεταβλητές που χρησιμοποιεί) Μια γεννήτρια συνάρτηση μηνυμάτων βάσει της οποίας παράγει τα μηνύματα που θα στείλει στους γείτονές του Μια συνάρτηση μετάβασης καταστάσεων βάσει της οποίας θα υπολογίσει τη νέα κατάσταση, δηλαδή θα αλλάξει τιμές στις μεταβλητές.
Step Apply the message generation function to the current state to generate the messages to be sent to all outgoing neighbors. Apply the state transition function to the current state and the incoming messages to obtain the new state. Η εκτέλεση ξεκινά με όλους τους επεξεργαστές να βρίσκονται σε κάποια initial state. Μετά οι επεξεργαστές κάνουν τα ακόλουθα δύο πράγματα: Σύμφωνα με την κατάσταση που βρίσκονται υπολογίζουν το μήνυμα που θα στείλουν στους γείτονές τους και το στέλνουν Έπειτα ανάλογα με την τρέχουσα κατάστασή τους και τα μηνύματα που θα λάβουν υπολογίζουν την καινούρια κατάστασή τους. Αυτά αποτελούν ένα βήμα Ο κατανεμημένος υπολογισμός αποτελείται από κάποιο αριθμό τέτοιων βημάτων.
Complexity measures Time complexity: the number of the steps until all outputs are produced or all the processors halt. Communication complexity: the number of non-null messages that are sent during the execution. Αυτό που μας ενδιαφέρει κυρίως είναι το time αρκεί να μην επιβαρύνεται τόσο πολύ το σύστημα που να επιβραδύνεται η διαδικασία
Leader Election in Rings with UIDs
Setting The network graph is a directed ring consisting of n nodes (n is unknown to the processors). Processors run the same deterministic algorithm. The only piece of information supplied to the processors is a unique integer identifier (UID). Οι διαδικασίες είναι ακίνητες πάνω στους κόμβους και τρέχουν όλες ταυτόχρονα τον ίδιο ντετερμινιστικό αλγόριθμο. Αν το n είναι γνωστό τότε οι διαδικασίες μπορούν να το χρησιμοποιήσουν στα προγράμματα τους. Εκτός αυτού οι διαδικασίες έχουν και περιορισμένη δύναμη, δηλαδή μπορούν μόνο να στέλνουν κάποια μηνύματα στους out_nbrs που να περιέχουν περιορισμένη πληροφορία (το uid και ίσως και κάποιου είδους μετρητές ή διακριτικά) και να δέχονται τέτοια μηνύματα απο τους in_nbrs. Επίσης μπορούν να εκτελούν συγκρίσεις και ίσως και κάποιου είδους υπολογισμούς βάσει των οποίων θα αποφασίσουν αν θα στείλουν μήνυμα στις επόμενες διαδικασίες. Θα αποδείξουμε στη συνέχεια ότι αν οι διαικασίες ήταν πανομοιότυπες τότε θα ήταν αδύνατη η εκλογή αρχηγού, αφού δε θα είχαν κανένα στοιχείο που να τις ξεχωρίζει μεταξύ τους
Related Work and Important Results Algorithm Time Complexity Msg Complexity LCR (‘79) O(n) O(n2) HS (’80) O(nlogn) Our Algorithm O(nlogn) (better constant) Lower bound Ω(n) (trivial) Ω(nlogn) FL (’87) Franklin, Dolev- Klawe- Rodeh, Peterson, δικός μου
Our Algorithm
Basic Idea Every processor starts by sending a message with its UID Nodes which receive a UID greater than their own take on the task of forwarding it around the ring, while the node which initially possessed it becomes inactive. The processor that will become the leader is the one with the greatest UID and this will happen when its UID returns to itself after traveling around the ring.
Description Every processor has the following fields: Its own UID The greatest UID it has seen so far One activity field {active, inactive, waiting} One status field {leader, unknown}
Description The algorithm is executed in phases 0, 1, 2... Every phase k has two parts
First Part of Phase k Every active processor i sends a token with the greatest UID it has seen so far to travel for distance at most 2k.
First Part of Phase k When a processor receives a UID that is equal to its own UID, it declares itself the leader. If this is not the case then it compares it with the greatest UID it has seen so far.
First Part of Phase k If the incoming UID is smaller then it discards it. If the incoming UID is greater then It saves this UID as the greatest it has seen so far. Either it becomes waiting if it is the incoming UID’s end of path (it has already traveled distance 2k), or it passes it to the next processor and becomes inactive.
Second Part of Phase k After this time (2k), if i is still active resends the UID to travel distance 2k and becomes inactive. If a waiting processor receives again the same UID after 2k time then it becomes active. If not it becomes inactive. The next phase k+1 begins…
A Simple Example
4 7 2 5 2 4 7 5
4 7 2 5 2 4 7 5
4 7 2 5 2 2 4 5 4 7 7 5
4 7 2 5 2 5 4 5 4 7 7 7
4 7 2 5 5 4 7 7
4 7 2 5 5 4 4 7 7 7
4 2 5 4 4 7 7 5 7 7
A More Complicated Example
5 3 4 2 6 8 1 7 7 5 1 3 4 8 6 2
5 3 4 2 6 8 1 7 7 5 1 Phase 0 Part 1 Step 1 3 4 8 6 2
5 3 4 2 6 8 1 7 7 5 1 3 4 8 6 2
5 3 4 2 6 8 1 7 1 7 7 5 1 3 5 3 4 6 8 4 2 8 6 2
5 3 4 2 6 8 1 7 1 7 7 5 7 3 5 6 5 6 8 4 2 8 8 4
5 3 4 2 6 8 1 7 7 5 7 Phase 0 Part 2 Step 1 6 5 8 8 4
5 3 4 2 6 8 1 7 7 5 7 6 5 8 8 4
5 3 4 2 6 8 1 7 7 7 5 7 5 6 5 8 8 8 4
5 3 4 2 6 8 1 7 7 7 5 7 5 6 5 8 8 8 4
5 3 4 2 6 8 1 7 7 5 7 Phase 1 Part 1 Step 1 6 5 8 8 4
5 3 4 2 6 8 1 7 5 3 4 2 6 8 1 7 7 5 7 6 5 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8 8 8 8 7
5 3 4 2 6 8 1 7 8 8 8 8 8 8 8 8 7
5 3 4 2 6 8 1 7 8 8 8 8 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 Phase 2 Part 2 Step 1 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 Phase 2 Part 2 Step 2 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 Phase 2 Part 2 Step 3 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 Phase 2 Part 2 Step 4 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 8 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 8 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 Phase 3 Part 1 Step 1 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 8 8 8 8 8
5 3 4 2 6 8 1 7 8 8 8 8 8 8 8 8 8
5 1 7 8 8 8 3 8 8 4 8 8 2 8 6 8 8
Complexity Analysis
Execution Time Total running time = time until maximum UID reaches its initiator (one round = n steps) But how many phases will be executed until maxUID reaches its initiator?
5 1 7 3 4 2 8 8 6
5 1 7 3 4 8 2 8 6
5 1 7 8 3 4 2 8 6
5 1 7 3 4 8 2 8 6
5 1 7 3 4 2 8 8 6
Number of Phases f = total number of phases. 1 + 2 + 4 + … + 2f-1 < n → 2f – 1 < n 2f+1 – 1 ≥ n So f ≈ logn
Time Complexity In every phase i: 2 parts 2i steps each part Total running time 2 + 4 + 8 + … + 2f + rest ≤ ≤ 2f+2 – 2 = O(2logn) = = O(n) 2i+1 steps
Messages Only an active processor can initiate a message. Inactive processors pass the message to the final receiver
2i+1
In phase i+1 2i+1 → 1 active processor n → (n / 2i+1) active processors Every active processor causes 2∙2i+1= 2i+2 messages to be sent. Total number of messages in this phase: (n / 2i+1) ∙ 2i+2 ≈ 4n
Message Complexity Total number of phases ≈ logn Number of messages in every phase ≈ 4n The total number of messages during the execution is O(nlogn) with a constant factor 4 (improving a previous constant factor 8 in HS).
Complexity Time Complexity: O(n) Message Complexity: O(nlogn) For non-leader results we need n extra steps and n extra messages.
THANK YOU!
Leader Election in Anonymous Rings
General Lemma: If the network is symmetric (i.e. a ring) and anonymous (the processors haven’t UIDs) then it is impossible to elect a leader by a deterministic algorithm. [by Angluin (1980)] Probabilistic algorithms are used to break symmetry.
Itai and Rodeh Algorithm Assumption: processors know n. The Algorithm The algorithm proceeds in phases, each of them containing n steps. At every phase, a ≤ n processors are active (initially everyone). During each phase some processors may become inactive. At the beginning of every phase, every active processor decides with probability a-1 whether or not to become a candidate. To do that, it picks a random number r, 0<r<1 and if r<a-1, then it becomes a candidate and initiates a pebble to travel around the ring. Αυτός το 1990. Ένας προηγούμενός τους αλγόριθμος 1981, στηρίζεται στον αλγόριθμο LCR
Itai and Rodeh Algorithm To compute the number of candidates (c), each processor counts the pebbles it has seen. Number of pebbles counted = Number of candidates. At the end of the phase, every processor has calculated c. If c=1 then sole candidate becomes leader. If c>1 then a new phase begins with the new active processors (the candidates of the previous phase). If c=0 the phase was useless.
Itai and Rodeh Algorithm 0.46 0.04 a-1 = 1/10 c = 2 0.37 0.35 0.83 0.64 0.08 0.22 0.53 0.93
Itai and Rodeh Algorithm Useless phase 0.74 a-1 = 1/2 c = 2 0.88
Itai and Rodeh Algorithm 0.32 a-1 = 1/2 c = 1 0.69
Itai and Rodeh Algorithm The leader!!!
Itai and Rodeh Algorithm- Complexity Analysis p(a,c) : the probability that c out of a active processors become candidates. Then Proof: Xi a random variable, Xi=1 if i becomes a candidate, else 0 (bernoulli trial) Then X=ΣnXi= the number of processors become candidates. X~binomial distribution. Thus
Itai and Rodeh Algorithm- Complexity Analysis Average Case Time Complexity: 2.441716 · n Message Complexity: 2.441716 · n The number of pebbles initialized per phase is X (the number of active processors that become candidates). E[X ] = E[ΣaXi ] = Σa(E[Xi ]) = a · a-1 = 1 Thus, the expected message complexity per phase is n. Για n τείνει στο άπειρο το L = 2.441716 σταθερό Ο αριθμός αυτός διαισθητικά είναι σταθερός επειδή το Ε[Χ] = 1 Bit Complxity ίδια! Σημαντική βελτίωση από τον προηγούμενό τους αλγόριθμο ο οποίος ήταν O(nlogn)
Itai and Rodeh Algorithm- Complexity Analysis Theorem: The expected number of phases required to reduce the number of active processors from a to 1 l(a) converges to 2.441716… Proof sketch:
Itai and Rodeh Algorithm- Complexity Analysis For fixed c, L(a,c) converges, L( ,c) converges, . Thus, So, L ≈ 2.441716
Itai and Rodeh Algorithm- Complexity Analysis Average Case Time Complexity: 2.441716 · n Message Complexity: 2.441716 · n The number of pebbles initialized per phase is X (the number of active processors that become candidates). E[X ] = E[ΣaXi ] = Σa(E[Xi ]) = a · a-1 = 1 Thus, the expected message complexity per phase is n.