210 likes | 233 Views
Clock Synchronization. Problem. 5:33. 5:57. 5:20. 6:01. 4:53. Why is this hard?. Hard to set the clocks simultaneously Hardware clocks have a small drift rate Network messages have random delay This delay is unbounded Various types of faults are possible: Process failure
E N D
Problem 5:33 5:57 5:20 6:01 4:53
Why is this hard? • Hard to set the clocks simultaneously • Hardware clocks have a small drift rate • Network messages have random delay • This delay is unbounded • Various types of faults are possible: • Process failure • Communication failure
Making it Tractable • Clocks have higher resolution than needed e.g. clocks measure microseconds, but we only care about milliseconds • Drift rate ρ of clock H is known • ρ is very small • Small bounded error in measurement allowable: (1 - ρ)(t - t’) ≤ H(t) - H(t’) ≤ (1 + ρ)(t - t’) • A message is on-time if sent and delivered within maxp time units • Minimum transmission time min is known
Reading a Remote Clock Real time P Q P sends “Time = ?” to Q 5:31 5:30 5:33
Reading a Remote Clock Real time P Q P sends “Time = ?” to Q 5:31 5:30 5:33 Q receives “Time = ?” from P 5:37 Q sends “Time = 5:41” to P 5:35 5:41
Reading a Remote Clock Real time P Q P sends “Time = ?” to Q 5:31 5:30 5:33 Q receives “Time = ?” from P 5:37 Q sends “Time = 5:41” to P 5:35 5:40 P receives “Time = 5:41” from Q 5:44 5:42 5:46
Reading a Remote Clock Real time P Q P sends “Time = ?” to Q 5:31 5:30 5:33 Q receives “Time = ?” from P P measures the roundtrip delay to be 12 = 2D 5:37 Q sends “Time = 5:41” to P 5:35 5:40 P receives “Time = 5:41” from Q 5:44 5:42 5:46
What does P know about Q? • P sends “Time = ?” to Q at P(t) • P receives “Time = T” from Q at P(t’) • Roundtrip delay = P(t’) – P(t) = 2D • Drift rate ρfor P and Q • Minimum message travel time min • At P(t’), Q(t’) in interval [T + min(1 - ρ), T + 2D(1 + 2ρ) - min(1 + ρ)]
What does P know about Q? • P sends “Time = ?” to Q at P(t) = 5:30 • P receives “Time = 5:41” from Q at P(t’) = 5:42 • Roundtrip delay = 12 minutes = 2D • Drift rate ρ= 0.25 for P and Q • Minimum message travel time min = 4 minutes • At P(t’) = 5:42, Q(t’) in interval [T + min(1 - ρ), T + 2D(1 + 2ρ) - min(1 + ρ)] = ?
What does P know about Q? • P sends “Time = ?” to Q at P(t) = 5:30 • P receives “Time = 5:41” from Q at P(t’) = 5:42 • Roundtrip delay = 12 minutes = 2D • Drift rate ρ= 0.25 for P and Q • Minimum message travel time min = 4 minutes • At P(t’) = 5:42, Q(t’) in interval [5:41 + 4(1– .25), 5:41 + 12(1 + .5) - 4(1 +.25)] = [5:44, 5:54]
P’s Best Guess For Q(t’) • At P(t’), Q(t’) in interval [T + min(1 - ρ), T + 2D(1 + 2ρ) - min(1 + ρ)] • In example: [5:44, 5:54] • To P, Q(t’) could be anywhere in the interval • What should P guess that Q(t’) is equal to?
P’s Best Guess For Q(t’) • At P(t’), Q(t’) in interval [T + min(1 - ρ), T + 2D(1 + 2ρ) - min(1 + ρ)] • In example: [5:44, 5:54] • To P, Q(t’) could be anywhere in the interval • What should P guess that Q(t’) is equal to? • The midpoint! • Q(t’) = T + D(1 + 2ρ) - minρ • Q(t’) = 5:41 + 6(1 + .5) – 4(.25) = 5:49
How Precise is the Measurement? • Max error e = D(1 + 2ρ) - min • P wants to know Q(t’) within error ε • Only guaranteed if D ≤ U where U = (1 - 2ρ)(ε + min) • Then P reaches rapport with Q • Pick ε such that U > min(1+ ρ) • If D > U then need to try again
Time Service Q P4 Master Slave 5:33 5:57 P1 P3 P2 Slave 5:20 Slave 6:01 Slave 4:53
Time Service Q P4 Master Slave 5:33 5:57 All slaves try to maintain rapport with Q P1 P3 P2 Slave 5:20 Slave 6:01 Slave 4:53
How Should P Change it’s Clock? • At P(t’) = 5:42, P estimates Q(t’) = 5:49 • What should P do?
How Should P Change it’s Clock? • At P(t’) = 5:42, P estimates Q(t’) = 5:49 • What should P do? • Gradually adjust clock to eventually match Q • Let P(t) = H(t) + A(t) • H(t) is the value of the hardware clock • A(t) = mH(t) + N is an adjustment to P’s clock • Set m and N so P(t’ + x) = Q(t’ + x) • x is the amortization parameter • m = (Q(t’) - P(t’)) / x • N = P(t’) - (1 + m)×H(t’)
Master-Slave Synchronization • Slave tries up to k syncs with master • Remember: rapport means D ≤ U • Sync retry every W time units until rapport • W > 2U • At rapport, gradually adjust according to P(t) = H(t) + A(t) • Slave knows it is out of sync after k tries
Importance • Reliable Clock Synchronization required for: • Synchronous Atomic Broadcast • http://www.cs.utexas.edu/~schrum2/cs386c/sab.php • Processor Group Membership Agreement • Any distributed system needs accurate Clock Synchronization