Synchronization (2) – Mutual Exclusion

Slides:



Advertisements
Similar presentations
Dr. Kalpakis CMSC 621, Advanced Operating Systems. Distributed Mutual Exclusion.
Advertisements

CS542 Topics in Distributed Systems Diganta Goswami.
Ricart and Agrawala’s Algorithm
Token-Dased DMX Algorithms n LeLann’s token ring n Suzuki-Kasami’s broadcast n Raymond’s tree.
Synchronization Chapter clock synchronization * 5.2 logical clocks * 5.3 global state * 5.4 election algorithm * 5.5 mutual exclusion * 5.6 distributed.
1 Algorithms and protocols for distributed systems We have defined process groups as having peer or hierarchical structure and have seen that a coordinator.
Page 1 Mutual Exclusion* Distributed Systems *referred to slides by Prof. Paul Krzyzanowski at Rutgers University and Prof. Mary Ellen Weisskopf at University.
Distributed Systems Spring 2009
CS 582 / CMPE 481 Distributed Systems
What we will cover…  Distributed Coordination 1-1.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Distributed Snapshots –Termination detection Election algorithms –Bully –Ring.
1. Explain why synchronization is so important in distributed systems by giving an appropriate example When each machine has its own clock, an event that.
Synchronization Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion.
Synchronization in Distributed Systems. Mutual Exclusion To read or update shared data, a process should enter a critical region to ensure mutual exclusion.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms.
Dr. Kalpakis CMSC 621, Advanced Operating Systems. Fall 2003 URL: Distributed Mutual Exclusion.
Distributed Mutex EE324 Lecture 11.
Distributed Mutual Exclusion
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved Chapter 6 Synchronization.
4.5 DISTRIBUTED MUTUAL EXCLUSION MOSES RENTAPALLI.
MUTUAL EXCLUSION AND QUORUMS CS Distributed Mutual Exclusion Given a set of processes and a single resource, develop a protocol to ensure exclusive.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms –Bully algorithm.
Chapter 2/6 –Critical Section Problem / Mutual exclusion progress, bounded wait –Hardware Solution disable interrupts –problems ? –Software Solution busy.
CS425 /CSE424/ECE428 – Distributed Systems – Fall 2011 Material derived from slides by I. Gupta, M. Harandi, J. Hou, S. Mitra, K. Nahrstedt, N. Vaidya.
Coordination and Agreement. Topics Distributed Mutual Exclusion Leader Election.
Global State (1) a)A consistent cut b)An inconsistent cut.
Synchronization CSCI 4780/6780. Mutual Exclusion Concurrency and collaboration are fundamental to distributed systems Simultaneous access to resources.
Presenter: Long Ma Advisor: Dr. Zhang 4.5 DISTRIBUTED MUTUAL EXCLUSION.
Studying Different Problems from Distributed Computing Several of these problems are motivated by trying to use solutiions used in `centralized computing’
Lecture 10 – Mutual Exclusion Distributed Systems.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Mutual Exclusion & Leader Election Steve Ko Computer Sciences and Engineering University.
ITEC452 Distributed Computing Lecture 6 Mutual Exclusion Hwajung Lee.
Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are:  Resource sharing  Avoiding concurrent update on shared data  Controlling the.
Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are: 1. Resource sharing 2. Avoiding concurrent update on shared data 3. Controlling the.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Page 1 Mutual Exclusion & Election Algorithms Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content.
Lecture 12-1 Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428 Fall 2012 Indranil Gupta (Indy) October 4, 2012 Lecture 12 Mutual Exclusion.
Lecture 7- 1 CS 425/ECE 428/CSE424 Distributed Systems (Fall 2009) Lecture 7 Distributed Mutual Exclusion Section 12.2 Klara Nahrstedt.
Decentralized solution 1
COMP 655: Distributed/Operating Systems Summer 2011 Dr. Chunbo Chu Week 6: Synchronyzation 3/5/20161 Distributed Systems - COMP 655.
Distributed Mutual Exclusion Synchronization in Distributed Systems Synchronization in distributed systems are often more difficult compared to synchronization.
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
CS3771 Today: Distributed Coordination  Previous class: Distributed File Systems Issues: Naming Strategies: Absolute Names, Mount Points (logical connection.
CSC 8420 Advanced Operating Systems Georgia State University Yi Pan Transactions are communications with ACID property: Atomicity: all or nothing Consistency:
Revisiting Logical Clocks: Mutual Exclusion Problem statement: Given a set of n processes, and a shared resource, it is required that: –Mutual exclusion.
Lecture 11: Coordination and Agreement Central server for mutual exclusion Election – getting a number of processes to agree which is “in charge” CDK4:
CS 425 / ECE 428 Distributed Systems Fall 2015 Indranil Gupta (Indy) Oct 1, 2015 Lecture 12: Mutual Exclusion All slides © IG.
Coordination and Agreement
4.5 Distributed Mutual Exclusion
Chapter 11 Coordination Election Algorithms
Mutual Exclusion Continued
Distributed Mutual Exclusion
Distributed Mutex EE324 Lecture 11.
Distributed Mutual Exclusion
Decentralized solution 1
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Mutual Exclusion Problem Specifications
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
Outline Distributed Mutual Exclusion Introduction Performance measures
Chapter 5 Continued Termination Detection Election algorithms
Mutual Exclusion CS p0 CS p1 p2 CS CS p3.
CSE 486/586 Distributed Systems Mutual Exclusion
Lecture 10: Coordination and Agreement
Physical clock synchronization
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
Prof. Leonardo Mostarda University of Camerino
Lecture 11: Coordination and Agreement
Distributed Systems and Concurrency: Synchronization in Distributed Systems Majeed Kassis.
Distributed Mutual eXclusion
CSE 486/586 Distributed Systems Mutual Exclusion
Presentation transcript:

Synchronization (2) – Mutual Exclusion Chapter 5 (section 5.5 + extra reading) Synchronization (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) CS 2510, cs.pitt.edu Synchronization (2)

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 CS 2510, cs.pitt.edu Synchronization (2)

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) CS 2510, cs.pitt.edu Synchronization (2)

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 CS 2510, cs.pitt.edu Synchronization (2)

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 CS 2510, cs.pitt.edu Synchronization (2)

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 Master Site 1 Site 3 Site 2 List of requests Site 1 has critical section; will yield to the master; master will grant to site x Bottleneck network congestion timeout CS 2510, cs.pitt.edu Synchronization (2)

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. Time P1 P2 P3 Request for CS CS 2510, cs.pitt.edu Synchronization (2)

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. CS 2510, cs.pitt.edu Synchronization (2)

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 CS 2510, cs.pitt.edu Synchronization (2)

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 CS 2510, cs.pitt.edu Synchronization (2)

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 CS 2510, cs.pitt.edu Synchronization (2)

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) CS 2510, cs.pitt.edu Synchronization (2)

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 to its subset of nodes, and site b will then respond positively to c c e f g a b d CS 2510, cs.pitt.edu Synchronization (2)

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 CS 2510, cs.pitt.edu Synchronization (2)

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. CS 2510, cs.pitt.edu Synchronization (2)

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. CS 2510, cs.pitt.edu Synchronization (2)

A Token Ring Algorithm An unordered group of processes on a network. A logical ring constructed in software. CS 2510, cs.pitt.edu Synchronization (2)

Comparison A comparison of three mutual exclusion algorithms. Messages per entry/exit Delay before entry (in message times) Problems Centralized 3 2 Coordinator crash Distributed 2 ( n – 1 ) Crash of any process (n points of failure) Token ring 1 to ????? ( / n-1) 0 to n – 1 Lost token, process crash A comparison of three mutual exclusion algorithms. CS 2510, cs.pitt.edu Synchronization (2)

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?). CS 2510, cs.pitt.edu Synchronization (2)