CS 347Notes 121 CS 347: Parallel and Distributed Data Management Notes12: Time and Clocks Hector Garcia-Molina.

Slides:



Advertisements
Similar presentations
Lecture 1: Logical, Physical & Casual Time (Part 2) Anish Arora CSE 763.
Advertisements

CS 542: Topics in Distributed Systems Diganta Goswami.
CS3771 Today: deadlock detection and election algorithms  Previous class Event ordering in distributed systems Various approaches for Mutual Exclusion.
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.
Computer Science 425 Distributed Systems CS 425 / ECE 428  2013, I. Gupta, K. Nahrtstedt, S. Mitra, N. Vaidya, M. T. Harandi, J. Hou.
Distributed Systems Dinesh Bhat - Advanced Systems (Some slides from 2009 class) CS 6410 – Fall 2010 Time Clocks and Ordering of events Distributed Snapshots.
Distributed Systems Spring 2009
CS 582 / CMPE 481 Distributed Systems
Ordering and Consistent Cuts Presented By Biswanath Panda.
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.
Synchronization in Distributed Systems CS-4513 D-term Synchronization in Distributed Systems CS-4513 Distributed Computing Systems (Slides include.
Ordering and Consistent Cuts Presented by Chi H. Ho.
Time, Clocks and the Ordering of Events in a Distributed System - by Leslie Lamport.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
EEC-681/781 Distributed Computing Systems Lecture 10 Wenbing Zhao Cleveland State University.
Distributed Systems: Time and Mutual Exclusion. 2 Distributed Systems Definition: Loosely coupled processors interconnected by network Distributed system.
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.
Time, Clocks, and the Ordering of Events in a Distributed System Leslie Lamport (1978) Presented by: Yoav Kantor.
Distributed Systems Foundations Lecture 1. Main Characteristics of Distributed Systems Independent processors, sites, processes Message passing No shared.
TIME, CLOCKS AND THE ORDERING OF EVENTS IN A DISTRIBUTED SYSTEM L. Lamport Computer Science Laboratory SRI International.
Logical Clocks (2). Topics r Logical clocks r Totally-Ordered Multicasting r Vector timestamps.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
1DT066 D ISTRIBUTED I NFORMATION S YSTEM Time, Coordination and Agreement 1.
EECS 262a Advanced Topics in Computer Systems Lecture 14 Lamport Clocks and OCC October 20 th, 2014 John Kubiatowicz Electrical Engineering and Computer.
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Naming Name distribution: use hierarchies DNS X.500 and LDAP.
MUTUAL EXCLUSION AND QUORUMS CS Distributed Mutual Exclusion Given a set of processes and a single resource, develop a protocol to ensure exclusive.
Parallel and Distributed Simulation Synchronizing Wallclock Time.
Page 1 Logical Clocks Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation is.
Logical Clocks. Topics Logical clocks Totally-Ordered Multicasting Vector timestamps.
Lamport’s Logical Clocks & Totally Ordered Multicasting.
Communication & Synchronization Why do processes communicate in DS? –To exchange messages –To synchronize processes Why do processes synchronize in DS?
Replication (1). Topics r Why Replication? r System Model r Consistency Models – How do we reason about the consistency of the “global state”? m Data-centric.
Commit Algorithms Hamid Al-Hamadi CS 5204 November 17, 2009.
Time, Clocks, and the Ordering of Events in a Distributed System Leslie Lamport Massachusetts Computer Associates,Inc. Presented by Xiaofeng Xiao.
Time This powerpoint presentation has been adapted from: 1) sApr20.ppt.
Physical clock synchronization Question 1. Why is physical clock synchronization important? Question 2. With the price of atomic clocks or GPS coming down,
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
CS603 Clock Synchronization February 4, What is Clock Synchronization? All nodes agree on time What do we mean by time? –Monotonic –Any observation.
Distributed Systems Topic 5: Time, Coordination and Agreement
CS 3471 CS 347: Parallel and Distributed Data Management Notes13: Time and Clocks.
Feb 15, 2001CSCI {4,6}900: Ubiquitous Computing1 Announcements.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Logical Clocks. Topics r Logical clocks r Totally-Ordered Multicasting.
Event Ordering. CS 5204 – Operating Systems2 Time and Ordering The two critical differences between centralized and distributed systems are: absence of.
Hwajung Lee. Primary standard = rotation of earth De facto primary standard = atomic clock (1 atomic second = 9,192,631,770 orbital transitions of Cesium.
Lecture 1: Logical and Physical Time with some Applications Anish Arora CSE 6333 Notes include material from Dr. Jeff Brumfield.
Ordering of Events in Distributed Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 739 Distributed Systems Andrea C. Arpaci-Dusseau.
CS533 Concepts of Operating Systems Class 8 Time, Clocks, and the Ordering of Events in a Distributed System By Constantia Tryman.
CS3771 Today: Distributed Coordination  Previous class: Distributed File Systems Issues: Naming Strategies: Absolute Names, Mount Points (logical connection.
Distributed Systems Lecture 9 Leader election 1. Previous lecture Middleware RPC and RMI – Marshalling 2.
11-Jun-16CSE 542: Operating Systems1 Distributed systems Time, clocks, and the ordering of events in a distributed system Leslie Lamport. Communications.
Distributed Systems Lecture 5 Time and synchronization 1.
CSE 486/586 CSE 486/586 Distributed Systems Time and Synchronization Steve Ko Computer Sciences and Engineering University at Buffalo.
Ordering of Events in Distributed Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 739 Distributed Systems Andrea C. Arpaci-Dusseau.
Logical time Causality between events is fundamental to the design of parallel and distributed systems. In distributed systems, it is not possible to have.
John Kubiatowicz and Anthony D. Joseph
CSE 486/586 Distributed Systems Time and Synchronization
John Kubiatowicz Electrical Engineering and Computer Sciences
TIME, CLOCKS AND THE ORDERING OF EVENTS IN A DISTRIBUTED SYSTEM
Chapter 5 (through section 5.4)
Logical time (Lamport)
John Kubiatowicz Electrical Engineering and Computer Sciences
CSE 542: Operating Systems
Last Class: Naming Name distribution: use hierarchies DNS
Outline Theoretical Foundations
Presentation transcript:

CS 347Notes 121 CS 347: Parallel and Distributed Data Management Notes12: Time and Clocks Hector Garcia-Molina

CS 347Notes 122 Reference: Leslie Lamport, Time, clocks, and the ordering of events in a distributed system, Communications of the ACM, Volume 21, Issue 7 (July 1978), pages: Available at:

CS 347Notes 123 Time and clocks Time and clocks are fundamental concepts in distributed systems e.g.:timeouts identifying calls, transactions,… setting priorities versions of data...

CS 347Notes 124 What is time? How can clocks be implemented? Questions

CS 347Notes 125 Ordering of events More basic than time: event ordering event ahappened event b 9 am before 10 am Do not need physical time to order events event ahappened before event b can affect

CS 347Notes 126 Ordering of events “  ” is a partial ordering [ total ordering: for any two events a,b (a  b) either a  b or b  a partial ordering: a,b can be concurrent ]

CS 347Notes 127 The model ProcessProcessProcess P Q R P4P4 P3P3 P2P2 P1P1 R4R4 R3R3 R2R2 R1R1 Q7Q7 Q6Q6 Q3Q3 Q2Q2 Q5Q5 Q1Q1 Q4Q4 TIMETIME

CS 347Notes 128 Events within a process are totally ordered Sending or receiving a message is an event No assumptions about message transmission times E.g.: P 1  P 2 P 1  Q 2 P 3, Q 3 concurrent

CS 347Notes 129 Definition The relation  on the set of events of a system is the smallest relation satisfying the following 3 conditions: 1) if a,b events in same process, and a comes before b, then a  b 2) if a is sending a message and b is receipt of same message by a different process, then a  b 3) if a  b and b  c, than a  c assume a  a if a  b and b  a, than a,b are concurrent

CS 347Notes 1210 Logical Clocks ProcessProcess Process P QR P4P4 P3P3 P2P2 P1P1 R4R4 R3R3 R2R2 R1R1 Q7Q7 Q6Q6 Q3Q3 Q2Q2 Q5Q5 Q1Q1 Q4Q4 TIMETIME C R =9 C R =8 C R =7 C R =6 C R =5

Overview Logical Clocks Physical Clocks –basic properties –synchronization scheme –synchronization with clock server –probabilistic synchronization CS 347Notes 1211

CS 347Notes 1212 Logical Clock C i =logical clock (counter) at process i C[b] = reading of C j when event b occurs at process j Clock condition for any events a,b IF a  b THEN C[a] < C[b] No relationship to physical time

CS 347Notes 1213 Clock Condition If a and b are events in process i and a comes before b, then C i [a] < C i [b] If a is the sending of a message by process i and b is the receipt of that message by process j, then C i [a] < C j [b] C1C1 C2C2 If a  b THEN C[a] < C[b] can be satisfied if the following conditions hold:

CS 347Notes 1214 ProcessProcess Process P QR P4P4 P3P3 P2P2 P1P1 R4R4 R3R3 R2R2 R1R1 Q7Q7 Q6Q6 Q3Q3 Q2Q2 Q5Q5 Q1Q1 Q4Q4 TIMETIME C R =7 C R =5 C Q =10 7>5 by C1 10>7 by C2

CS 347Notes 1215 To implement C1, C2: IR1 Each process i increments C i between any two successive events IR2 - Let a be event “process i sends message to j” - Message contains timestamp T m = C i [a] - When message arrives at j (1) IF T m > C j THEN C j  T m (2) event “arrival of message” takes place

CS 347Notes 1216 Note: C i [a] < C j [b]  a  b Note: a,b concurrent  C i [a] = C j [b] Note: C i [a] = C j [b]  a,b concurrent

CS 347Notes 1217 Ordering Events Totally (breaking ties) Example: A server wants to execute requests in order a is event that originated one request (at client) b is event that originates second request (at other client) If C[a] < C[b], service a first (it could be that a  b) If C[a] = C[b], pick one (a,b concurrent) e.g., pick one with lower [ node#, process id ]

CS 347Notes 1218 Total Ordering Let “<” be a total ordering of the processes Define total ordering of events “  ” a  b (a event in process i; b in j) if and only if (1) C i [a] < C j [b] or (2) C i [a] = C j [b] and i < j “  ” not unique

CS 347Notes 1219 Anomalous behavior C=100C=50 Reserve a TelephoneReserve a seat call seat server Client AClient B 1 2 3

CS 347Notes 1220 Anomalous behavior C=100C=50 Reserve a TelephoneReserve a seat call seat server Client AClient B C= 9am

CS 347Notes 1221 Solutions (1) Include “telephone call” in “system” (2) Use perfect physical clocks (3) Use real physical clocks - may be “slightly off” - does not eliminate anomaly, but reduces its likelihood - useful for fault detection

CS 347Notes 1222 Physical Clocks C i (t) = clock reading at process i at physical time t time=t C i (t)

CS 347Notes 1223 time=t C i (t) C i + (x) C i - (x) C i - (x)=lim C i (x - |  |) C i + (x)=lim C i (x + |  |) 00 x Assume Ci(t) is a continuous, differentiable function except when clock is reset (message arrived) 00

CS 347Notes 1224 How do we enforce clock condition? If a  b then C(a) < C(b)

CS 347Notes 1225 Each process i increments C i between any two successive events For each process i, if i does not receive a message at time t, then C i is differentiable at t and dCi(t) dt IR1 IR1’ Logical clocks > 0 process i a b TIMETIME

CS 347Notes 1226 Let a be event “process i sends message m to j” m contains timestamp T m = C i [a] when m arrives at j (1) IF T m > C j THEN C j  T m (2) event “arrival of m” takes place IR2 Logical clocks

CS 347Notes 1227 Let a be event “process i sends message m to j” at physical time t m contains timestamp T m = C i (t) Let  m be minimum transmission delay for m m arrives at process j at physical time t’ t’ > t +  m IF Tm +  m > C j - (t’) THEN C j +  T m +  m After clock adjust, event “arrival of m” takes place IR2’ optional

CS 347Notes 1228 i j t t’ m mm IF Tm +  m > C j - (t’) THEN C j +  T m +  m TIMETIME

CS 347Notes 1229 Additional properties Clock drift There exists a contstant k <<1 such that for all processes i dCi(t) dt - 1 < k PC1

CS 347Notes 1230 For typical crystal controlled clocks, k < time CiCi xx+1 y y+1 k k y+1+k y+1-k dCi(t) dt - 1 < k

CS 347Notes 1231 Clock synchronization for all i,j:| Ci(t) - Cj(t) | <  PC2

CS 347Notes 1232 can be satisfied if a message is sent on every link at least every  seconds PC2 diameter = d d=4 (not 3)

CS 347Notes 1233  let  m be the transmission time of message m  m = minimum delay + unpredictable delay  m =  m + Z m Assume constant  such that for all m: Z m   Assume that for all m:  m =  t 1 t2t2 maximum transit time:  +  shortest transit time: 

CS 347Notes 1234 Theorem PC2 holds for all t > t o +  d with   d(2k  +  ) (assuming  +  <<  ).

CS 347Notes 1235 Argument for d=1 slow fast sf Worst case scenario: t 1 : m leaves f for s with T m = C f (t 1 ) t 2 : m arrives at s: C s (t 2 ) = C f (t 1 ) +  C f (t 2 ) - C s (t 2 ) is as large as possible,  t 2 +  : no communication for  sec; f is as fast as possible, s as slow as possible. Just before communication at t 2 +  clocks are as far apart as possible, 

CS 347Notes 1236 t 2 +  t2t2 f s kk kk    time clock reading So,  = 2  +  Now just need largest possible 

CS 347Notes 1237 C f (t 1 ) t 1 C s (t 2 ) t 2 f s ++ C f (t 2 ) = C f (t 1 ) + (1+k)(  +  ) C s (t 2 ) = C f (t 1 ) +   = (1+k)(  +  ) -  max  = k(  +  ) + 

CS 347Notes 1238  =2k  +  max  = k(  +  ) +  Thus:  = 2  +  + k(  +  ) Assuming that k<<1 and (  +  ) <<  we get:   2  + 

CS 347Notes 1239 Summary Physical clocks: clock condition a  b  C(a) < C(b) drift < k | Ci(t) - Cj(t) | <  can be implemented as discrete

CS 347Notes 1240 Uses for Physical Clocks: (1) To order events (2) Timeouts Example: “Reply to my request by time t 1 ” At time t 2 = (  +  +  )( 1+  ) + t 1 we can timeout my clock may drift

CS 347Notes 1241 my node other t 1 on my clock  max trans  +  t 1 at remote clock t 2 = (  +  +  )( 1+  ) + t 1

CS 347Notes 1242 Do physical clocks rule out anomalous behavior? No anomalous behavior if C s (t 2 )>C f (t 1 )  min f fast clock s slow clock message out of system C f (t 1 ) C s (t 2 ) C s (t 1 )=C f (t 1 ) - 

CS 347Notes 1243 Worst possible scenario: Smallest possible transmission time  min C s, C f as far apart as possible C s (t 1 ) = C f (t 1 ) -  Smallest possible C s (t 2 ) = C f (t 1 ) -  + S.P.increment = C f (t 1 ) -  +  min (1-  ) No anomalous behavior if C s (t 2 )>C f (t 1 )

CS 347Notes 1244 No A.B. if C s (t 2 ) > C f (t 1 ) I.e., if C f (t 1 ) -  +  min (1-  ) > C f (t 1 )  1 - k  min >

CS 347Notes 1245 Using a clock service With IR2’, a fast clock speeds up all clocks Use instead a single, reliable clock service (eg. WWV), assume it is perfect “real time” (k=0) IR2’ is now: C j + (t ’ )  T m +  min whenever timing message arrives If max. transmission time from central clock is <  +  then  k    (1 + k  (Why? )

CS 347Notes 1246 Using a clock service - analysis 0  error at synchronization time, node j   node j server Cj=+Cj=+ Cj=+Cj=+ ++++ ++  time slowest clock message fastest clock message

CS 347Notes 1247 Using a clock service - analysis - cont.   elapsed time  server time 0  Node that got fastest message Node that got slowest message time  possible difference slow clock fast clock

CS 347Notes 1248 Why can period be   ? ++  t t +  server j   fast slow

CS 347Notes 1249   elapsed time  server time 0  Node that got fastest message Node that got slowest time    k(   kk worst case for clock reset

CS 347Notes 1250  server time 0  Node that got fastest message Node that got slowest time  k(   kk worst case for clock reset |C s (t) - C j (t)|    |C k (t) - C j (t)|  2  

CS 347Notes 1251 Setting clocks back C j (t) time timing msg arrives cannot use other solutions?

CS 347Notes 1252 How can we reset a clock after a failure?

CS 347Notes 1253 Probabilistic clock synchronization |C j (t) - C k (t)|  2k   k  CsCs k = drift  =update period  =max. transmission variability

CS 347Notes 1254 Probabilistic clock synchronization |C j (t) - C k (t)|  2k   k  CsCs k = drift  =update period  =max. transmission variability   % of messages transmission time

CS 347Notes 1255 Idea #1 When site j wants to synchronize, it requests time from server T 2  v C j  T+  +v/2 server time j assume k =0

CS 347Notes 1256 Idea #1 When site j wants to synchronize, it requests time from server T 2  v C j  T+  +v/2 server time j  T+  +v T assume k =0

CS 347Notes 1257 Idea #1 When site j wants to synchronize, it requests time from server T 2  v C j  T+  +v/2 server time j  T+  +v T T+  T assume k =0

CS 347Notes 1258 Idea #1 When site j wants to synchronize, it requests time from server T 2  v C j  T+  +v/2 server time j  T+  +v T T+  T |C s (t) - C j (t)|  v/2 assume k =0

CS 347Notes 1259 If we are lucky, v will be small and we get tight synchronization If we are unlucky, v is large and we lose!! |C s (t) - C j (t)|  v/2

CS 347Notes 1260 Idea #2 (a) pick desired desired bound, D (b) repeat request until v/2  D (c) if more than q requests, we die!

CS 347Notes 1261 area=p 22 2  D p.d.f of round trip delay Prob. 1 request fails = Pr[roundtrip time > 2   D]= p Prob. q requests fail = p q Prob. We can synchronize = 1 - p q  Choose q so that it is “very likely” that algorithm works...

CS 347Notes 1262 If k = 0, we are done –step 1: all nodes synchronize –step 2: we stay synchronized forever If k > 0, synchronize every  seconds homework…..

Excecise Consider the clock synchronization scheme described in Slides (Notes 10), where a server site has an accurate clock. Assume that communications are asymetric, so that messages TO the server are "slower": –Largest minimum delay is  –Largest unpredictable delay is  2 messages FROM the server are "faster": –Largest minimum delay is  –Largest unpredictable delay is  1 and  1 <  2. Continue to assume that   is zero. At time t1 a node j sends a synchronization request to the server. At time t2 = t1 + v + , node j receives its reply CS 347Notes 1263

(1) When j gets the reply from the server at time t2 (containing server time T), to what value should it set its local clock? Answer: Cj(t2) <- T + v/2 +  (2) Right after the local clock is updated at j, how far apart can the local and server clocks be? That is, what is the largest possible value of | Cs(t2) - Cj(t2) | ? Answer: v/2 CS 347Notes 1264