Lecture 10 – Mutual Exclusion 15-440 Distributed Systems.

Slides:



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

CS542 Topics in Distributed Systems Diganta Goswami.
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.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED.
Synchronization in Distributed Systems
Distributed Systems Spring 2009
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.
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.
CS603 Process Synchronization February 11, Synchronization: Basics Problem: Shared Resources –Generally data –But could be others Approaches: –Model.
20101 Synchronization in distributed systems A collection of independent computers that appears to its users as a single coherent system.
SynchronizationCS-4513, D-Term Synchronization in Distributed Systems CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts,
Chapter 18: Distributed Coordination (Chapter 18.1 – 18.5)
Synchronization in Distributed Systems CS-4513 D-term Synchronization in Distributed Systems CS-4513 Distributed Computing Systems (Slides include.
Coordination in Distributed Systems Lecture # 8. Coordination Anecdotes  Decentralized, no coordination  Aloha ~ 18%  Some coordinating Master  Slotted.
EEC-681/781 Distributed Computing Systems Lecture 11 Wenbing Zhao Cleveland State University.
EEC-681/781 Distributed Computing Systems Lecture 11 Wenbing Zhao Cleveland State University.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
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.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
CIS 720 Distributed algorithms. “Paint on the forehead” problem Each of you can see other’s forehead but not your own. I announce “some of you have paint.
Distributed Mutex EE324 Lecture 11.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Mutual Exclusion Steve Ko Computer Sciences and Engineering University at Buffalo.
4.5 DISTRIBUTED MUTUAL EXCLUSION MOSES RENTAPALLI.
4.5 Distributed Mutual Exclusion Ranjitha Shivarudraiah.
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.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 15/01/2008.
Presenter: Long Ma Advisor: Dr. Zhang 4.5 DISTRIBUTED MUTUAL EXCLUSION.
Lamport’s Logical Clocks & Totally Ordered Multicasting.
Vector Clock Each process maintains an array of clocks –vc.j.k denotes the knowledge that j has about the clock of k –vc.j.j, thus, denotes the clock of.
Synchronization Chapter 5.
Real-Time & MultiMedia Lab Synchronization Distributed System Jin-Seung,KIM.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Mutual Exclusion & Leader Election Steve Ko Computer Sciences and Engineering University.
D u k e S y s t e m s Asynchronous Replicated State Machines (Causal Multicast and All That) Jeff Chase Duke University.
Physical clock synchronization Question 1. Why is physical clock synchronization important? Question 2. With the price of atomic clocks or GPS coming down,
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
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.
Logical Clocks. Topics r Logical clocks r Totally-Ordered Multicasting.
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.
COMP 655: Distributed/Operating Systems Summer 2011 Dr. Chunbo Chu Week 6: Synchronyzation 3/5/20161 Distributed Systems - COMP 655.
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
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.
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
Distributed Mutex EE324 Lecture 11.
Distributed Mutual Exclusion
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Outline Distributed Mutual Exclusion Introduction Performance measures
Mutual Exclusion CS p0 CS p1 p2 CS CS p3.
CSE 486/586 Distributed Systems Mutual Exclusion
Synchronization (2) – Mutual Exclusion
Prof. Leonardo Mostarda University of Camerino
Distributed Systems and Concurrency: Synchronization in Distributed Systems Majeed Kassis.
CSE 486/586 Distributed Systems Mutual Exclusion
Presentation transcript:

Lecture 10 – Mutual Exclusion Distributed Systems

Today's Lecture NTP correction Totally ordered multicast Centralized Mutual Exclusion Distributed Mutual Exclusion 2

NTP Protocol All modes use UDP Each message bears timestamps of recent events: Local times of Send and Receive of previous message Local times of Send of current message Recipient notes the time of receipt T 3 (we have T 0, T 1, T 2, T 3 ) 3 T3T3 T2T2 T1T1 T0T0 Server Client Time mm' Time

Accuracy of NTP Timestamps t 0 is the client's timestamp of the request packet transmission, t 1 is the server's timestamp of the request packet reception, t 2 is the server's timestamp of the response packet transmission and t 3 is the client's timestamp of the response packet reception. RTT= wait_time_client – server_proc_time = (t 3 -t 0 ) – (t 2 -t 1 ) Offset = ((t 1 -t 0 ) + (t 3 -t 2 ))/2 = ((offset + delay) + (offset – delay))/2 NTP servers filter pairs, estimating reliability from variation, allowing them to select peers Accuracy of 10s of millisecs over Internet paths (1 on LANs) 4

Accuracy of NTP Timestamps t 0 is the client's timestamp of the request packet transmission, t 1 is the server's timestamp of the request packet reception, t 2 is the server's timestamp of the response packet transmission and t 3 is the client's timestamp of the response packet reception. RTT= wait_time_client – server_proc_time = (t 3 -t 0 ) – (t 2 -t 1 ) Offset = ((t 1 -t 0 ) + (t 2 -t 3 ))/2 = ((offset + delay) + (offset – delay))/2 NTP servers filter pairs, estimating reliability from variation, allowing them to select peers Accuracy of 10s of millisecs over Internet paths (1 on LANs) 5

Today's Lecture NTP correction Totally ordered multicast Centralized Mutual Exclusion Distributed Mutual Exclusion 6

Example: Totally-Ordered Multicasting San Fran customer adds $100, NY bank adds 1% interest San Fran will have $1,111 and NY will have $1,110 Updating a replicated database and leaving it in an inconsistent state. Can use Lamport’s to totally order 7 (San Francisco)(New York) (+$100)(+1%)

8 Totally-Ordered Multicast A multicast operation by which all messages are delivered in the same order to each receiver. Lamport Details: Each message is timestamped with the current logical time of its sender. Multicast messages are also sent back to the sender. Assume all messages sent by one sender are received in the order they were sent and that no messages are lost.

Totally-Ordered Multicast Lamport Details (cont): Receiving process puts a message into a local queue ordered according to timestamp. The receiver multicasts an ACK to all other processes. Only deliver message when it is *both* at the head of queue and ack’ed by all participants Why does this work? Key point from Lamport: the timestamp of the received message is lower than the timestamp of the ACK. All processes will eventually have the same copy of the local queue  consistent global ordering. 9

Today's Lecture NTP correction Totally ordered multicast Centralized Mutual Exclusion Distributed Mutual Exclusion 10

Mutual Exclusion while true: Perform local operations Acquire(lock) Execute critical section Release(lock) Must ensure that only one instance of code is in critical section Whereas multithreaded systems can use shared memory, we assume that processes can only coordinate message passing. 11

Requirements 1.Correctness/Safety: At most one process holds the lock/enter C.S. at a time 2.Fairness: Any process that makes a request must be granted lock Implies that system must be deadlock-free Assumes that no process will hold onto a lock indefinitely Eventual fairness: Waiting process will not be excluded forever Bounded fairness: Waiting process will get lock within some bounded number of cycles (typically n) 12

Other Requirements 1.Low message overhead 2.No bottlenecks 3.Tolerate out-of-order messages 4.Allow processes to join protocol or to drop out 5.Tolerate failed processes 6.Tolerate dropped messages Today, will focus on 1-3 Total number of processes is fixed at n No process fails or misbehaves Communication never fails, but messages may be delivered out of order. 13

Mutual Exclusion A Centralized Algorithm Client  Acquire: Send (Request, i) to coordinator Wait for Server: while true: m = Receive() If m == (Request, i): If Available(): Send (Grant) to i 14

Mutual Exclusion A Centralized Algorithm Server: while true: m = Receive() If m == (Request, i): If Available(): Send (Grant) to I else: Add i to Q 15

Mutual Exclusion A Centralized Algorithm Server: while true: m = Receive() If m == (Request, i): If Available(): Send (Grant) to I else: Add i to Q If m == (Release)&&!empty(Q): Remove ID j from Q Send (Grant) to Client  Release: Send (Release) to coordinator 16

Mutual Exclusion A Centralized Algorithm (4) Correctness: Clearly safe Fairness depends on queuing policy. E.g., if always gave priority to lowest process ID, then processes 1 & 2 lock out 3 Performance "cycle" is a complete round of the protocol with one process i entering its critical section and then exiting. 3 messages per cycle (1 request, 1 grant, 1 release) Lock server creates bottleneck Issues What happens when coordinator crashes? What happens when it reboots? 17

Today's Lecture NTP correction Totally ordered multicast Centralized Mutual Exclusion Distributed Mutual Exclusion 18

Distributed Algorithm Strawman Assume that there are n coordinators Access requires a majority vote from m > n/2 coordinators. A coordinator always responds immediately to a request with GRANT or DENY Node failures are still a problem Large numbers of nodes requesting access can affect availability 19

A Distributed Algorithm 2 (Lamport Mutual Exclusion) Every process maintains a queue of pending requests for entering critical section in order. The queues are ordered by virtual time stamps derived from Lamport timestamps For any events e, e' such that e --> e' (causality ordering), T(e) < T(e') For any distinct events e, e', T(e) != T(e') When node i wants to enter C.S., it sends time-stamped request to all other nodes (including itself) Wait for replies from all other nodes. If own request is at the head of its queue and all replies have been received, enter C.S. Upon exiting C.S., remove its request from the queue and send a release message to every process. 20

A Distributed Algorithm 2 Other nodes: After receiving a request, enter the request in its own request queue (ordered by time stamps) and reply with a time stamp. This reply is unicast unlike the Lamport totally order multicast example. Why? Only the requester needs to know the message is ready to commit. Release messages are broadcast to let others to move on After receiving release message, remove the corresponding request from its own request queue. If own request is at the head of its queue and all replies have been received, enter C.S. 21

A Distributed Algorithm 2 Correctness When process x generates request with time stamp Tx, and it has received replies from all y in Nx, then its Q contains all requests with time stamps <= Tx. Performance Process i sends n-1 request messages Process i receives n-1 reply messages Process i sends n-1 release messages. Issues What if node fails? Performance compared to centralized What about message reordering? 22

A Distributed Algorithm 3 (Ricart & Agrawala) Also relies on Lamport totally ordered clocks. When node i wants to enter C.S., it sends time- stamped request to all other nodes. These other nodes reply (eventually). When i receives n-1 replies, then can enter C.S. Trick: Node j having earlier request doesn't reply to i until after it has completed its C.S. 23

A Distributed Algorithm Three different cases: 1.If the receiver is not accessing the resource and does not want to access it, it sends back an OK message to the sender. 2.If the receiver already has access to the resource, it simply does not reply. Instead, it queues the request. 3.If the receiver wants to access the resource as well but has not yet done so, it compares the timestamp of the incoming message with the one contained in the message that it has sent everyone. The lowest one wins. 24

A Distributed Algorithm Two processes (0 and 2) want to access a shared resource at the same moment. 25

A Distributed Algorithm Process 0 has the lowest timestamp, so it wins. 26

A Distributed Algorithm (4) When process 0 is done, it sends an OK also, so 2 can now go ahead. 27

Correctness Look at nodes A & B. Suppose both are allowed to be in their critical sections at same time. A must have sent message (Request, A, Ta) & gotten reply (Reply, A). B must have sent message (Request, B, Tb) & gotten reply (Reply, B). Case 1: One received request before other sent request. E.g., B received (Request, A, Ta) before sending (Request, B, Tb). Then would have Ta < Tb. A would not have replied until after leaving its C.S. Case 2: Both sent requests before receiving others request. But still, Ta & Tb must be ordered. Suppose Ta < Tb. Then A would not sent reply to B until after leaving its C.S. 28

Deadlock Free Cannot have cycle where each node waiting for some other Consider two-node case: Nodes A & B are causing each other to deadlock. This would result if A deferred reply to B & B deferred reply to A, but this would require both Ta < Tb & Tb < Ta. For general case, would have set of nodes A, B, C,..., Z, such that A is holding deferred reply to B, B to C,... Y to Z, and Z to A.This would require Ta < Tb <... < Tz < Ta, which is not possible. 29

Starvation Free If node makes request, it will be granted eventually Claim: If node A makes a request with time stamp Ta, then eventually, all nodes will have their local clocks > Ta. Justification: From the request onward, every message A sends will have time stamp > Ta. All nodes will update their local clocks upon receiving those messages. So, eventually, A's request will have a lower time stamp than anyother node's request, and it will be granted. 30

Performance Each cycle involves 2(n-1) messages n-1 requests by I n-1 replies to I Issues What if node fails? Performance compared to centralized 31

A Token Ring Algorithm Organize the processes involved into a logical ring One token at any time  passed from node to node along ring 32

A Token Ring Algorithm Correctness: Clearly safe: Only one process can hold token Fairness: Will pass around ring at most once before getting access. Performance: Each cycle requires between 1 - ∞ messages Latency of protocol between 0 & n-1 Issues Lost token 33

Summary Lamport algorithm demonstrates how distributed processes can maintain consistent replicas of a data structure (the priority queue). Ricart & Agrawala's algorithms demonstrate utility of logical clocks. Centralized & ring based algorithms much lower message counts None of these algorithms can tolerate failed processes or dropped messages. 34

A Comparison of the Four Algorithms 35

Ricart & Agrawala Example Processes 1, 2, 3. Create totally ordered clocks by having process ID compute timestamp of form T(e) = 10*L(e), where L(e) is a regular Lamport clock. Initial timestamps  P1: 421, P2: 112, P3: 143 Action types: R m: Receive message m B m: Broadcast message m to all other processes S m to j: Send message m to process j 36

Timeline ProcessT1T2T3Action 3153B (Request, 3, 153) 2162R (Request, 3, 153) 1431R (Request, 3, 153) 1441S (Reply, 1) to S (Reply, 2) to R (Reply, 1) 3463R (Reply, 2) 3473Enter critical section 1451B (Request, 1, 451) 2182B (Request, 2, 182) 3483R (Request, 1, 451) 3493R (Request, 2, 182) 1461R (Request, 2, 182) 2462R (Request, 1, 451) # 2 has D = {1} 1471S (Reply, 1) to 2 # 2 has higher priority 2482R (Reply, 1) 3503S (Reply, 3) to 1 # Release lock 3513S (Reply, 3) to R (Reply, 3) # 1 has R = {2} 2522R (Reply, 3) # 2 has R = {} 2532Enter critical section 2542S (Reply, 2) to 1 # Release lock 1551R (Reply, 2) # 1 has R = {} 1561Enter critical section 37

Overall Flow in Example P1 and P2 compete for lock after it is released by P3. P1's request has timestamp 451, while P2's request has timestamp 182. P2 defers reply to P1, but P1 replies to P2 immediately. This allows P2 to proceed ahead of P1. 38