Documente Academic
Documente Profesional
Documente Cultură
Introduction
Several challenges have to be handled in designing and building
distributed systems
Heterogeneity
Transparency
Scalability
Fault Tolerance
Openness
Security
Concurrency
No Global Clock
Introduction
A common
Resource
Q. WHICH REQUEST
WAS MADE FIRST?
Solution
Request
A
Node
A
Request B
Node B
A Distributed
System
Global
Synchronizatio
n?
Introduction (contd)
Q. WHICH REQUEST
WAS MADE FIRST?
A common
Resource
request A
10:00 AM
Node A
A Distributed
System
Individual
Clocks?
request B
10:02 AM
Node B
Are individual
clocks
accurate,
precise?
One clock
might run
faster/slow
er?
Introduction (contd)
The concept of time is fundamental to our way of thinking. It is
derived from the more basic concept of the order in which events
occur.
The concept of the temporal ordering of events pervades our thinking
about systems.
For example, in an airline reservation system we specify that a
request for a reservation should be granted if it is made before the
flight is filled.
In a distributed system, it is
sometimes impossible to say that one
of two events occurred first.
Introduction (contd)
Synchronization of Processes
Clock Synchronization
Algorithms
Introduction
Process 1
Process 2
.
.
.
.
Client/Server
Cooperate
Synchronization
Compete
Process N
Shared
resource
Clock Synchronization
a timer mechanism
(computer clock)
Astronomical Time
Defined in terms of the rotation of the Earth on its axis
And its rotation about the Sun.
Atomic Time
Based on atom Caesium- 133 (Cs133)
1second
Clock Drift
Let
dC
dt
1+
Perfect clock
dC = 1
dt
dC
dt
Clock
time
dC
dt
Real time
Fig. 1. Slow, perfect and fast clocks
Clock 1
Local Memory
CPU1
Clock 2
Local Memory
CPU2
Clock 3
Local Memory
CPU3
Communication Network
External Synchronization
We need an authoritative, external source of time
(UTC). Consider a source, S, of UTC time.
The clocks Ci are accurate to within the bound D if:
S(t) Ci(t)
For i = 1, 2, .. N
and for all real times in I
(I is the interval of real time)
Internal Synchronization
We need a consistent view of time across all nodes
in the distributed system.
The clocks Ci are accurate to within the bound D if:
Ci(t) Cj(t)
For i, j = 1, 2, .. N
and for all real times in I
(I is the interval of real time)
C1(t)
Clock 2
C2(t)
Prepare message;
Transmit message;
Minimum time
predictable
Receive reply.
Maximum time
unpredictable
Quiz 1
Consider a source, S, of UTC time (authoritative, external source of time) and three
other clocks C1, C2, and C3 that constitute a distributed system. The clock times are
given in Fig. Q1.
Confirm whether the clocks are both internally and externally synchronized, giving
statements of the basic rules being applied. Assume the bound for synchronization
is 0.005 seconds.
S:
16:34:23.480
C1:
16:34:23.430
C2:
16:34:23.725
C3:
16:34:23.728
Fig. Q1
Centralized Algorithms
Distributed Algorithms
Centralized Algorithms
Key features:
One node has a real-time receiver, time server node.
Clock time regarded as correct, reference time
Keep the clocks of all other nodes synchronized
with the reference time
Clock 1
Clock 2
Clock 3 (R)
Clock 4
Clock 3 (R)
time = ?
time = T
T1
T + (T1 T0)/2
Time
Server
(T)
Drawbacks
(a). Single point of failure the time server;
(b). Scalability problem single time server.
Distributed Algorithms
Key features:
Node N broadcasts its local clock time;
Broadcasts dont happen at same time, because clocks
of different nodes run at different rates
The node (N) collects broadcasts from other nodes,
recording the time when received (according to its own
clock time)
Node N then estimates the clock skew of its own with the rest
Compute a fault-tolerant average
Summary
Clock synchronization is important:
Internal synchronization;
External synchronization
Synchronization Algorithms:
Centralized;
Distributed
ntp.kenic.or.ke
NTP Architecture
Stratum 1
1
Stratum 2
2
Stratum 3
Event Ordering
We can not synchronize clocks perfectly in a distributed
system;
Attempting to do so is expensive & non-trivial;
Thus, we can not use physical time to find out the order
of any arbitrary pair of events occurring within a
distributed system
Happened-Before Relation
e11 e23
Physical
Time
e13
e12
e11
e10
Process P1
e24
e23
e22
e21
e20
Process P2
e32
e31
Happened
-before
Concurrent
e30
Process P3
e10 e21
Happened-Before Events
To determine that an event a happened-before event b,
we need:
either a common clock;
or a set of perfectly synchronized physical clocks.
None of which is available
in a distributed system
Process Pi
Clock Ci
event
a
Timestamp
Ci(a)
Clock Condition
The timestamps assigned to the events by the system
of logical clocks must satisfy the following clock
condition:
Implementation
To satisfy the clock condition, the following conditions
should hold:
C1:
C2:
Implementation (Contd)
C3:
Rule IR2:
Time
e08
C1 = 7
e07
e14 C2 = 6
C1 = 6
e06
e13
C1 = 5
e05
e04
C1 = 4
C1 = 3
C1 = 2
C1 = 1
C1 = 0
Tm = 6
Tm = 4
e03
e02
e01
Process P1
C2 = 3 = 5
(since 3 < Tm =
4)
e12
C2 = 2
e11
C2 = 1
Process P2
C2 = 0
Summary: Problem
Assume two nonfaulty clocks (a slow clock and a fast clock).
Further, assume that t is the time elapsed after the two clocks were
synchronized.
(i). Determine the maximum deviation between the time value of the
two clocks at time t after they were synchronized.
(ii). To guarantee that no two clocks in a set of clocks ever differ by
more than , the clocks in the set must be resynchronized
periodically. Determine the interval between two synchronizations.