1 CS194: Clocks and Synchronization Scott Shenker and Ion Stoica Computer Science Division Department of Electrical Engineering and Computer Sciences University.

Slides:



Advertisements
Similar presentations
Time in Distributed Systems
Advertisements

1 CS 194: Elections, Exclusion and Transactions Scott Shenker and Ion Stoica Computer Science Division Department of Electrical Engineering and Computer.
Time and Global States Part 3 ECEN5053 Software Engineering of Distributed Systems University of Colorado, Boulder.
Synchronization Chapter clock synchronization * 5.2 logical clocks * 5.3 global state * 5.4 election algorithm * 5.5 mutual exclusion * 5.6 distributed.
Time and synchronization (“There’s never enough time…”)
Time and Clock Primary standard = rotation of earth De facto primary standard = atomic clock (1 atomic second = 9,192,631,770 orbital transitions of Cesium.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Time and Synchronization Steve Ko Computer Sciences and Engineering University at Buffalo.
Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428 Fall 2011 August 30, 2011 Lecture 3 Time and Synchronization Reading: Sections
Distributed Systems Spring 2009
CS 582 / CMPE 481 Distributed Systems Synchronization.
Distributed Systems Fall 2010 Time and synchronization.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Time and Synchronization Steve Ko Computer Sciences and Engineering University at Buffalo.
Teaching material based on Distributed Systems: Concepts and Design, Edition 3, Addison-Wesley Copyright © George Coulouris, Jean Dollimore, Tim.
Synchronization Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion.
Time and Global States Chapter 11. Why time? Time is an Important and interesting issue in distributes systems. One we can measure accurately. Can use.
Time in Distributed Systems Distributed Systems. Why Time is Important? If you work in the industry, you never have to worry about this You’ll rarely.
Teaching material based on Distributed Systems: Concepts and Design, Edition 3, Addison-Wesley Copyright © George Coulouris, Jean Dollimore, Tim.
Distributed Systems CS Synchronization – Part II Lecture 8, Sep 28, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
Clock Synchronization and algorithm
EEC-681/781 Distributed Computing Systems Lecture 10 Wenbing Zhao Cleveland State University.
EEC-681/781 Distributed Computing Systems Lecture 10 Wenbing Zhao Cleveland State University.
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Clock Synchronization Physical clocks Clock synchronization algorithms –Cristian’s.
Lecture 9: Time & Clocks CDK4: Sections 11.1 – 11.4 CDK5: Sections 14.1 – 14.4 TVS: Sections 6.1 – 6.2 Topics: Synchronization Logical time (Lamport) Vector.
1 Synchronization Part 1 REK’s adaptation of Claypool’s adaptation of Tanenbaum’s Distributed Systems Chapter 5.
Lecture 2-1 CS 425/ECE 428 Distributed Systems Lecture 2 Time & Synchronization Reading: Klara Nahrstedt.
1 Physical Clocks need for time in distributed systems physical clocks and their problems synchronizing physical clocks u coordinated universal time (UTC)
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.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
1 Distributed Systems CS 425 / CSE 424 / ECE 428 Global Snapshots Reading: Sections 11.5 (4 th ed), 14.5 (5 th ed)  2010, I. Gupta, K. Nahrtstedt, S.
© Oxford University Press 2011 DISTRIBUTED COMPUTING Sunita Mahajan Sunita Mahajan, Principal, Institute of Computer Science, MET League of Colleges, Mumbai.
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Naming Name distribution: use hierarchies DNS X.500 and LDAP.
CSE 486/586 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
Communication & Synchronization Why do processes communicate in DS? –To exchange messages –To synchronize processes Why do processes synchronize in DS?
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Global States Steve Ko Computer Sciences and Engineering University at Buffalo.
Synchronization Distributed System. Why synchronization? Two sharpshooters in a multiplayer online game kill the same target. Which one gets the points?
Lecture 9: Time and clocks (Chap 11) Haibin Zhu, PhD. Assistant Professor Department of Computer Science Nipissing University © 2002.
Time This powerpoint presentation has been adapted from: 1) sApr20.ppt.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Real-Time & MultiMedia Lab Synchronization Distributed System Jin-Seung,KIM.
Synchronization CSCI 4900/6900. Importance of Clocks & Synchronization Avoiding simultaneous access of resources –Cooperate to grant exclusive access.
Distributed Systems Topic 5: Time, Coordination and Agreement
CS 582 / CMPE 481 Distributed Systems Synchronization.
6 SYNCHRONIZATION. introduction processes synchronize –exclusive access. –agree on the ordering of events much more difficult compared to synchronization.
Synchronization. Clock Synchronization In a centralized system time is unambiguous. In a distributed system agreement on time is not obvious. When each.
Hwajung Lee. Primary standard = rotation of earth De facto primary standard = atomic clock (1 atomic second = 9,192,631,770 orbital transitions of Cesium.
Ordering of Events in Distributed Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 739 Distributed Systems Andrea C. Arpaci-Dusseau.
CSE 486/586 CSE 486/586 Distributed Systems Global States Steve Ko Computer Sciences and Engineering University at Buffalo.
Distributed Systems Lecture 5 Time and synchronization 1.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586 CSE 486/586 Distributed Systems Time and Synchronization Steve Ko Computer Sciences and Engineering University at Buffalo.
Distributed Systems Lecture 6 Global states and snapshots 1.
Distributed Web Systems Time and Global State Lecturer Department University.
Distributed Computing
CSE 486/586 Distributed Systems Logical Time
CSE 486/586 Distributed Systems Time and Synchronization
CSE 486/586 Distributed Systems Logical Time
Time Synchronization and Logical Clocks
Logical time (Lamport)
Chapter 5 (through section 5.4)
CDK: Sections 11.1 – 11.4 TVS: Sections 6.1 – 6.2
Distributed Synchronization
Logical time (Lamport)
Logical time (Lamport)
Chap 5 Distributed Coordination
CSE 486/586 Distributed Systems Logical Time
CSE 486/586 Distributed Systems Time and Synchronization
Logical time (Lamport)
Last Class: Naming Name distribution: use hierarchies DNS
Presentation transcript:

1 CS194: Clocks and Synchronization Scott Shenker and Ion Stoica Computer Science Division Department of Electrical Engineering and Computer Sciences University of California, Berkeley Berkeley, CA

2 Warning!  Material is deceptively simple  Looks obvious once you’ve thought about it  But it took several years (and Lamport) to do the thinking  And even the authors made errors….  Just pay attention to the basic ideas, will get more detailed later in the course

3 When Did Time Begin?  January 1, 1958  In this lecture, when I refer to reference time, I mean universal coordinated time (UTC)

4 Why Do Clocks Matter?  Correlate with outside world -Paper deadlines, earthquake analysis, etc. -Need true UTC  Organize local process -File timestamps, etc. -Ordering, not UTC  Coordinate between machines -Later: will use it in Kerboros, concurrency control, etc. -Rarely UTC, usually need synchronized ordering

5 Example: Make  Make inspects files and compiles those that have changed since the last compilation.  Assume file.c lives on machine 1, but file.o is produced on machine 2.  If machine 2’s clock is ahead of machine 1’s, what might happen?

6 Make Example UTCC1C2 File compiled File edited Make initiated File.c on 1: 10File.o on 2: 15 Make does not recompile file

7 What Does Make Need?  Machine needs to know if time of compilation is later than time of last edit.  Ordering, not absolute time.  Could be easily provided at the application level -Annotate file.o with timestamp of file.c

8 Assumptions  Each machine has local clock  No guarantee of accuracy, but never runs backwards  Clocks on different machines will eventually differ substantially unless adjustments are made

9 Terminology  Consider a clock with readings C(t), where t is UTC  If C(t) = R x t + A then (different from book) A = offset R = skew  If A or R change, that’s drift  Different clocks have different A, R

10 Adjusting Clocks  Never make time go backwards! -Would mess up local orderings  If you want to adjust a clock backwards, just slow it down for a bit

11 Aside #1: How Good are Clocks?  Ordinary quartz clocks: drift-seconds/second  High-precision quartz clocks:  International Atomic Time (IAT):  GPS: (why not just use GPS?)  Computer clocks are lousy!

12 Clock Synchronization (Cristian)  Client polls time server (which has external UTC source)  Gets time from server  How does it adjust this time? -Estimates travel time as 1/2 of RTT -Adds this to server time  Problems? (major and minor)

13 Clock Synchronization (Berkeley)  Time master polls clients (has no UTC)  Gets time from each client, and averages  Sends back message to each client with a recommended adjustment  What advantages does this algorithm have?

14 Aside #2: Internet vs LAN  Synchronizing at Internet scale is very different than synchronizing on a LAN -Delays more variable -Packet drops more likely

15 Network Time Protocol (NTP)  Time service for the Internet -Synchronizes clients to UTC  Primary servers connected to UTC source  Secondary servers are synchronized to primary servers  Clients synchronize with secondary servers

16 NTP (2)  Reconfigurable hierarchy -Adapts to server failures, etc.  Multiple modes of synchronization -Multicast (on LAN) -Server-based RPC -Symmetric (the fancy part!) Pairs exchange messages Attempt to model skew, offset Signal processing to average out random delays 10s of milliseconds over Internet

17 Aside #3: Sensornet Synchronization  Leverages properties of broadcast: -Multiple receivers -Minimal propagation time  Beacon sends out messages -Nodes receiving them compare timestamps  Can extend to global synchronization -Neat mathematics….(clocks as rubber bands)  On order of microseconds, not milliseconds -Why is this important?

18 Logical Clocks  Who cares about time anyway?  Ordering is usually enough  What orderings do we need to preserve?

19 Lamport “Happens Before”  A  B means A “happens before” -A and B are in same process, and B has a later timestamp -A is the sending of a message and B is the receipt  Transitive relationship -A  B and B  C implies A  C  If neither A  B nor B  A are true, then A and B are “concurrent” (not simultaneous)

20 Lamport Timestamps  When message arrives, if process time is less than timestamp s, then jump process time to s+1  Clock must tick once between every two events  If A  B then must have L(A) < L(B)  If L(A) < L(B), it does NOT follow that A  B  How would this help make?

21 Make Example (revisited) UTCC1C2 Before compiled After compiled File edited Make initiated File.c on 1: 20File.o on 2: 15 Make recompiles file

22 Ordering Noncausal Events  Lamport timestamps don’t prevent two sites from processing events in different order -Lamport timestamps don’t unambiguously order events without a potential causal relationship  In some cases (banking!) need everyone to process messages in the same order, even if there isn’t a causal order  For that, we can use Totally Ordered Multicast

23 Totally Ordered Multicast  Each message is broadcast to all other clients, with timestamp  Each client broadcasts the ACK of that message -N^2 algorithm, not likely in the Internet….  Only process head-of-queue (ordered by timestamp) when all ACKs received  Why does this work?  What happens when packets are reordered?

24 Totally Ordered Multicast (2)  Don’t do event, then timestamp it.  Declare your intention to do something, and timestamp that declaration  Makes sure everyone hears that declaration  All done in same order (not necessarily chronological!)

25 Aside #3: The Debate!  There is a dispute about whether one needs highly synchronized primitives like totally ordered multicast -Recall, make problem handled by app-specific techniques  Some contend that you should not embed heavyweight time ordering when most events don’t need to be ordered -Only order important events using app-specific methods

26 Vector Timestamps  L(A) < L(B) doesn’t tell you that A came before B  Only incorporates intrinsic causality, ignores any relationship with external clocks or external events  Vector timestamps have the property that -V(A) < V(B) then A causally precedes B

27 Vector Timestamps (2)  V I [I]: number of events occurred in process I  V I [J] = K: process I knows that K events have occurred at process J  All messages carry vectors  When J receives vector v, for each K it sets V J [K] = v[K] if it is larger than its current value

28 Vector Timestamps (3)  If the vector associated event A is less than that associated with B, then A preceded B.  This comparison is element by element  Two vectors are “concurrent” if neither dominates the other -(1,5,1) vs (5, 1, 5)  Why does this work?

29 Global State  Global state is local state of each process, including any sent messages -Think of this as the sequence of events in each process -Useful for debugging, etc.  If we had perfect synchronization, it would be easy to get global state at some time t -But don’t have synchronization, so need to take snapshot with different times in different processes  A consistent state is one in which no received messages haven’t been sent -No causal relationships violated

30 Distributed Snapshot  Initiating process records local state and sends out “marker” to its “neighbors”  Whenever a process receives a marker: -Not recorded local state yet: records, then sends out marker -Already recorded local state: records all messages received after it recorded its own local state  A process is done when it has received a marker along each channel; it then sends state to initiator

31 Termination  Need distributed snapshot with no messages in flight  Send “continue” message when finished with all channels, but not all have sent “done”  Send “done” when all channels have sent “done” or when no other messages have been received since taking local state

32 Comments  Few of these algorithms work at scale, with unreliable messages and flaky nodes  What do we do in those cases?