Download presentation
Presentation is loading. Please wait.
Published byAylin Cogburn Modified over 10 years ago
1
Token-Dased DMX Algorithms n LeLann’s token ring n Suzuki-Kasami’s broadcast n Raymond’s tree
2
Token-Ring Algorithm (Le Lann, 1977?) n processes are arranged in a logical ring n initially, process 0 is given a token u token circulates around the ring in a fixed direction via point-to- point messages u when a process acquires the token, it has the right to enter the critical section F after exiting the CS, it passes the token on n evaluation: u N–1 messages required to enter the CS u not difficult to add new processes to ring u with unidirectional ring, mutual exclusion is fair, and no process starves u does not guarantee “happened-before” order of entry into the CS
3
Suzuki-Kasami’s Broadcast Algorithm (1985) n if a process wants to enter the critical section, and it does not have the token, it broadcasts a request message to all other processes in the system n the process that has the token will then send it to the requesting process u However, if it is in CS, it gets to finish before sending the token n a process holding the token can continuously enter the critical section until the token is requested n request vector at process i : u RN i [k] contains the largest sequence number received from process k in a request message n token consists of vector and a queue: u LN[k] contains the sequence number of the latest executed request from process k u Q is the queue of requesting process
4
Suzuki-Kasami’s Broadcast Algorithm (cont.) n requesting the CS: u when a process i wants to enter the CS, if it does not have the token, it: F increments its sequence number RN i [i] F sends a request message containing new sequence number to all processes in the system u when a process k receives the request(i,sn) message, it: F Sets RN k [i] to MAX(RN k [i], sn) If sn < RN k [i], the message is outdated u if process k has the token and is not in CS (i.e., is not using token), and if RN k [i] == LN[i]+1 (indicating an outstanding request) it sends the token to process i n executing the CS: u a process enters the CS when it acquires the token
5
n releasing the CS: u when a process i leaves the CS, it: F sets LN[i] of the token equal to RN i [i] indicates that its request RN i [i] has been executed F for every process k whose ID is not in the token queue Q, it appends its ID to Q if RN i [k] == LN[k]+1 indicates that process k has an outstanding request F if the token queue Q is nonempty after this update, it deletes the process ID at the head of Q and sends the token to that process gives priority to others’ requests otherwise, it keeps the token n evaluation: u N messages required to enter CS F otherwise (N-1) requests, 1 reply F note, no messages needed if process holds the token u synchronization delay – T Suzuki-Kasami’s Broadcast Algorithm (cont.)
6
Raymond’s Tree Algorithm (1989) n processors are arranged as a logical tree u Edges are directed toward the processor that holds the token (called the “holder”, initially the root of tree) n each processor has: u a variable holder that points to its neighbor on the directed path toward the holder of the token u a FIFO queue called request_q that holds its requests for the token, as well as any requests from neighbors that have requested but haven’t received the token F If request_q is non-empty, that implies the node has already sent the request at the head of its queue toward the holder T1 T2 T3 T4 T5 T6 T7
7
Raymond’s Tree Algorithm (cont.) n requesting the CS: u when a process wants to enter the CS, but it does not have the token, it: F adds its request to its request_q F if its request_q was empty before the addition, it sends a request message along the directed path toward the holder if the request_q was not empty, it’s already made a request, and has to wait u when a process in the path between the requesting process and the holder receives the request message, it F u when the holder receives a request message, it F sends the token (in a message) toward the requesting process F sets its holder variable to point toward that process (toward the new holder)
8
Raymond’s Tree Algorithm (cont.) n requesting the CS (cont.): u when a process in the path between the holder and the requesting process receives the token, it F deletes the top entry (the most current requesting process) from its request_q F sends the token toward the process referenced by the deleted entry, and sets its holder variable to point toward that process F If its request_q is not empty after this deletion, it sends a request message along the directed path toward the new holder (pointed to by the updated holder variable) n executing the CS: u a process can enter the CS when it receives the token and its own entry is at the top of its request_q F It deletes the top entry from the request_q, and enters the CS
9
Raymond’s tree algorithm (cont.) n Releasing the CS: u When a process leaves the CS F If its request_q is not empty (meaning a process has requested the token from it), it: Deletes the top entry from its request_q Sends the token toward the process referenced by the deleted entry, and sets its holder variable to point toward that process F If its request_q is not empty after this deletion (meaning more than one process has requested the token from it), it sends a request message along the directed path toward the new holder (pointed to by the updated holder variable) n greedy variant – a process may execute the CS if it has the token even if it is not at the top of the queue. How does this variant affect Raymond’s alg.?
10
Performance Comparison of DMX algs. n E – CS duration n T – time of message propagation n notice that Maekawa’s message complexity under hl is not correct in Singhal n for Raymond’s performance calculation: average distance between nodes in a tree is log(N)/2 u when system is idle – token is at root
11
Raymond’s tree algorithm (cont.) T1 T2 T3 T4 T5 T6 T7 4 req4 T1 T2 T3 T4 T5 T6 T7 4 req4 4 T1 T2 T3 T4 T5 T6 T7 4 tok4 4 T1 T2 T3 T4 T5 T6 T7 4 T1 T2 T3 T4 T5 T6 T7 4 tok4 T1 T2 T3 T4 T5 T6 T7 enters CS
12
Raymond’s tree algorithm (cont.) T1 T2 T3 T4 T5 T6 T7 4 req4 T1 T2 T3 T4 T5 T6 T7 4 req4 4 T1 T2 T3 T4 T5 T6 T7 4 req5 4 5 T1 T2 T3 T4 T5 T6 T7 4 tok4 5 4 5 T1 T2 T3 T4 T5 T6 T7 4 tok4 5 5 req5 T1 T2 T3 T4 T5 T6 T7 55 5 enters CS
13
Election algorithms n In a distributed system, many algorithms require a permanent or temporary leader: u Distributed mutual exclusion: F Central coordinator algorithm requires a coordinator F Token-ring algorithm, Suzuki-Kasami’s broadcast algorithm, and Raymond’s tree algorithm require an initial token holder u Distributed deadlock detection — maintainer of a global wait-for graph n If leader fails, must elect a new leader u Election algorithms assume there is a unique priority number for each process u Goal: elect the highest-priority process as the leader, tell all active processes u Second goal: allow a recovered leader to re-establish control (or at least, to identify the current leader)
14
Garcia-Molina’s bully algorithm (1993) n 3 types of messages: u Election —announce an election u Answer — acknowledge election msg. u Coordinator — announce new coordinator n The election: u A process begins an election when it notices the coordinator has failed F To do so, it sends election messages to all processes with a higher priority u It then awaits an answer message (from a live process with a higher priority) F If none arrives within a certain time, it declares itself the coordinator, and sends a coordinator message to all processes with a lower priority F If an answer message does arrive, it waits a certain time for a coordinator message to arrive from the new coordinator If none arrives, it begins another election
15
Garcia-Molina’s bully algorithm (cont.) n Result of the election: u If a process receives a coordinator message, it accepts the new coordinator n Participating in an election: u If a process receives an election message: F It sends back an answer message F It begins another election (with its higher-ups) unless it has already begun one n Failed processes: u When one restarts, it begins an election F Unless it knows it has the highest priority, in which case it just sends out coordinator messages to re-establish control n Evaluation: u N–2 messages in best case u O(N 2 ) messages in worst case
16
Chang and Roberts’ ring algorithm (1979) n processes are arranged in a logical ring u Every process is initially a non-participant n The election: u A process begins an election by F Marking itself as a participant F Sending an election message (containing its identifier) to its neighbor u When a process receives an election message, it compares the identifier that arrived in the message to its own: F If the arrived identifier is greater, then it: If it is not a participant, it: Marks itself as a participant Forwards the message to its neighbor F If the arrived identifier is smaller: If it is not a participant, it: –Marks itself as a participant –Substitutes its own identifier in the election message and sends it on If it is already a participant, it does nothing
17
Chang and Roberts’ ring algorithm (cont.) n The election: u When a process receives an election message, it compares…: F If the arrived identifier is that of the receiving process, then its identifier is the largest, so it becomes the coordinator It marks itself as a non-participant again, It sends an elected message to its neighbor, announcing the results of the election and its identity u When a process receives an elected message, it F Marks itself as a non-participant, and F Forwards the message to its neighbor n Evaluation: u 3N–1 messages in worst case F N–1 election messages to reach immediate neighbor in wrong direction, N election messages to elect it, then N elected messages to announce result
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.