1 / 20

Distributed Mutual Exclusion Algorithms in Synchronization

Explore the different approaches to achieving mutual exclusion in distributed systems and the algorithms used for synchronization. Learn about centralized and distributed algorithms, token-based and non-token-based approaches, and evaluate performance metrics. Examples of algorithms like Lamport's, Ricart and Agrawala's, and Maekawa's are discussed.

mcauliffe
Download Presentation

Distributed Mutual Exclusion Algorithms in Synchronization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Synchronization (2) – Mutual Exclusion Chapter 5 (section 5.5 + extra reading) Synchronization (2)

  2. Mutual Exclusion (ME) • In a single-processor system, ME can be achieved with semaphores, lock variables, monitors, etc. (Did anyone actually read the optional readings?) • In distributed systems, ME is more complex due to the absence of shared memory, timing (communication delays and clock synchronization) and the ordering of events (or lack thereof) Synchronization (2)

  3. Mutual Exclusion (ME) (cont’d) • Two basic approaches to ME in distributed systems can be identified: • Centralized: Master and slaves, master dictates actions • Distributed: each site decides on actions, based on own state • Distributed algorithms can be subdivided into: • Token based: a site is allowed in the CS if has a token. Tokens are passed from site to site, in some priority order • Non-token based: site enters CS when an assertion becomes TRUE. A site communicates with others to get information about the other sites’ states, and based on this, decides whether the assertion is TRUE or FALSE. This communication is usually based on timestamps Synchronization (2)

  4. ME requirements • For a solution to be correct, the algorithms must have the following properties • Deadlock freedom • Starvation freedom • Fairness: give everyone a chance, in certain systems it also means to execute the requests as they are made (e.g., Logical FIFO) Synchronization (2)

  5. Evaluating Distributed ME Solutions • Performance metrics • Number of messages sent, received, or both • Synchronization delay • Response time • System throughput • Conditions under which we must test performance • High vs. low load behaviors • Worst vs. best vs. average case behaviors Synchronization (2)

  6. Mutual Exclusion: A Centralized Algorithm • Process 1 asks the coordinator for permission to enter a critical region. Permission is granted • Process 2 then asks permission to enter the same critical region. The coordinator does not reply. • When process 1 exits the critical region, it tells the coordinator, which then replies to 2 Synchronization (2)

  7. Bottleneck network congestion timeout Site 1 Site 1 has critical section; will yield to the master; master will grant to site x Master Site 2 Site 3 List of requests Simple Solution: Centralized ME • Centralized approach: Master holds a list of processes requesting the CS; grants requests in some order (random, FIFO, etc.) • Advantages: fair, correct, no starvation, simple to implement • Disadvantages: single point of failure and bottleneck Synchronization (2)

  8. Time P1 P2 P3 Request for CS Distributed ME • Problem: if messages are not ordered correctly, the CS can be acquired improperly (remember that if there are no global timestamps, the “earliest” request should gain the CS) • In the example below, P3 thinks that P1 should have the CS (P3 got P1’s message first), while both P1 and P2 think that P2 should have it. • In a distributed algorithm, the decision must be made independently from other nodes in the system, AND the decision should be the same at all nodes. Synchronization (2)

  9. A Distributed Algorithm • Two processes want to enter the same critical region at the same moment. • Process 0 has the lowest timestamp, so it wins. • When process 0 is done, it sends an OK also, so 2 can now enter the critical region. Synchronization (2)

  10. Distributed ME • Lamport’s algorithm solves the problem above, with the logical clocks. • To request CS: • send req message M to all processes; • enQ M in its own queue • Upon receiving request from Pi: enQ and send ack • Upon receiving release from Pi: deQ • To release CS: • send ack message to all procs • remove it from Q • To acquire CS: enter CS when got a message with a larger timestamp from every other proc AND has own message with smallest TS in own Q Note that to enter the CS, checks must only be made locally Synchronization (2)

  11. Distributed ME • Ricart and Agrawala’s Algorithm • To request CS: • send req message M to all processes; • enQ M in its own queue • Upon receiving M from Pi: • If it doesn’t have/want CS send ack • If it has CS, enQ request Pi:M • If it wants CS, either enQ or ack • To release CS: • send ack message to all procs in the Q • remove them (procs) from Q • To acquire CS: enter CS when got ack from every other proc Synchronization (2)

  12. Ricart and Agrawala’s Algorithm (cont’d) • The main idea is that lowest timestamp wins • Also, the acks AND permission messages are combined into acks, which are only sent out after a proc used the CS (if it has smaller timestamp) • Example: • Node A req CS with ts=8, Node C with ts=12. • B acks both A&C • C acks A (smaller ts). • A uses CS, then sends ack to C. 8 A A A 8 ack ack ack 8 12 B C B C B C ack 12 12 Phase I Phase II Phase III Synchronization (2)

  13. Maekawa’s Algorithm • Maekawa presents an algorithm where a subset of nodes can give permission to a node to enter the CS • It is sufficient for a majority of the nodes to give permission • In Maekawa’s algorithm, |G| = sqrt(n)+1, G is the subset. • There are sqrt(n) subsets. By design, there is always a node in the intersection of 2 subsets. • To request CS: send request message M to all processes in G(i) • Upon receiving a request M from Pi: if it hasn’t sent a reply since last release, send a reply. Otherwise, queue it • To release CS: send release to all procs in G(i) • Upon receiving a release from Pi: send a reply to head of Q and remove it from Q; if Q is empty, update state (no reply sent) • To acquire CS: enter CS when got ack from all other proc in G(i) Synchronization (2)

  14. c d b e a f g Maekawa’s Algorithm (cont’d) • For example, G(a) = {b, d, e}; G(c) = {a, b, f}; G(g) = {c, d, f} • Say sites a, c, g make requests simultaneously • If site b responds positively to a, what happens? • Site b queues the response to site c until it gets a release from a,but it could send positive responses to site a • Meanwhile site f responds positively to site g, but then must queue the request for site c • Eventually, site a will send a release toits subset of nodes, and site b will thenrespond positively to c Synchronization (2)

  15. Maekawa’s Algorithm (Problem) • The biggest problem in Maekawa’s algorithm is that it may lead to deadlocks (unless it uses extra messages). HOW? Non-graded mini homework: Show a sequence of events that may lead to deadlocks; a simple answer with an explanation of how Maekawa’s algorithm avoids deadlocks. • Note that there is no ordering in the messages that are sent to the subsets of authorizing nodes. Also, there are communication delays that may cause the deadlocks. • Solution: One of the nodes initiates a deadlock resolution phase. • New types of messages are needed: • FAILED: message sent to a site (after a REPLY) when a higher-priority request was received. • INQUIRE: message sent to a site to check whether the site was able to acquire all locks • YIELD: a message sent in reply to INQUIRE message, releasing the locks (in case it didn’t get all locks) • GRANT: a message sent to a site, granting that site a lock Synchronization (2)

  16. Maekawa’s Algorithm (Modifications) • Upon receiving a request M form Pi; if it hasn’t sent a reply since last release, send a reply. Or, if new req. has a larger timestamp, send a FAILED message; or, if new req has a smaller timestamp, send an INQUIRE message to the site of the previous REPLY. • Upon receiving an INQUIRE message, a site ignores it if it already got all grants from its subset. If the site received a FAILED message from any site, it sends a YIELD message. IF a site sent a YIELD message, but got no GRANT message from another site in the request set, it sends a YIELD message. • Upon receiving a YIELD from a site, a member of a request site assumes that the site has released the locks and processes the request normally. • Number of messages required for the algorithm to succeed? • Non-graded mini homework again: show how many messages are needed for Maekawa’s algorithm. Extend the table below. Synchronization (2)

  17. Token-Based Distributed ME • In the token based approaches to distributed ME, the general correctness of the algorithm is easier to prove, since the site will only go into the CS if it holds a token. • On the other hand, there are more problems to prove freedom of starvation (since a site may retain a token forever). • Another problem is when a site fails: there has to be a regeneration of the tokens, which is similar to leader election. • One representative algorithm for token-based tree-based ME is Raymond’s algorithm. Synchronization (2)

  18. A Token Ring Algorithm • An unordered group of processes on a network. • A logical ring constructed in software. Synchronization (2)

  19. Comparison • A comparison of three mutual exclusion algorithms. Synchronization (2)

  20. Rings and Other Approaches • Rings: physical or logical • any physical interconnection (e.g., BUS, point-to-point nets, etc.) • Usually uses a token: the proc that has the token enters the CS • It’s fair, since CS is round-robin • It’s correct, since there is a single token • Problems: lost-token, duplicated token. • We need to be able to detect and regenerate/delete token • If a process crashes/fails, what to do? Acks? • Other Approaches: • Maekawa’s algorithm is a more intricate form of earlier majority algorithms (remember the usefulness of elections?). Synchronization (2)

More Related