CS603 Clock Synchronization February 4, 2002
What is Clock Synchronization? All nodes agree on time What do we mean by time? –Monotonic –Any observation increases –When sun is overhead, time is “noon” What do we mean by agree? –Clocks on different nodes give same reading when time requested simultaneously –Can’t distinguish readings from above definition
Event-based definition (Lamport ’78) Define partial order of processes A B: A “happened before” B: Smallest relation such that: 1.If A and B in same process and A occurs first, A B 2.If A is sending a message and B is receipt of a message, A B 3.If A B and B C, then A C Clock: C(x) is time x occurs: –C(x) = C i (x) where x running on node i. –Clocks correct if a,b: a b C(a) < C(b)
Event-based clocks: Example PQR p1p1 q1q1 p3p3 p2p2 r1r1 q2q2 q3q3 q4q4 q5q5 q6q6 p4p4 r2r2 r3r3 r4r4
Time in a Distributed System PQR p1p1 q1q1 p3p3 p2p2 r1r1 q2q2 q3q3 q4q4 q5q5 q6q6 p4p4 r2r2 r3r3
Event-based definition (Lamport ’78) Define partial order of processes A B: A “happened before” B: Smallest relation such that: 1.If A and B in same process and A occurs first, A B 2.If A is sending a message and B is receipt of a message, A B 3.If A B and B C, then A C
Anomalous Events PQR p1p1 q1q1 p3p3 p2p2 r1r1 q2q2 q3q3 q4q4 q5q5 q6q6 p4p4 r2r2 r3r3 r4r4
Event-based definition (Lamport ’78) Define partial order of processes A B: A “happened before” B: Smallest relation such that: 1.If A and B in same process and A occurs first, A B 2.If A is sending a message and B is receipt of a message, A B 3.If A B and B C, then A C Clock: C(x) is time x occurs: –C(x) = C i (x) where x running on node i. –Clocks correct if a,b: a b C(a) < C(b)
Event-based clocks PQR p1p1 q1q1 p3p3 p2p2 r1r1 q2q2 q3q3 q4q4 q5q5 q6q6 p4p4 r2r2 r3r3
Lamport Clock Implementation Node i Increments C i between any two successive events If event a is sending of a message m from i to j, –m contains timestamp T m = Ci(a) –Upon receiving m, set C j ≥ current C j and > T m Can now define total ordering. a b iff: –C i (a) < C j (b) –C i (a) = C j (b) and P i < P j
What if we want “wall clock” time? C i must run at correct rate: – κ << 1 such that | dC i (t)/dt – 1 | < κ Synchronized: – small ε such that i,j: | C i (t) – C j (t) | < ε Assume transmission time between μ and μ+ξ Algorithm: Upon receiving message m, set C j (t) = max(C j (t), T m +μ) Theorem: Assume every τ seconds a message with unpredictable delay ξ is sent over every arc. Then t ≥ t 0 + τd, ε ≈ d(2κτ + ξ)
Is this it? What if we don’t know maximum delay ξ? What if a clock goes “bad” –Runs much too fast/slow –Gives wrong answers What about network faults? Can we do better in practice? –Probabilistic algorithms