CS3551 Unit 2-Part1
CS3551 Unit 2-Part1
STATE
Part 1 : LOGICAL TIME
i. Physical Clock Synchronization: NTP
ii. Logical Time
iii. A Framework for a System of Logical Clocks
iv. Scalar Time
v. Vector Time
Motivation
In centralized systems, there is only single clock. A process gets
the time by simply issuing a system call to the kernel.
In distributed systems, there is no global clock or common
memory. Each processor has its own internal clock and its own
notion of time.
These clocks can easily drift seconds per day, accumulating
significant errors over time.
Also, because different clocks tick at different rates, they may
not remain always synchronized although they might be
synchronized when they start.
This clearly poses serious problems to applications that
depend on a synchronized notion of time.
Clock Inaccuracies
Physical clocks are synchronized to an accurate real-time
standard like UTC (Universal Coordinated Time).
However, due to the clock inaccuracy discussed above, a timer
(clock) is said to be working within its specification if (where
constant ρ is the maximum skew rate specified by the
manufacturer.)
d
1−ρ≤ ≤1+ρ
C
dt
(1)
Figure 3.5 illustrates the behavior of fast, slow, and perfect
clocks with respect to UTC.
Fast Clock
dC/dt >
1
Perfect Clock
Clock time, C
dC/dt = 1
Slow Clock
dC/dt < 1
UTC, t
Figure 3.5: The behavior of fast, slow, and perfect clocks with
respect to UTC.
T1 T2
B
A
T3
T4
Let a = T 1 − T 3 and b = T 2 −
. network delay difference from A to B and from B to A,
T 4the
If
called differential delay, is small, the clock offset θ and
roundtrip delay δ of B relative to A at time T4 are
approximately given by the following.
a+
θ , δ= a−b
b2
= (2)
Each NTP message includes the latest three timestamps T1, T2
and T3, while T4 is determined upon arrival.
Thus, both peers A and B can independently calculate delay and
offset using a single bidirectional message stream as shown in
Figure 3.7.
T i-3 Ti
Server B
The offset between A’s clock and B’s clock is O. If A’s local
clock time is
A(t ) and B’s local clock time is B(t ), we have
A(t ) = B(t ) + (3
O )
The
n, Ti − 2 = Ti − 3 + t + O (4
Ti = Ti − 1 − O + t
′ )
(5
Assuming t = t , the offset Oi can be
′
)
estimated as:
(6
Oi = (T i − 2 − T i − 3 + T i )
− 1 − T i )/2
Di = (T i − T i − 3) − (T i − 1 − T i (7
The round-trip delay )is estimated as: )
−2
The eight of
The value most recent
Oi that pairs of (O
corresponds toi ,minimum
Di ) are D i s chosen to
i
retained. Logical
A. Kshemkalyani and M. Singhal (Distributed CUP 14 / 67
Distributed Computing: Principles, Algorithms, and
Systems
Introductio
n
Introductio
n
Logical Time:
Implementing Logical
Clocks
local view of the logical global time. Typically, lci is a part of gci .
The protocol ensures that a process’s logical clock, and thus its view of
the global time, is managed consistently. The protocol consists of the
following two rules:
R1: This rule governs how the local logical clock is updated by a
process when it executes an event.
R2: This rule governs how a process updates its global logical
clock to update its view of the global time and global
progress.
Systems of logical clocks differ in their representation of logical time
and also in the protocol to update the logical clocks.
Scalar
Time
Scalar
Time
Scalar Time
Evolution of scalar
time:
1 2 3 8 9
p
1
9
2
1 4 5 7 11
p
2 3 10
4
1 b
p
3
5 6 7
Basic
Properties
Consistency Property
Scalar clocks satisfy the monotonicity and hence the
consistency property: for two events ei and ej , ei → ej
=⇒ C(ei ) < C(ej ).
Total Ordering
Scalar clocks can be used to totally order events in a distributed
system.
The main problem in totally ordering events is that two or more
events at different processes may have identical timestamp.
For example in Figure 3.1, the third event of process P1 and the second
event of process P2 have identical scalar timestamp.
Total
Ordering
A tie-breaking mechanism is needed to order such events. A tie is
broken as follows:
Process identifiers are linearly ordered and tie among events
with identical scalar timestamp is broken on the basis of their
process identifiers.
The lower the process identifier in the ranking, the higher the
priority.
Properties
...
Event counting
If the increment value d is always 1, the scalar time has the
following interesting property: if event e has a timestamp h,
then h-1 represents the minimum logical duration, counted in
units of events, required before producing the event e;
We call it the height of the event e.
In other words, h-1 events have been produced sequentially
before the event e
regardless of the processes that produced these events.
For example, in Figure 3.1, five events precede event b on the
longest causal path ending at b.
Properties
...
No Strong Consistency
The system of scalar clocks is not strongly consistent; that is, for
two events
ei and ej , C(ei ) < C(ej ) =/⇒ ei → ej .
For example, in Figure 3.1, the third event of process P1 has
smaller scalar timestamp than the third event of process P2.
However, the former did not happen before the latter.
The reason that scalar clocks are not strongly consistent is that
the logical local clock and logical global clock of a process are
squashed into one, resulting in the loss causal dependency
information among events at different processes.
Vector Time
Vector
Time
Process pi uses the following two rules R1 and R2 to update its clock:
R1: Before executing an event, process pi updates its local
logical time as follows:
vt i [i ] := vt i [i ] + d
(d > 0)
R2: Each message m is piggybacked with the vector clock vt of the
sender process at sending time. On the receipt of such a message
(m,vt), process pi executes the following sequence of actions:
◮ Update its global logical time as follows:
1 ≤ k ≤ n : vt i [k ] := max (vt i [k ], vt [k ])
◮ Execute R1.
◮ Deliver the message m.
Vector Time
Vector Time
An Example of Vector
Clocks
1 2 3 4 5
0 0 0 3 3
0 0 0 4 4
p
1 5
2 2 3
0 3 4
0 0 2 2 2 4 5
1 2 3 4 6
0 0 0 0 4
p
2 5
2
3 5
0 4
0 2 2 2
0 3 3 3
1 2 3 4
p
3
Vector Time
Comparing Vector
Timestamps
The following relations are defined to compare two vector
timestamps, vh
and vk :
vh = vk ⇔ ∀x : vh[x ] = vk [x ]
vh ≤ vk ⇔ ∀x : vh[x ] ≤ vk [x ]
vh < vk ⇔ vh ≤ vk and ∃x : vh[x ] <
vk [x ]
vh ǁ vk ⇔ ¬(vh < vk ) ∧ ¬(vk < vh)
If the process at which an event occurred is known, the test to
compare two timestamps can be simplified as follows: If events x
and y respectively occurred at processes pi and pj and are assigned
timestamps vh and vk, respectively, then
x→y ⇔ vh[i ] ≤ vk [i ]
xǁy ⇔ vh[i ] > vk [i ] ∧ vh[j ]
< vk [j ]
A. Kshemkalyani and M. Singhal (Distributed Logical CUP 31 / 67
Distributed Computing: Principles, Algorithms, and
Systems
Vector Time
Properties of Vector
Time
Isomorphism
If events in a distributed system are timestamped using a
system of vector clocks, we have the following property.
If two events x and y have timestamps vh and vk, respectively,
then
x→y ⇔
vh < vk x ǁ y ⇔
vh ǁ vk .
Vector
Time
Strong Consistency
The system of vector clocks is strongly consistent; thus, by
examining the vector timestamp of two events, we can
determine if the events are causally related.
However, Charron-Bost showed that the dimension of vector clocks
cannot be less than n, the total number of processes in the
distributed computation, for this property to hold.
Event Counting
If d=1 (in rule R1), then the i th component of vector clock at
process pi , vti [i ], denotes the number of events that have
occurred at pi until that instant.
So, if an event e has timestamp vh, vh[j] denotes the number
of events executed by process pj that causally precede e.
Clearly, Σ vh[j ] − 1 represents the total number of events
that causally precede e in the distributed computation.
Time