Distributed Mutual Exclusion and Synchronization Overview

distributed systems cs 15 440 n.w
1 / 37
Embed
Share

Explore the concepts of distributed mutual exclusion, synchronization, and election algorithms in distributed systems. Learn about permission-based and token-based approaches for achieving mutual exclusivity, along with centralized and decentralized algorithms. Dive into the intricacies of clock synchronization and the role of coordinators in managing shared resources.

  • Distributed Systems
  • Synchronization
  • Mutual Exclusion
  • Algorithms
  • Distributed Computing

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Distributed Systems CS 15-440 Synchronization - Part III Lecture 13, October 17, 2023 Mohammad Hammoud 1

  2. Today Last Session: Midterm exam Today s Session: Distributed Mutual Exclusion Election Algorithms Announcements: Midterm grades are out PS3 is due on Oct 19 P2 is due on Oct 24 by midnight

  3. Course Map Applications Programming Models Fast & Reliable or Efficient DS Replication & Consistency Fault-tolerance Communication Paradigms Architectures Naming Synchronization Correct or Effective DS Networks

  4. Course Map Applications Programming Models Replication & Consistency Fault-tolerance Communication Paradigms Architectures Naming Synchronization Networks

  5. Overview Synchronization Distributed Mutual Exclusion Election Algorithms Clock Synchronization Physical Clock Synchronization Logical Clock Synchronization

  6. Overview Synchronization Distributed Mutual Exclusion Election Algorithms Clock Synchronization Permission-based Approaches Token-based Approaches

  7. Types of Distributed Mutual Exclusion Mutual exclusion algorithms are classified into two categories: 1. Permission-based Approaches Request to access Coordinator C1 A process that wants to access a shared resource, requests the permission from one or more coordinators Client 1 Grant P1 Server Access Resource 2. Token-based Approaches Server Each shared resource has a token Resource Access Access The token is circulated among all the processes Access Client 1 Client 2 Client 3 P1 P2 P3 A process can access the resource if it has the token Token Token Token 7

  8. Overview Synchronization Distributed Mutual Exclusion Election Algorithms Clock Synchronization Permission-based Approaches Token-based Approaches Decentralized Algorithms Centralized Algorithms

  9. A Centralized Algorithm One process is elected as a coordinator (C) for a shared resource Coordinator maintains a Queue of access requests Whenever a process wants to access the resource, it sends a request message to the coordinator to access the resource P0 P1 P2 When the coordinator receives the request: If no other process is currently accessing the resource, it grants the permission to the process by sending a grant message If another process is accessing the resource, the coordinator queues the request, and does not reply to the requestor Grant Grant Req Req Rel Access Access C Resource P2 P1 Queue The process in action releases the exclusive access after accessing the resource Afterwards, the coordinator sends the grant message to the next process in the queue 9

  10. Discussion (+) Flexibility: Blocking vs. non-blocking requests The coordinator can block the requesting process until the resource is free Or, the coordinator can send a permission-denied message back to the process The process can poll the coordinator at a later time Or, the coordinator can queue the request (without blocking the requestor). Once the resource is released, it will send an explicit grant message to the process (+) Simplicity: The algorithm guarantees mutual exclusion, and is simple to implement (-) Fault-Tolerance Deficiency Centralized algorithms are vulnerable to a single-point of failure (at the coordinator) Processes cannot distinguish between a dead coordinator and a blocked request (-) Performance Bottleneck In a large-scale system, the single coordinator can be overwhelmed with requests 10

  11. Overview Synchronization Distributed Mutual Exclusion Election Algorithms Clock Synchronization Permission-based Approaches Token-based Approaches Decentralized Algorithms Centralized Algorithms

  12. A Decentralized Algorithm To avoid the drawbacks of the centralized algorithm, Lin et al. advocated a decentralized mutual exclusion algorithm Assumptions: Distributed processes are organized as a Distributed Hash Table (DHT) based system Each resource is replicatedn times The ithreplica of a resource rname is named as rname-i Every replica has its own coordinator for controlling access The coordinator for rname-i is determined by using a hash function Approach: Whenever a process wants to access the resource, it will have to get a majority vote from m > n/2 coordinators (assuming there are n coordinators) If a coordinator does not want to vote for a process (because it has already voted for another process), it will send a permission-denied message to the process

  13. A Decentralized Algorithm An Example If n=10 and m=7, then a process needs at-least 7 votes to access the resource C1 rname-1 Req C2 rname-2 Access OK 0 1 2 3 4 5 6 7 P0 C3 rname-3 C4 rname-4 Req C5 rname-5 0 1 2 3 P1 OK C6 rname-6 Deny C7 rname-7 Deny C8 rname-8 C9 rname-9 C10 rname-10 xth replica = of a resource rname = Coordinator j = Process i = Number of votes gained n Cj Pi rname-x

  14. Fault-tolerance in the Decentralized Algorithm This decentralized algorithm assumes that the coordinator recovers quickly from a failure However, the coordinator would have reset its state after recovery Coordinator could have forgotten any vote it had given earlier Thus, the coordinator may incorrectly grant permission to a process Mutual exclusion cannot be deterministically guaranteed But, can still be probabilistically guaranteed

  15. Probabilistic Guarantees When will mutual exclusion be violated? When enough coordinators, say f, out of m fail that will allow another process to proceed with a majority vote, while the current process is still accessing the shared resource Said differently, when the minority of the m coordinators are non-faulty I.e., when m f n/2 Or, when f m n/2

  16. Probabilistic Guarantees Let the probability of violating mutual exclusion be P Pv v Derivation of P Pv v Let T T be the lifetime of the coordinator Let p p= t t/T T be the probability that a coordinator crashes during time-interval t t Let P P[k k] be the probability that k k out of m m coordinators crash during the same interval The mutual exclusion violation probability P Pv v can be computed as: ? ??= ?[?] ?=? ?/2 In practice, this probability is typically very small For T T=3 hours, t t=10 s, n n=32, and m m=0.75n : P Pv v =10-40

  17. Quorum-Based Protocol This decentralized algorithm is an implementation of a more general protocol known as the quorum-based protocol The quorum-based protocolcan be implemented using a votingscheme, originally proposed by Thomas and subsequently generalized by Gifford Basic Idea: Clients are required to request and acquire the permission of multiple servers before either reading or writing from or to a replicated data item Rules on reads and writes should be established Each replica is assigned a version number, which is incremented on each write 17

  18. Quorum-Based Protocol Thomas s scheme: Consider a distributed file system and suppose that a file is replicated on N servers Write Rule: A client must first contact N/2 + 1 servers (a majority) before updating a file Once majority votes are acquired, the file is updated and its version number is incremented This is pursued at the N/2 + 1 replica sites Read Rule: A client must contact N/2 + 1 servers (a majority), asking them to send their version numbers of its requested file If all the version numbers are equal, this must be the most recent version of the file 18

  19. Quorum-Based Protocol Gifford s scheme: Read Rule: A client needs to assemble a read quorum, which is an arbitrary collection of any NR servers, or more Write Rule: To modify a file, a write quorum of at least NW servers is required The values of NR and NW are subject to the following two constraints: Constraint 1 (C1): NR + NW > N Constraint 2 (C2): NW > N/2 Premise: C1 prevents read-write (RW) conflicts C2 prevents write-write (WW) conflicts 19

  20. Giffords Scheme: Example 1 The most recent write quorum consisted of servers {C, D, , L} These servers got the new value & new version number (all of them) Write Quorum Read Quorum A B C D E F G H I J K L Any subsequent read quorum should include at least 1 member from the write quorum {C, D, , L} When a client looks at this member s version, it will notice that it has the highest version number, hence, it will read it NR = 3 and NW = 10 C1: NR + NW = 13 > N = 12 No RW conflicts C2: NW > 12/2 = 6 No WW conflicts 20

  21. Giffords Scheme: Example 2 Write Quorum Why violating C2 causes WW conflicts? If one client chooses {A, B, C, E, F, G} as its write quorum Read Quorum A B C D E F G H I J K L And another client chooses {D, H, I, J, K, L} as its write quorum NR = 7 and NW = 6 The two updates will be accepted without detecting that they actually conflict, thus leading to an inconsistent view! C1: NR + NW = 13 > N = 12 No RW conflicts C2: NW > 12/2 = 6 WW conflicts may arise 21

  22. Giffords Scheme: Example 3 Read Quorum A client can read a replicated file by finding any copy Good read performance! Write Quorum A B C D E F G H I J K L A client needs to attain a write quorum on all copies Slow write performance! NR = 1 and NW = 12 This example demonstrates a scheme that is generally referred to as ROWA (or Read-Once, Write-All) C1: NR + NW = 13 > N = 12 No RW conflicts C2: NW > 12/2 = 6 No WW conflicts 22

  23. Overview Synchronization Distributed Mutual Exclusion Election Algorithms Clock Synchronization Permission-based Approaches Token-based Approaches Token Ring Algorithms Decentralized Algorithms Centralized Algorithms

  24. A Token Ring Algorithm With a token ring algorithm: Each resource is associated with a token The token is circulated among the processes The process with the token can access the resource How is the token circulated among processes? All processes form a logical ring where each process knows its next process One process is given the token to access the resource The process with the token has the right to access the resource If the process has finished accessing the resource OR does not want to access the resource: It passes the token to the next process in the ring Resource Access T T P0 T P7 P1 P6 P2 T T P5 P3 T P4 T T

  25. Discussion about Token Ring Token ring approach provides deterministic mutual exclusion There is one token, and the resource cannot be accessed without a token Token ring approach avoids starvation Each process will receive the token Token ring has a high-message overhead When no processes need the resource, the token circulates at a high-speed If the token is lost, it must be re-generated Detecting the loss of the token is difficult (especially if the amount of time between successive appearances of the token is unbounded) Dead processes must be purged from the ring ACK based token delivery can assist in purging dead processes

  26. Comparison of Mutual Exclusion Algorithms Delay before a process can access the resource (in message times) Number of messages required for a process to access and release the shared resource Algorithm Problems Coordinator crashes 2 3 Centralized Decentralized Large number of messages 2mk 2mk + m; k=1,2, Token Ring Token may be lost Ring can cease to exist since processes may crash 1 to n 0 to (n-1) Assume that: n = Number of processes in the distributed system For the Decentralized algorithm: m = minimum number of coordinators who have to agree for a process to access a resource k = average number of requests made by the process to a coordinator to request for a vote

  27. Overview Synchronization Distributed Mutual Exclusion Election Algorithms Clock Synchronization Permission-based Approaches Token-based Approaches Token Ring Algorithms Decentralized Algorithms Centralized Algorithms

  28. Overview Synchronization Distributed Mutual Exclusion Election Algorithms Clock Synchronization

  29. Election in Distributed Systems Many distributed algorithms require one process to act as a coordinator Typically, it does not matter which process is elected as the coordinator Coordinator C1 Time server Client 1 P1 Server Resource A Centralized Mutual Exclusion Algorithm Home Node Selection in Naming Berkeley Clock Synchronization Algorithm

  30. The Election Process In a Nutshell We assume that any process Pi can initiate the election algorithm to elect a new coordinator At the end of the election algorithm, the elected coordinator should be unique Every process may know the process ID of every other process, but it does not know which processes have crashed Generally, we require that the coordinator is the process with the largest process ID This idea can be extended to elect the best coordinator E.g.,: Electing the process with the least computational load If the computational load of process Pi is denoted by loadi, the coordinator will be the process with the highest 1/loadi. Ties are broken by sorting IDs

  31. Overview Synchronization Distributed Mutual Exclusion Election Algorithms Clock Synchronization Bully Ring Algorithms Algorithms

  32. A Bully Algorithm A process (say, Pi) initiates the election algorithm when it notices that the existing coordinator is not responding Process Pi calls for an election as follows: 1. Pisends an Election message to all processes with higher process IDs 1 2 5 Election Take-Over 2. When process Pj with j>i receives the message, it responds with a Take-over message. Pi no more contests in the election i. Process Pj re-initiates another call for election. Steps 1 and 2 continue If no one responds, Pi wins the election. Pi sends Coordinator message to every process 4 6 Coordinator Election Take-over 0 3 7 3.

  33. Overview Synchronization Distributed Mutual Exclusion Election Algorithms Clock Synchronization Bully Ring Algorithms Algorithms

  34. A Ring Algorithm This algorithm is generally used in a ring topology When a process Pi detects that the coordinator has crashed, it initiates the election algorithm 1. Pibuilds an Election message (E), and sends it to its next node. It inserts its ID into the Election message E: 5,6,0 C: 6 E: 5,6,0,1 C: 6 1 0 2 When process Pjreceives the message, it appends its ID and forwards the message i. If the next node has crashed, Pj finds the next alive node 2. E: 5,6,0,1,2 C: 6 7 3 E: 5,6 C: 6 E: 5,6,0,1,2,3 C: 6 E: 5 C: 6 When the message gets back to Pi: i. Pielects the process with the highest ID as coordinator ii. Pichanges the message type to a Coordination message (C) and triggers its circulation in the ring 6 4 3. 5 E: 5,6,0,1,2,3,4 C: 6 34

  35. Comparison of Election Algorithms Number of Messages for Electing a Coordinator Algorithm Problems O(n2) Bully Algorithm Large message overhead 2n Ring Algorithm An overlay ring topology is necessary Assume that: n = Number of processes in the distributed system 35

  36. Summary of Election Algorithms Election algorithms are used for choosing a unique process that will coordinate certain activities At the end of an election algorithm, all nodes should uniquely identify the coordinator We studied two algorithms for performing elections: Bully algorithms Processes communicate in a distributed manner to elect a coordinator Ring algorithms Processes in a ring topology circulate election messages to choose a coordinator 36

  37. Next Lecture Message Passing Interface (MPI)

More Related Content