CSE 486/586 Distributed Systems 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
CS425 /CSE424/ECE428 – Distributed Systems – Fall 2011 Material derived from slides by I. Gupta, M. Harandi, J. Hou, S. Mitra, K. Nahrstedt, N. Vaidya.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Consensus Steve Ko Computer Sciences and Engineering University at Buffalo.
Page 1 Mutual Exclusion* Distributed Systems *referred to slides by Prof. Paul Krzyzanowski at Rutgers University and Prof. Mary Ellen Weisskopf at University.
CS 582 / CMPE 481 Distributed Systems
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Distributed Snapshots –Termination detection Election algorithms –Bully –Ring.
Distributed Systems Fall 2009 Coordination and agreement, Multicast, and Message ordering.
CS 425 / ECE 428 Distributed Systems Fall 2014 Indranil Gupta (Indy) Lecture 12: Mutual Exclusion All slides © IG.
Distributed Mutual Exclusion Béat Hirsbrunner References G. Coulouris, J. Dollimore and T. Kindberg "Distributed Systems: Concepts and Design", Ed. 4,
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms.
Distributed Mutual Exclusion
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Mutual Exclusion Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Mutual Exclusion Steve Ko Computer Sciences and Engineering University at Buffalo.
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.
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.
CS 425/ECE 428/CSE424 Distributed Systems (Fall 2009) Lecture 8 Leader Election Section 12.3 Klara Nahrstedt.
Presenter: Long Ma Advisor: Dr. Zhang 4.5 DISTRIBUTED MUTUAL EXCLUSION.
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.
Computer Science 425 Distributed Systems (Fall 2009) Lecture 6 Multicast/Group Communication and Mutual Exclusion Section &12.2.
CS 425 / ECE 428 Distributed Systems Fall 2015 Indranil Gupta (Indy) Oct 1, 2015 Lecture 12: Mutual Exclusion All slides © IG.
Lecture 10: Coordination and Agreement (Chap 12) Haibin Zhu, PhD. Assistant Professor Department of Computer Science Nipissing University © 2002.
Election Distributed Systems. Algorithms to Find Global States Why? To check a particular property exist or not in distributed system –(Distributed) garbage.
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.
From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley 2012 Slides for Chapter 15: Coordination.
Decentralized solution 1
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are:  Resource sharing  Avoiding concurrent update on shared data  Controlling the.
CSE 486/586 CSE 486/586 Distributed Systems Leader Election Steve Ko Computer Sciences and Engineering University at Buffalo.
CSC 8420 Advanced Operating Systems Georgia State University Yi Pan Transactions are communications with ACID property: Atomicity: all or nothing Consistency:
Process Synchronization Presentation 2 Group A4: Sean Hudson, Syeda Taib, Manasi Kapadia.
Revisiting Logical Clocks: Mutual Exclusion Problem statement: Given a set of n processes, and a shared resource, it is required that: –Mutual exclusion.
CS 425 / ECE 428 Distributed Systems Fall 2015 Indranil Gupta (Indy) Oct 1, 2015 Lecture 12: Mutual Exclusion All slides © IG.
Lecture 18: Mutual Exclusion
Exercises for Chapter 11: COORDINATION AND AGREEMENT
CSE 486/586 Distributed Systems Reliable Multicast --- 1
Coordination and Agreement
CSE 486/586 Distributed Systems Leader Election
Mutual Exclusion Continued
Distributed Mutual Exclusion
CSE 486/586 Distributed Systems Global States
CSE 486/586 Distributed Systems Time and Synchronization
Distributed Mutex EE324 Lecture 11.
Coordination and Agreement
Distributed Mutual Exclusion
Decentralized solution 1
Mutual Exclusion Problem Specifications
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
Outline Distributed Mutual Exclusion Introduction Performance measures
Mutual Exclusion CS p0 CS p1 p2 CS CS p3.
CSE 486/586 Distributed Systems Leader Election
CSE 486/586 Distributed Systems Mutual Exclusion
Physical clock synchronization
Synchronization (2) – Mutual Exclusion
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
Distributed Systems and Concurrency: Synchronization in Distributed Systems Majeed Kassis.
Distributed Mutual eXclusion
CSE 486/586 Distributed Systems Reliable Multicast --- 2
CSE 486/586 Distributed Systems Time and Synchronization
CSE 486/586 Distributed Systems Reliable Multicast --- 1
CSE 486/586 Distributed Systems Leader Election
Presentation transcript:

CSE 486/586 Distributed Systems Mutual Exclusion Steve Ko Computer Sciences and Engineering University at Buffalo

Recap: Consensus On a synchronous system On an asynchronous system There’s an algorithm that works. On an asynchronous system It’s been shown (FLP) that it’s impossible to guarantee. Getting around the result Masking faults Using failure detectors Still not perfect Impossibility Result Lemma 1: schedules are commutative Lemma 2: some initial configuration is bivalent Lemma 3: from a bivalent configuration, there is always another bivalent configuration that is reachable.

Why Mutual Exclusion? Bank’s Servers in the Cloud: Think of two simultaneous deposits of $10,000 into your bank account, each from one ATM connected to a different server. Both ATMs read initial amount of $1000 concurrently from the bank’s cloud server Both ATMs add $10,000 to this amount (locally at the ATM) Both write the final amount to the server What’s wrong?

Why Mutual Exclusion? Bank’s Servers in the Cloud: Think of two simultaneous deposits of $10,000 into your bank account, each from one ATM connected to a different server. Both ATMs read initial amount of $1000 concurrently from the bank’s cloud server Both ATMs add $10,000 to this amount (locally at the ATM) Both write the final amount to the server What’s wrong? The ATMs need mutually exclusive access to your account entry at the server (or, to executing the code that modifies the account entry)

Mutual Exclusion Critical section problem Solutions: Piece of code (at all clients) for which we need to ensure there is at most one client executing it at any point of time. Solutions: Semaphores, mutexes, etc. in single-node OS We’ll see the solutions for distributed systems. Mutual exclusion requirements: Safety – At most one process/thread may execute in CS at any time Liveness – Every request for a CS is eventually granted Ordering (desirable) – Requests are granted in the order they were made

Mutexes To synchronize access of multiple threads to common data structures Allows two operations: lock() while true: // each iteration atomic if lock not in use: label lock in use break unlock() label lock not in use

Semaphores To synchronize access of multiple threads to common data structures Semaphore S=1; Allows two operations wait(S) (or P(S)): while(1){ // each execution of the while loop is atomic if (S > 0) S--; break; } signal(S) (or V(S)): S++; Each while loop execution and S++ are each atomic operations

How Are Mutexes Used? mutex L= UNLOCKED; ATM1: lock(L); // enter // critical section obtain bank amount; add in deposit; update bank amount; unlock(L); // exit extern mutex L; ATM2 lock(L); // enter // critical section obtain bank amount; add in deposit; update bank amount; unlock(L); // exit

Assumptions/System Model For all the algorithms studied, we make the following assumptions: Each pair of processes is connected by reliable channels (such as TCP). Messages are eventually delivered to recipients’ input buffer in FIFO order. Processes do not fail Four algorithms Centralized control Token ring Ricart and Agrawala Maekawa

Distributed Mutual Exclusion Performance Criteria Bandwidth: the total number of messages sent in each entry and exit operation. Client delay: the delay incurred by a process at each entry and exit operation (when no other process is in, or waiting) (We will look at mostly the entry operation as exit costs are typically lower.) Synchronization delay: the time interval between one process exiting the critical section and the next process entering it (when there is only one process waiting) These translate into throughput — the rate at which the processes can access the critical section, i.e., x processes per second. This is in addition to safety, liveness, and ordering.

1. Centralized Control A central coordinator (master or leader) Is elected (next lecture) Grants permission to enter CS & keeps a queue of requests to enter the CS. Ensures only one process at a time can access the CS Has a special token per CS Operations (token gives access to CS) To enter a CS Send a request to the coord & wait for token. On exiting the CS Send a message to the coord to release the token. Upon receipt of a request, if no other process has the token, the coord replies with the token; otherwise, the coord queues the request. Upon receipt of a release message, the coord removes the oldest entry in the queue (if any) and replies with a token.

1. Centralized Control Safety, liveness, ordering? Bandwidth? Requires 3 messages per (entry + exit) operations combined. Client delay: one round trip time (request + grant) Synchronization delay one round trip time (release + grant) The coordinator becomes performance bottleneck and single point of failure.

2. Token Ring Approach Features: Processes are organized in a logical ring: pi has a communication channel to p(i+1)mod (n). Operations: Only the process holding the token can enter the CS. To enter the critical section, wait passively for the token. When in CS, hold on to the token. To exit the CS, the process sends the token onto its neighbor. If a process does not want to enter the CS when it receives the token, it forwards the token to the next neighbor. Features: Safety & liveness, ordering? Bandwidth, client delay, sync. delay? Bandwidth: 1 message per exit Client delay: 0 to N message transmissions. Synchronization delay between one process’s exit from the CS and the next process’s entry is between 1 and N-1 message transmissions. P0 Previous holder of token current holder of token PN-1 P1 P2 next holder of token P3

CSE 486/586 Administrivia PA3 due on Friday (4/12) Please do not use someone else’s code! Midterm results will be posted this week.

3. Ricart & Agrawala’s Algorithm Processes requiring entry to critical section multicast a request, and can enter it only when all other processes have replied positively. Use the Lamport clock and process id for ordering Messages requesting entry are of the form <T,pi>, where T is the sender’s timestamp (Lamport clock) and pi the sender’s identity (used to break ties in T).

3. Ricart & Agrawala’s Algorithm To enter the CS set state to wanted multicast “request” to all processes (including timestamp) wait until all processes send back “reply” change state to held and enter the CS On receipt of a request <Ti, pi> at pj: if (state = held) or (state = wanted & (Tj, pj)<(Ti,pi)), enqueue request else “reply” to pi On exiting the CS change state to release and “reply” to all queued requests.

3. Ricart & Agrawala’s Algorithm On initialization state := RELEASED; To enter the section state := WANTED; Multicast request to all processes; T := request’s timestamp; Wait until (number of replies received = (N – 1)); state := HELD; On receipt of a request <Ti, pi> at pj (i ≠ j) if (state = HELD or (state = WANTED and (T, pj) < (Ti, pi))) then queue request from pi without replying; else reply immediately to pi; end if To exit the critical section reply to any queued requests;

3. Ricart & Agrawala’s Algorithm 41 p 41 3 p Reply 1 Reply 34 Reply 34 41 34 p 2

Analysis: Ricart & Agrawala Safety, liveness, and ordering? Bandwidth: 2(N-1) messages per entry operation: N-1 unicasts for the multicast request + N-1 replies N-1 unicast messages per exit operation Client delay One round-trip time Synchronization delay One message transmission time

4. Maekawa’s Algorithm Simple example P0 P3 P1 P2 Can P0 just get permission from P1 and P3 and not ask P2? The only thing necessary is to know if P2 is in the CS.

4. Maekawa’s Algorithm A more complex example P0 P1 P2 P3 P4 P5 P6 P7 A process’s voting set is all other process in its row and column. P6 P7 P8

4. Maekawa’s Algorithm Observation: no need to have all peers reply Only need to have a subset of peers as long as all subsets overlap. Voting set: a subset of processes that grant permission to enter a CS Voting sets are chosen so that for any two processes, pi and pj, their corresponding voting sets have at least one common process. Each process pi is associated with a voting set vi (of processes) Each process belongs to its own voting set The intersection of any two voting sets is non-empty Each voting set is of size K Each process belongs to M other voting sets

4. Maekawa’s Algorithm Multicasts messages to a (voting) subset of processes To access a critical section, pi requests permission from all other processes in its own voting set vi Voting set member gives permission to only one requestor at a time, and queues all other requests Guarantees safety Maekawa showed that K=M=N works best One way of doing this is to put N processes in a N by N matrix and take union of row & column containing pi as its voting set.

Maekawa’s Algorithm – Part 1 On initialization state := RELEASED; voted := FALSE; For pi to enter the critical section state := WANTED; Multicast request to all processes in Vi; Wait until (number of replies received = K); state := HELD; On receipt of a request from pi at pj if (state = HELD or voted = TRUE) then queue request from pi without replying; else send reply to pi; voted := TRUE; end if Continues on next slide

Maekawa’s Algorithm – Part 2 For pi to exit the critical section state := RELEASED; Multicast release to all processes in Vi; On receipt of a release from pi at pj if (queue of requests is non-empty) then remove head of queue – from pk, say; send reply to pk; voted := TRUE; else voted := FALSE; end if

Maekawa’s Algorithm – Analysis Bandwidth: 2N messages per entry, N messages per exit Better than Ricart and Agrawala’s (2(N-1) and N-1 messages) Client delay: One round trip time Same as Ricart and Agrawala Synchronization delay: One round-trip time (two hops) Worse than Ricart and Agrawala May not guarantee liveness (may deadlock) How? P0 P1 P2

Summary Mutual exclusion Coordinator-based token Token ring Ricart and Agrawala’s timestamp algorithm Maekawa’s algorithm 27

Acknowledgements These slides contain material developed and copyrighted by Indranil Gupta (UIUC).