UNIT7 Clock Synchronization PDF
UNIT7 Clock Synchronization PDF
UNIT7 Clock Synchronization PDF
Brian Nielsen
[email protected]
But I
still dont
understand
women
Physical Time
1. The sun
2. An Atom
UTC
International standard for timekeeping.
Based on atomic time.
Synchronizes with astronomical time using leap
seconds.
UTC signals are synchronized and broadcast
regularly from land-based radio stations and
satellites.
Computers with receivers attached can
synchronize their clocks with these timing
signals.
UTC broadcasts
UTC-signals come from radio broadcasting stations
or from satellites (GEOS, GPS) with an accuracy of:
1.0 msec (broadcasting station)
1.0 sec (GPS)
>> 1ms (UTC available via phone line)
Receivers are available commercialle and can be
connected to PCs
Computer Clocks
Each node in the DS contains its own physical clock !
Physical clocks are HW devices that count oscillations of
a quartz.
After a specified number of oscillations, the clock
increments a register, thereby adding one clock-tick to a
counter the represents the passing of time: Hi(t).
Resolution: Period between clock updates
The OS maintains SW Clock by scaling and adding an
offset to it:
Ci(t) = Hi(t) + .
C2
C3
C4
Clock Skew
Network
Clock Synchronization
Clock makers specify a maximum drift rate (rho)
By definition
1- dC/dt 1+
where C(t) is the clocks time as a function of the real time
Internal/External Synchronization
External synchronization
Internal synchronization
Note that clocks that are internally synchronized are not necessarily externally
synchronized. i.e., even though they agree with each other, the drift collectively from the
external source of time.
Synchronization in a
synchronous system
We have:
known upper (max) and lower (min) bound for
communication delay,
known maximum clock drift,
known maximum time taken for each computational step.
We synchronize by:
time server sends its local time t to a client,
and the client sets its local clock to t+(max+min)/2.
Synchronization in an
asynchronous system
Christians algorithm.
The Berkeley algorithm.
Network time protocol (NTP).
Cristians Algorithm
A node is a time server TS (presumably
with access to UTC). How can the other
nodes be synced?
Periodically, at least every /2 seconds,
each machine sends a message to the TS
asking for the current time and the TS
responds.
Christians algorithm
Client p sends request (mr) to time server S,
S inserts its time t immediately before reply (mt) is returned,
p measures how long it takes (Tround=T1 - T0) from mr is send to mt
is received
p sets its local clock to t+Tround/2.
t
t
Cristians Algorithm
Monotonicity:
Jumps in time backward not permitted
Jumps forward may be confusing
Receiver adjusts : Ci(t) = Hi(t) + .
Improve precision
by taking several measurements and taking the
smallest round trip
or use an average after throwing out the large values
a)
b)
c)
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
An example synchronization
subnet in an NTP implementation
1
Stratum 1 servers
directly coupled UTC time
Reconfiguration
Distributed Systems
NTP-Modes
Multicast (for quick LANs, low accuracy)
- server sends its actual time to its leaves in the
LAN
Procedure-call (medium accuracy)
- server responds to requests with its actual
timestamp
- like Cristians algorithm
Symmetric mode (high accuracy)
- used to synchronize between the time servers
Remark: In all cases the UDP-transportation protocol is used, i.e. messages can get lost!
Messages exchanged
between a pair of NTP peers
Server B
Ti-2
Ti-1
Time
m'
Time
Server A
Ti- 3
oi=(Ti-2-Ti-3+Ti-1-Ti)/2
Ti
di=Ti-2-Ti-3+Ti-Ti-1
Theoretical Foundations
Inherent characterstic of a distributed system:
Absence of a global clock:
Absence of 100% accurately synchronized clocks
Impact: Due to the absence of global clock, it is
difficult to reason about the temporal order of
events in distributed system, e.g. scheduling
events is more difficult.
Logical Clocks in a DS
What is important is usually not when things
happened but in what order they happened so the
integer counter works well in a centralized
system.
However, in a DS, each system has its own
logical clock, and you can run into problems if one
clock gets ahead of others. (like with physical
clocks)
RELIABLE WAY OF ORDERING EVENTS IS
REQUIRED
We need a rule to synchronize the logical clocks.
Event Ordering
System Model
Sending a message;
Receiving a message;
Performing an internal computation that alters its state si;
Concurrent Events
Two distinct events a and b are
concurrent (a||b) if not (ab or ba).
We cannot say whether one event
happened-before
For any two events a and b in a distributed
system, either ab, ba or a||b.
Example
p1
a
m1
Physical
time
p2
c
m2
p3
e
a b and a c and b f
bf and ef Does e b?
Logical Clocks
There is a clock Ci at each process pi
The clock Ci can be thought of as a function
that assigns a number Ci(a) to any event a,
called the timestamp of event a, at pi
These clocks can be implemented by
counters and have no relation to physical
time.
Implementation Rules
[IR1] Before Pi timestamps an event
Ci:= Ci+1
[IR2a] Pi sends m: [IR1] and piggy-back
timestamp t=Ci: m=<m, t>
[IR2b] Pj receives m=<m, t>:
Cj:=max(Cj, t), followed by [IR1]
p2
p3
m1
3
Physical
time
m2
(2,1)
(4,2)
(3,2)
(1,3)
(5,3)
a b
e
f
Vector Clocks
Lamport: e f implies C(e) < C(f)
Vector clocks: e f iff C(e) < C(f)
vector timestamps: Each node maintains
an array of N counters
Vi[i] is the local clock for process pi
In general, Vi[j] is the latest info the node
has on what pjs local clock is.
Implementation Rules
[VC1] Initially Vi[j]=0 for i,j = 1N
[VC2] Before Pi timestamps an event:
Vi[i] := Vi [i] +1
[VC3] Pi sends m: piggy-back timestamp t=Vi:
m=<m, t>
[VC4] Pj receives m=<m, t>
Vi[i] :=max(Vi[i] , ti[i])
p2
p3
m1
(2,1,0)
(2,2,0)
Physical
time
m2
(0,0,1)
(2,2,2)
a
b
END