Distributed Systems: Time and Mutual Exclusion. 2 Distributed Systems Definition: Loosely coupled processors interconnected by network Distributed system.

Slides:



Advertisements
Similar presentations
CS542 Topics in Distributed Systems Diganta Goswami.
Advertisements

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.
CSC 4320/6320 Operating Systems Lecture 13 Distributed Coordination
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.
Ken Birman Cornell University. CS5410 Fall
Distributed Systems Spring 2009
CS 582 / CMPE 481 Distributed Systems
What we will cover…  Distributed Coordination 1-1.
Ordering and Consistent Cuts Presented By Biswanath Panda.
Shared Memory Coordination We will be looking at process coordination using shared memory and busy waiting. –So we don't send messages but read and write.
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.
CS514: Intermediate Course in Operating Systems Professor Ken Birman Vivek Vishnumurthy: TA.
Module 2.4: Distributed Systems
20101 Synchronization in distributed systems A collection of independent computers that appears to its users as a single coherent system.
Synchronization in Distributed Systems. Mutual Exclusion To read or update shared data, a process should enter a critical region to ensure mutual exclusion.
SynchronizationCS-4513, D-Term Synchronization in Distributed Systems CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts,
Lecture 13 Synchronization (cont). EECE 411: Design of Distributed Software Applications Logistics Last quiz Max: 69 / Median: 52 / Min: 24 In a box outside.
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.
EEC-681/781 Distributed Computing Systems Lecture 11 Wenbing Zhao Cleveland State University.
EEC-681/781 Distributed Computing Systems Lecture 10 Wenbing Zhao Cleveland State University.
Lecture 12 Synchronization. EECE 411: Design of Distributed Software Applications Summary so far … A distributed system is: a collection of independent.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms.
Time, Clocks, and the Ordering of Events in a Distributed System Leslie Lamport (1978) Presented by: Yoav Kantor.
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.
4.5 DISTRIBUTED MUTUAL EXCLUSION MOSES RENTAPALLI.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved Chapter 6 Synchronization.
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Naming Name distribution: use hierarchies DNS X.500 and LDAP.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms –Bully algorithm.
Operating Systems Distributed Coordination. Topics –Event Ordering –Mutual Exclusion –Atomicity –Concurrency Control Topics –Event Ordering –Mutual Exclusion.
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.
Presenter: Long Ma Advisor: Dr. Zhang 4.5 DISTRIBUTED MUTUAL EXCLUSION.
Synchronization. Why we need synchronization? It is important that multiple processes do not access shared resources simultaneously. Synchronization in.
CS514: Intermediate Course in Operating Systems Professor Ken Birman Krzys Ostrowski: TA.
CSC 536 Lecture 1. Outline Synchronization Clock synchronization Logical clocks Lamport timestamps Vector timestamps Global states and distributed snapshot.
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.
Communication & Synchronization Why do processes communicate in DS? –To exchange messages –To synchronize processes Why do processes synchronize in DS?
CIS825 Lecture 2. Model Processors Communication medium.
D u k e S y s t e m s Asynchronous Replicated State Machines (Causal Multicast and All That) Jeff Chase Duke University.
Distributed Systems. -2 A Distributed System -3 Loosely Coupled Distributed Systems r Users are aware of multiplicity of machines. Access to resources.
Distributed Process Coordination Presentation 1 - Sept. 14th 2002 CSE Spring 02 Group A4:Chris Sun, Min Fang, Bryan Maden.
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Distributed Systems: Motivation, Time, Mutual Exclusion.
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.
Ordering of Events in Distributed Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 739 Distributed Systems Andrea C. Arpaci-Dusseau.
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.
CIS 825 Review session. P1: Assume that processes are arranged in a ring topology. Consider the following modification of the Lamport’s mutual exclusion.
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.
Ordering of Events in Distributed Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 739 Distributed Systems Andrea C. Arpaci-Dusseau.
Distributed Mutex EE324 Lecture 11.
Outline Distributed Mutual Exclusion Introduction Performance measures
Chapter 5 (through section 5.4)
Synchronization (2) – Mutual Exclusion
Distributed Systems and Concurrency: Synchronization in Distributed Systems Majeed Kassis.
Presentation transcript:

Distributed Systems: Time and Mutual Exclusion

2 Distributed Systems Definition: Loosely coupled processors interconnected by network Distributed system is a piece of software that ensures: –Independent computers appear as a single coherent system Lamport: “A distributed system is a system where I can’t get my work done because a computer has failed that I never heard of”

3 Today What is the time now? Distributed Mutual Exclusion

4 What time is it? In distributed system we need practical ways to deal with time –E.g. we may need to agree that update A occurred before update B –Or offer a “lease” on a resource that expires at time 10: –Or guarantee that a time critical event will reach all interested parties within 100ms

5 But what does time “mean”? Time on a global clock? –E.g. with GPS receiver … or on a machine’s local clock –But was it set accurately? –And could it drift, e.g. run fast or slow? –What about faults, like stuck bits? … or could try to agree on time

6 Event Ordering Fundamental Problem: distributed systems do not share a clock –Many coordination problems would be simplified if they did (“first one wins”) Distributed systems do have some sense of time –Events in a single process happen in order –Messages between processes must be sent before they can be received –How helpful is this?

7 Lamport’s approach Leslie Lamport suggested that we should reduce time to its basics –Time lets a system ask “Which came first: event A or event B?” –In effect: time is a means of labeling events so that… If A happened before B, TIME(A) < TIME(B) If TIME(A) < TIME(B), A happened before B

8 Drawing time-line pictures: p m snd p (m) q rcv q (m) deliv q (m) D

9 Drawing time-line pictures: A, B, C and D are “events”. –Could be anything meaningful to the application –So are snd(m) and rcv(m) and deliv(m) What ordering claims are meaningful? p m A C B snd p (m) q rcv q (m) deliv q (m) D

10 Drawing time-line pictures: A happens-before B, and C happens-before D –“Local ordering” at a single process –Write and p q m A C B rcv q (m) deliv q (m) snd p (m) D

11 Drawing time-line pictures: snd p (m) also happens-before rcv q (m) –“Distributed ordering” introduced by a message –Write p q m A C B rcv q (m) deliv q (m) snd p (m) D

12 Drawing time-line pictures: A happens-before D –Transitivity: A happens-before snd p (m), which happens-before rcv q (m), which happens-before D p q m D A C B rcv q (m) deliv q (m) snd p (m)

13 Drawing time-line pictures: Does B happen before D? B and D are concurrent –Looks like B happens first, but D has no way to know. No information flowed… p q m D A C B rcv q (m) deliv q (m) snd p (m)

14 Happens before “relation” We’ll say that “A happens-before B”, written A  B, if 1.A  P B according to the local ordering, or 2.A is a snd and B is a rcv and A  M B, or 3.A and B are related under the transitive closure of rules (1) and (2) So far, this is just a mathematical notation, not a “systems tool”

15 Logical clocks A simple tool that can capture parts of the happens before relation First version: uses just a single integer –Designed for big (64-bit or more) counters –Each process p maintains LogicalTimestamp (LT p ), a local counter –A message m will carry LT m

16 Rules for managing logical clocks When an event happens at a process p it increments LT p. –Any event that matters to p –Normally, also snd and rcv events (since we want receive to occur “after” the matching send) When p sends m, set –LT m = LT p When q receives m, set –LT q = max(LT q, LT m )+1

17 Time-line with LT annotations LT(A) = 1, LT(snd p (m)) = 2, LT(m) = 2 LT(rcv q (m))=max(1,2)+1=3, etc… p q m D A C B rcv q (m) deliv q (m) snd p (m) LT q LT p

18 Logical clocks If A happens-before B, A  B, then LT(A)<LT(B) But converse might not be true: –If LT(A)<LT(B) can’t be sure that A  B –This is because processes that don’t communicate still assign timestamps and hence events will “seem” to have an order

19 Total ordering? Happens-before gives a partial ordering of events We still do not have a total ordering of events

20 Partial Ordering Pi ->Pi+1; Qi -> Qi+1; Ri -> Ri+1 R0->Q4; Q3->R4; Q1->P4; P1->Q2

21 Total Ordering? P0, P1, Q0, Q1, Q2, P2, P3, P4, Q3, R0, Q4, R1, R2, R3, R4 P0, Q0, Q1, P1, Q2, P2, P3, P4, Q3, R0, Q4, R1, R2, R3, R4 P0, Q0, P1, Q1, Q2, P2, P3, P4, Q3, R0, Q4, R1, R2, R3, R4

22 Logical Timestamps w/ Process ID Assume each process has a local logical clock that ticks once per event and that the processes are numbered –Clocks tick once per event (including message send) –When send a message, send your clock value –When receive a message, set your clock to MAX( your clock, timestamp of message + 1) Thus sending comes before receiving Only visibility into actions at other nodes happens during communication, communicate synchronizes the clocks –If the timestamps of two events A and B are the same, then use the network/process identity numbers to break ties. This gives a total ordering!

23 Distributed Mutual Exclusion (DME) Example: Want mutual exclusion in distributed setting –The system consists of n processes; each process P i resides at a different processor –Each process has a critical section that requires mutual exclusion Problem: We can no longer rely on just an atomic test and set operation on a single machine to build mutual exclusion primitives Requirement –If P i is executing in its critical section, then no other process P j is executing in its critical section.

24 Solution We present three algorithms to ensure the mutual exclusion execution of processes in their critical sections. –Centralized Distributed Mutual Exclusion (CDME) –Fully Distributed Mutual Exclusion (DDME) –Token passing

25 CDME: Centralized Approach One of the processes in the system is chosen to coordinate the entry to the critical section. –A process that wants to enter its critical section sends a request message to the coordinator. –The coordinator decides which process can enter the critical section next, and its sends that process a reply message. –When the process receives a reply message from the coordinator, it enters its critical section. –After exiting its critical section, the process sends a release message to the coordinator and proceeds with its execution. 3 messages per critical section entry

26 Problems of CDME Electing the master process? Hardcoded? Single point of failure? Electing a new master process? Distributed Election algorithms later…

27 DDME: Fully Distributed Approach When process P i wants to enter its critical section, it generates a new timestamp, TS, and sends the message request (P i, TS) to all other processes in the system. When process P j receives a request message, it may reply immediately or it may defer sending a reply back. When process P i receives a reply message from all other processes in the system, it can enter its critical section. After exiting its critical section, the process sends reply messages to all its deferred requests.

28 DDME: Fully Distributed Approach (Cont.) The decision whether process P j replies immediately to a request(P i, TS) message or defers its reply is based on three factors: –If P j is in its critical section, then it defers its reply to P i. –If P j does not want to enter its critical section, then it sends a reply immediately to P i. –If P j wants to enter its critical section but has not yet entered it, then it compares its own request timestamp with the timestamp TS. If its own request timestamp is greater than TS, then it sends a reply immediately to P i (P i asked first). Otherwise, the reply is deferred.

29 Problems of DDME Requires complete trust that other processes will play fair –Easy to cheat just by delaying the reply! The processes needs to know the identity of all other processes in the system –Makes the dynamic addition and removal of processes more complex. If one of the processes fails, then the entire scheme collapses. –Dealt with by continuously monitoring the state of all the processes in the system. Constantly bothering people who don’t care –Can I enter my critical section? Can I?

30 Token Passing Circulate a token among processes in the system Possession of the token entitles the holder to enter the critical section Organize processes in system into a logical ring –Pass token around the ring –When you get it, enter critical section if need to then pass it on when you are done (or just pass it on if don’t need it)

31 Problems of Token Passing If machines with token fails, how to regenerate a new token? A lot like electing a new coordinator If process fails, need to repair the break in the logical ring

32 Compare: Number of Messages? CDME: 3 messages per critical section entry DDME: The number of messages per critical-section entry is 2 x (n – 1) –Request/reply for everyone but myself Token passing: Between 0 and n messages –Might luck out and ask for token while I have it or when the person right before me has it –Might need to wait for token to visit everyone else first

33 Compare : Starvation CDME : Freedom from starvation is ensured if coordinator uses FIFO DDME: Freedom from starvation is ensured, since entry to the critical section is scheduled according to the timestamp ordering. The timestamp ordering ensures that processes are served in a first-come, first served order. Token Passing: Freedom from starvation if ring is unidirectional Caveats –network reliable (I.e. machines not “starved” by inability to communicate) –If machines fail they are restarted or taken out of consideration (I.e. machines not “starved” by nonresponse of coordinator or another participant) –Processes play by the rules

34 Summary What time did an event occur? –Rather, Lamport’s notion of time –Did a particular event occur before another? –Happens-before relation used for event ordering Happens-before gives a partial ordering But what about a total ordering –Logical Timestamp with process id used for tie breakers gives a total order Distributed mutual exclusion –Requirement: If P i is executing in its critical section, then no other process P j is executing in its critical section –Compare three solutions Centralized Distributed Mutual Exclusion (CDME) Fully Distributed Mutual Exclusion (DDME) Token passing