Lecture-3 Clock Shrychronization in Distributed System
Lecture-3 Clock Shrychronization in Distributed System
in
Distributed Systems
Guide to Synchronization Lectures
• Synchronization in shared memory systems
Figure 6-9. (a) Three processes, each with its own clock.
The clocks “run” at different rates.
Lamport’s Logical Clocks (3)
Event c: P3
sends m3 to
P2 at t = 60
Event d: P2
receives m3
at t = 56
Do C(c) and
C(d) satisfy
the
conditions?
Middleware layer
Network Layer
Figure 6-12.
Figure 5.4
Time
Space
e11 e12
P1 .(1) (2)
P2 e21 e22
(1) (3)
C(e11) < C(e22) and C(e11) < C(e32) but while e11 → e22, we cannot say
e11 → e32 since there is no causal path connecting them. So, with
Lamport clocks we can guarantee that if C(a) < C(b) then
b a , but by looking at the clock values alone we cannot say
whether or not the events are causally related.
Vector Clocks – How They Work
• Each processor keeps a vector of values,
instead of a single value.
• Ci is the clock at process Pi; it has a component
for each process in the system.
– Ci[i] corresponds to Pi‘s local “time”.
– Ci[j] represents Pi‘s knowledge of the “time” at
Pj (the # of events that Pi knows have
occurred at Pj
• Each processor knows its own “time” exactly,
and updates the values of other processors’
clocks based on timestamps received in
messages.
Implementation Rules
• IR1: Clock Ci is incremented between any two
successive events in Process Pi
Ci[i]=Ci[i]+d (d>0)
• IR2: If the event a is the sending of the message m
by process Pi, then message m is assigned a
vector timestamp tm=Ci[a]; on receiving the
message m by process Pj, Cj is updated as follows:
for all k, Cj[k]=max(Cj[k],tm[k])
• On receiving a message, a process learnt about the
more recent clock value of the rest of the processes
in the system.
Review
• Physical clocks: hard to keep synchronized
• Logical clocks: can provide some notion of
relative event occurrence
• Lamport’s logical time
– happened-before relation defines causal relations
– logical clocks – don’t capture causality
– total ordering relation
– use in establishing totally ordered multicast
• Vector clocks
– Unlike Lamport clocks, vector clocks capture causality
– Have a component for each process in the system
Figure 5.5. Singhal and Shivaratri
e11 e12
P1 (2, 0, 0)
(1, 0, 0)
P2 e21 e22
(0, 1, 0) (2, 2, 0)
ts(e11) = (1, 0, 0) and ts(e32) = (0, 0, 2), which shows that the
two events are concurrent.
ts(e11) = (1, 0, 0) and ts(e22) = (2, 2, 0), which shows that
e11 e22
Causal Ordering of Messages
An Application of Vector Clocks
• Premise: Deliver a message only if
messages that causally precede it have
already been received
– i.e., if send(m1) → send(m2), then it should be
true that receive(m1) → receive(m2) at each
site.
– If messages are not related (send(m1) ||
send(m2)), delivery order is not of interest.