Professional Documents
Culture Documents
Time Synchronization ds14
Time Synchronization ds14
CS542: Topics
Topics in
in
Distributed
Distributed Systems
Systems
Diganta Goswami
Concept
Concept of
of Time
Time in
in Distributed
Distributed Systems
Systems
Time
Time in
in DS
DS
– Clock skew
» The instantaneous difference between the
readings of any two clocks
• Max drift rate between two clocks with similar MDR is 2 * MDR
Max-Synch-Interval =
(MaxAcceptableSkew—CurrentSkew) / (MDR * 2)
(i.e., time = distance/speed)
Clock
Clock synchronization
synchronization
– If the UTC time is t and the process i’s time is Ci(t) then
ideally we would like to have Ci(t) = t, or dC/dt = 1.
C i (t ) C j (t ) D
for i, j=1,2,...,N and for all real times t.
Clocks Ci are internally accurate within the bound D.
• Asynchronous system
UTC
mr
mt
p Time server,S
Cristian’s
Cristian’s Algorithm
Algorithm (Accuracy)
(Accuracy)
• Assumption
• Cristian stated that the message that came back the fastest
can be taken to be the most accurate since it presumably
encountered the least traffic.
Cristian’s
Cristian’s Algorithm
Algorithm (Discussion)
(Discussion)
• The time daemon asks all the other machines for their clock values
• The machines answer
• The time daemon tells everyone how to adjust their clock
Averaging
Averaging Algorithms
Algorithms
• Both Cristian’s and Berkeley’s methods are highly
centralized, with the usual disadvantages - single point
of failure, congestion around the server, … etc.
• Some algorithms:
Secondary servers,
synched by the 2 2 2
primary server Strata 3,
synched by the
3 3 3 3 3 secondary
3
servers
Messages
Messages exchanged
exchanged between
between aa pair
pair of
of NTP
NTPpeers
peers
• Multicast
• Procedure-call mode
• Symmetric mode
m m'
Time
Server A Ti- 3 Ti
Each message bears timestamps of recent message events: the local time
when the previous NTP message was sent and received, and the local time
when the current message was transmitted.
Theoretical
Theoretical Base
Base for
for
NTP
NTP
Server B Ti-2 Ti-1
Time
m m'
Time
Server A Ti- 3 Ti
T i- 2 =T i- 3 + t + o
• t and t’: actual transmission times T i =T i- 1 + t '- o
for m and m’(unknown)
• o: true offset of clock at B This leads to
relative to clock at A d i =t + t ' =T i- 2 - T i- 3 + T i - T i- 1
• oi: estimate of actual offset
between the two clocks o =oi + (t '- t) / 2, where
• di: estimate of accuracy of oi ;
total transmission times for m
oi =(T i- 2 - T i- 3 + T i- 1 - T i ) / 2.
and m’; di=t+t’ It can then be shown that
oi - d i / 2 £o £ oi + d i / 2.
Theoretical
Theoretical Base
Base for
for
NTP
NTP
Server B Ti-2 Ti-1
Time
m m'
Time
Server A Ti- 3 Ti
• NTP servers apply a data filtering algorithm to successive
pairs < oi , di> which estimates the offset o and calculates
the quality of this estimate as a statistical quantity called the
filter dispersion.
• Calculation …
Is
Is itit enough
enough to
to synchronize
synchronize physical
physical clocks?
clocks?
p1
a b m1
p2 Physical
c d time
m2
p3
e f
Lamport
Lamport Timestamps
Timestamps
1 2
p1
a b m1
3 4
p2 Physical
c d time
m2
1 5
p3
e f
Find
Find the
the Mistake:
Mistake: Lamport
Lamport Logical
Logical Time
Time
Physical Time
p 1 0 1 2
3
4
1
3 4
p 2 0 2 2
3 6
p 3 0 3
4
5 6 8
4 7
p 4 0 5 6 7
n Clock Value
timestamp
Message
Corrected
Corrected Example:
Example: Lamport
Lamport Logical
Logical Time
Time
Physical Time
p 1 0 1 2
7
8
1
3 8
p 2 0 2 2
3 6
p 3 0 3
4
5 9 10
4 7
p 4 0 5 6 7
3 4
p2 Physical
c d time
m2
1 5
p3
e f
(1,0,0) (2,0,0)
p1
a b m1
(2,1,0) (2,2,0)
Physical
p2
time
c d m2
(0,0,1) (2,2,2)
p3
e f
Example:
Example: Vector
Vector Timestamps
Timestamps
Physical Time
Physical Time
P1 0 1 2
1
P2 0
2 5 6
4
P3 0 3 4
Physical Time
P2 0,0,0 2,1,2
2,2,2
(2,0,0)
(2,0,2)
P3 0,0,0
2,0,1 2,0,2
– Cristian’s algorithm
– Berkeley algorithm
– NTP