CSE 486/586 Distributed Systems

Similar documents
Recap: Consensus. CSE 486/586 Distributed Systems Mutual Exclusion. Why Mutual Exclusion? Why Mutual Exclusion? Mutexes. Mutual Exclusion C 1

Distributed Systems. coordination Johan Montelius ID2201. Distributed Systems ID2201

Coordination and Agreement

CS455: Introduction to Distributed Systems [Spring 2018] Dept. Of Computer Science, Colorado State University

CS 455: INTRODUCTION TO DISTRIBUTED SYSTEMS [DISTRIBUTED MUTUAL EXCLUSION] Frequently asked questions from the previous class survey

Coordination 1. To do. Mutual exclusion Election algorithms Next time: Global state. q q q

CS455: Introduction to Distributed Systems [Spring 2018] Dept. Of Computer Science, Colorado State University

Frequently asked questions from the previous class survey

Mutual Exclusion. A Centralized Algorithm

Distributed Systems (5DV147)

CSE 486/586: Distributed Systems

CSE 486/586 Distributed Systems

CSE 486/586 Distributed Systems

Distributed Mutual Exclusion

Distributed Systems 8L for Part IB

Process Synchroniztion Mutual Exclusion & Election Algorithms

PROCESS SYNCHRONIZATION

Clock Synchronization. Synchronization. Clock Synchronization Algorithms. Physical Clock Synchronization. Tanenbaum Chapter 6 plus additional papers

CSE 486/586 Distributed Systems

Several of these problems are motivated by trying to use solutiions used in `centralized computing to distributed computing

Homework #2 Nathan Balon CIS 578 October 31, 2004

Last Class: Clock Synchronization. Today: More Canonical Problems

Distributed Systems Coordination and Agreement

Time and Coordination in Distributed Systems. Operating Systems

Verteilte Systeme/Distributed Systems Ch. 5: Various distributed algorithms

CSE 5306 Distributed Systems. Synchronization

Distributed Synchronization. EECS 591 Farnam Jahanian University of Michigan

DISTRIBUTED MUTEX. EE324 Lecture 11

Synchronization Part 2. REK s adaptation of Claypool s adaptation oftanenbaum s Distributed Systems Chapter 5 and Silberschatz Chapter 17

June 22/24/ Gerd Liefländer System Architecture Group Universität Karlsruhe (TH), System Architecture Group

Distributed Operating Systems. Distributed Synchronization

Last Dme. Distributed systems Lecture 5: Consistent cuts, process groups, and mutual exclusion. Dr Robert N. M. Watson

Distributed Mutual Exclusion Algorithms

Distributed Systems Exam 1 Review. Paul Krzyzanowski. Rutgers University. Fall 2016

Exam 2 Review. Fall 2011

Recap. CSE 486/586 Distributed Systems Paxos. Paxos. Brief History. Brief History. Brief History C 1

CSE 486/586 Distributed Systems Reliable Multicast --- 1

CSE Traditional Operating Systems deal with typical system software designed to be:


Chapter 6: Process Synchronization

C 1. Recap. CSE 486/586 Distributed Systems Failure Detectors. Today s Question. Two Different System Models. Why, What, and How.

CSE 486/586 Distributed Systems

Verteilte Systeme (Distributed Systems)

Chapter 16: Distributed Synchronization

CSE 5306 Distributed Systems

Chapter 18: Distributed

Distributed Mutual Exclusion

Slides for Chapter 15: Coordination and Agreement

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

VALLIAMMAI ENGINEERING COLLEGE

Slides for Chapter 12: Coordination and Agreement

Coordination and Agreement

Advanced Topics in Distributed Systems. Dr. Ayman A. Abdel-Hamid. Computer Science Department Virginia Tech

Concurrent Processes Rab Nawaz Jadoon

Concurrency: Mutual Exclusion and

Design and Implementation of Distributed Algorithms for Their Application in Telematic Services. Use case: Shared Calendar

OUTLINE. Introduction Clock synchronization Logical clocks Global state Mutual exclusion Election algorithms Deadlocks in distributed systems

Coordination and Agreement

CSE 486/586 Distributed Systems

! What is a deadlock? ! What causes a deadlock? ! How do you deal with (potential) deadlocks? Maria Hybinette, UGA

Distributed Systems Question Bank UNIT 1 Chapter 1 1. Define distributed systems. What are the significant issues of the distributed systems?

Recap. CSE 486/586 Distributed Systems Google Chubby Lock Service. Recap: First Requirement. Recap: Second Requirement. Recap: Strengthening P2

Chapter 6 Synchronization

X X C 1. Recap. CSE 486/586 Distributed Systems Gossiping. Eager vs. Lazy Replication. Recall: Passive Replication. Fault-Tolerance and Scalability

Distributed Systems - II

Exam 2 Review. October 29, Paul Krzyzanowski 1

High-level Synchronization

Concurrency: Mutual Exclusion and Synchronization

What's wrong with Semaphores?

11/7/2018. Event Ordering. Module 18: Distributed Coordination. Distributed Mutual Exclusion (DME) Implementation of. DME: Centralized Approach

Distributed Transaction Management 2003

A Two-Layer Hybrid Algorithm for Achieving Mutual Exclusion in Distributed Systems

A DAG-BASED ALGORITHM FOR DISTRIBUTED MUTUAL EXCLUSION ATHESIS MASTER OF SCIENCE

CMPSCI 677 Operating Systems Spring Lecture 14: March 9

CS 153 Design of Operating Systems Winter 2016

CSE 153 Design of Operating Systems

UNIT:2. Process Management

Distributed systems. Lecture 6: distributed transactions, elections, consensus and replication. Malte Schwarzkopf

CS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019

Failures, Elections, and Raft

Concept of a process

Algorithms and protocols for distributed systems

Synchronization Principles I

C 1. Today s Question. CSE 486/586 Distributed Systems Failure Detectors. Two Different System Models. Failure Model. Why, What, and How

Distributed Systems. Lec 9: Distributed File Systems NFS, AFS. Slide acks: Dave Andersen

PART B UNIT II COMMUNICATION IN DISTRIBUTED SYSTEM PART A

CS 425 / ECE 428 Distributed Systems Fall 2017

Lecture 7: Logical Time

Synchronization I. Jo, Heeseung

416 practice questions (PQs)

Distributed Deadlocks. Prof. Ananthanarayana V.S. Dept. of Information Technology N.I.T.K., Surathkal

Synchronization. Clock Synchronization

CS455: Introduction to Distributed Systems [Spring 2018] Dept. Of Computer Science, Colorado State University

!! What is a deadlock? !! What causes a deadlock? !! How do you deal with (potential) deadlocks? Maria Hybinette, UGA

Deadlock. Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1

Self Stabilization. CS553 Distributed Algorithms Prof. Ajay Kshemkalyani. by Islam Ismailov & Mohamed M. Ali

Event Ordering Silberschatz, Galvin and Gagne. Operating System Concepts

Concurrency: Deadlock and Starvation. Chapter 6

Synchronization. Chapter 5

Midterm Exam. October 20th, Thursday NSC

Transcription:

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

Recap: Consensus On a synchronous 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 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 execution of the code that modifies the account entry)

Mutual Exclusion Critical section problem Piece of code (at all clients) for which we need to ensure at most one client is executing it at any point of time. Solutions: Semaphores, mutexes, etc. in single-node OS Message-passing-based protocols in distributed systems:» enter() the critical section» AccessResource() in the critical section» exit() the critical section Distributed mutual exclusion requirements: Safety At most one process 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 Synchronize access to common data structures between multiple threads Allows two operations: lock() forever: // each loop iteration is atomic unlock() if lock not in use: label lock in use break label lock not in use // atomic

Semaphores Synchronize access to common data structures between multiple threads Initialize with S = 1, allows two operations: wait(s) (or P(S)): forever: // each loop iteration is atomic if S > 0: S-- break signal(s) (or V(S)): S++ // atomic

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

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 (when no other process is in, or waiting) (We will prefer mostly the entry operation.) 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) Throughput: the rate at which the processes can access the critical section, i.e., x processes per second (these definitions are more correct than those in the textbook)

Assumptions/System Model We make the following assumptions: Each pair of processes is connected by reliable channels. Messages are eventually delivered to recipient s input buffer in FIFO order. Processes do not fail. (why?) Four algorithms Centralized control Token ring Ricart and Agrawala Maekawa

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) Enter: Send a request to the coordinator & wait for token. Exit: Send a message to the coordinator to release the token. Upon receipt of a request, if no other process has the token, the coordinator grants the token; otherwise, it queues the request. Upon receipt of a release message, the coordinator removes the oldest entry in the queue (if any) and grants the token.

1. Centralized Control Safety, liveness, ordering? Bandwidth? Requires 3 messages per entry + exit operation. 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 Processes are organized in a logical ring: p i 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, forward the token on. If a process does not want to enter the CS when it receives the token, it forwards the token its neighbor.

2. Token Ring Approach Features: Safety & liveness, ordering? 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 PN-1 P1 current holder of token P3 P2 next holder of token

3. Ricart & Agrawala s Algorithm Processes multicast a request to enter a CS Once all processes reply positively, the requester can enter Use a Lamport clock and process id for ordering Messages requesting entry are of the form <T,p i > T is the sender s Lamport clock timestamp p i is 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 reply change state to held and enter the CS On receipt of a request <T i, p i > at p j : if (state = held) or (state = wanted & (T j, p j )<(T i,p i )), 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 <T i, p i > at p j (i j) if (state = HELD or (state = WANTED and (T, p j ) < (T i, p i ))) then queue request from p i without replying else reply immediately to p i ; end if To exit the critical section state := RELEASED; reply to any queued requests;

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

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

4. Maekawa s Algorithm P0 P1 P2 P3 P4 P5 P6 P7 P8

4. Maekawa s Algorithm Observation: no need to have all peers reply A subset of peers is sufficient 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, p i and p j, their corresponding voting sets have at least one common process. Each process p i is associated with a voting set v i (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, p i requests permission from all other processes in its own voting set v i 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 p i as its voting set.

Maekawa s Algorithm Part 1 On initialization state := RELEASED; voted := FALSE; For p i to enter the critical section state := WANTED; Multicast request to all processes in V i ; Wait until (number of replies received = K); state := HELD; On receipt of a request from p i at p j if (state = HELD or voted = TRUE) then queue request from p i without replying; else send reply to p i ; voted := TRUE; end if

Maekawa s Algorithm Part 2 For p i to exit the critical section state := RELEASED; Multicast release to all processes in V i ; On receipt of a release from p i at p j if (queue of requests is non-empty) then remove head of queue from p k, say; send reply to p k ; 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 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

References Textbook section 15.2. Required Reading.

Acknowledgements These slides by Steve Ko, lightly modified and used with permission by Ethan Blanton These slides contain material developed and copyrighted by Indranil Gupta (UIUC).