1 / 64

CS 347: Parallel and Distributed Data Management Notes12: Time and Clocks

CS 347: Parallel and Distributed Data Management Notes12: Time and Clocks. Hector Garcia-Molina. 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: 558 - 565.

snowy
Download Presentation

CS 347: Parallel and Distributed Data Management Notes12: Time and Clocks

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 347: Parallel and DistributedData ManagementNotes12: Time and Clocks Hector Garcia-Molina Notes 12

  2. 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: 558 - 565. • Available at:http://portal.acm.org/citation.cfm?id=359563 Notes 12

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

  4. Questions • What is time? • How can clocks be implemented? Notes 12

  5. Ordering of events • More basic than time: event ordering event a happened event b 9 am before 10 am • Do not need physical time to order events event a happened before event b can affect Notes 12

  6. 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 ] Notes 12

  7. The model Process Process Process P Q R T I M E P4 Q7 R4 Q6 P3 R3 Q5 Q4 Q3 R2 P2 Q2 R1 P1 Q1 Notes 12

  8. Events within a process are totally ordered • Sending or receiving a message is an event • No assumptions about message transmission times E.g.: P1 P2 P1 Q2 P3, Q3 concurrent Notes 12

  9. 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 Notes 12

  10. Logical Clocks Process Process Process P Q R P4 Q7 R4 CR=9 Q6 R3 P3 Q5 CR=8 Q4 Q3 R2 P2 CR=7 T I M E Q2 CR=6 R1 P1 Q1 CR=5 Notes 12

  11. Overview • Logical Clocks • Physical Clocks • basic properties • synchronization scheme • synchronization with clock server • probabilistic synchronization Notes 12

  12. Logical Clock • Ci =logical clock (counter) at process i • C[b]= reading of Cj 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 Notes 12

  13. Clock Condition • If a  b THEN C[a] < C[b] • can be satisfied if the following conditions hold: If a and b are events in process i and a comes before b, then Ci[a] < Ci[b] If a is the sending of a message by process i and b is the receipt of that message by process j, then Ci[a] <Cj[b] C1 C2 Notes 12

  14. Process Process Process P Q R P4 Q7 R4 CQ=10 10>7 by C2 Q6 R3 P3 Q5 Q4 Q3 R2 P2 CR=7 T I M E Q2 7>5 by C1 R1 P1 Q1 CR=5 Notes 12

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

  16. Note: Ci[a] <Cj[b] a  b Note: a,b concurrent  Ci[a] = Cj[b] Note: Ci[a] =Cj[b]  a,b concurrent Notes 12

  17. 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 ] Notes 12

  18. 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) Ci[a] < Cj[b] or (2) Ci[a] = Cj[b] and i < j • “” not unique Notes 12

  19. Anomalous behavior server C=100 C=50 Reserve a Telephone Reserve a seat call seat Client A Client B 1 3 2 Notes 12

  20. C= 9am C= 9am Anomalous behavior server C=100 C=50 Reserve a Telephone Reserve a seat call seat Client A Client B 1 3 2 Notes 12

  21. 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 Notes 12

  22. Physical Clocks Ci(t) = clock reading at process i at physical time t Ci(t) time=t Notes 12

  23. Assume Ci(t) is a continuous, differentiable function except when clock is reset (message arrived) Ci(t) Ci+(x) Ci-(x)=lim Ci(x - ||) 0 Ci+(x)=lim Ci(x + ||) 0 Ci-(x) time=t x Notes 12

  24. How do we enforce clock condition? If a  b then C(a) < C(b) Notes 12

  25. IR1 Logical clocks IR1’ Each process i increments Ci between any two successive events For each process i, if i does not receive a message at time t, then Ci is differentiable at t and dCi(t) dt > 0 a T I M E b process i Notes 12

  26. IR2 Logical clocks • Let a be event “process i sends message m to j” • m contains timestamp Tm = Ci[a] • when m arrives at j (1) IF Tm > Cj THEN Cj Tm (2) event “arrival of m” takes place Notes 12

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

  28. IF Tm + m>Cj-(t’)THEN Cj+ Tm+ m • t’ m T I M E m • t i j Notes 12

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

  30. dCi(t) dt - 1 < k y+1+k Ci For typical crystal controlled clocks, k < 10-6 k y+1 k y+1-k y time x x+1 Notes 12

  31. PC2 Clock synchronization for all i,j: | Ci(t) - Cj(t) | <  Notes 12

  32. PC2 can be satisfied if a message is sent on every link at least every  seconds diameter = d • • • • • • d=4 (not 3) Notes 12

  33. let m be the transmission time of message m m= minimum delay + unpredictable delay m = m + Zm Assume constant  such that for all m: Zm   Assume that for all m: m =  t2 • maximum transit time: + shortest transit time:  • t1 Notes 12

  34. Theorem PC2 holds for all t > to + d with   d(2k + ) (assuming  +  <<  ). Notes 12

  35. Argument for d=1 slow fast s f Worst case scenario: t1: m leaves f for s withTm = Cf(t1) t2: m arrives at s:Cs(t2) = Cf(t1) +  Cf(t2) - Cs(t2) is as large as possible,  t2+ : no communication for  sec; f is as fast as possible, s as slow as possible. Just before communication at t2+  clocks are as far apart as possible,  Notes 12

  36. clock reading k f   k  s t2 + time t2 So,  = 2 +  Now just need largest possible  Notes 12

  37. Cs(t2) t2 + • Cf(t1) t1 s f Cf(t2) = Cf(t1) + (1+k)(+) Cs(t2) = Cf(t1) +   = (1+k)( + ) -  max  = k(+) +  Notes 12

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

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

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

  41. t2 = (++)(1+) + t1 max trans + t1 at remote clock  t1 on my clock my node other Notes 12

  42. Do physical clocks rule out anomalous behavior? No anomalous behavior if Cs(t2)>Cf (t1) Cs(t2) min message out of system Cs(t1)=Cf (t1) -  Cf (t1) s slow clock f fast clock Notes 12

  43. No anomalous behavior if Cs(t2)>Cf (t1) Worst possible scenario: • Smallest possible transmission time min • Cs, Cf as far apart as possible Cs(t1) = Cf (t1) -  • Smallest possible Cs(t2) = Cf (t1) -  + S.P.increment = Cf(t1) -  + min(1-k) Notes 12

  44. No A.B. if Cs(t2) > Cf(t1) I.e., if Cf(t1) -  + min(1-k) > Cf(t1)  1 - k min > Notes 12

  45. 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: Cj+(t’)Tm+min whenever timing message arrives • If max. transmission time from central clock is < + then e = 2kt + (1 + k) (Why? ) Notes 12

  46. Using a clock service - analysis 0  error at synchronization time, node j  T++ Cj=T+ slowest clock message T+ Cj=T+ fastest clock message time T server node j Notes 12

  47. Using a clock service - analysis - cont. fast clock server time t possible difference telapsed time Node that got fastest message 0  slow clock Node that got slowest message time  Notes 12

  48. Why can period bet+ ? slow m+ t +  t +t fast m t j server Notes 12

  49. k(t+) server time  telapsed time t kt Node that got fastest message 0 worst case for clock reset  Node that got slowest time   Notes 12

  50. k(t+) server time  t kt Node that got fastest message 0 worst case for clock reset  Node that got slowest time |Cs(t) - Cj(t)|  kt + x |Ck(t) - Cj(t)|  2kt + x(1+k) Notes 12

More Related