GB Final Unit3 Clock-Synchronization
GB Final Unit3 Clock-Synchronization
in a Distributed System
1
Topics
• Introduction
• Clock synchronization
• Physical Clock
• Logical clocks
• Election algorithms
Introduction
• Aim is to determine how processes can synchronize.
• It is important that :-
• Multiple processes do not simultaneously access
a shared resource, rather they should cooperate.
• Sometimes , multiple processes need to agree on
the ordering of events.
• Synchronization in distributed systems is difficult
3
Lack of Global time in DS
• It is impossible to guarantee that physical clocks
run at the same frequency
• Lack of global time, can cause problems
• Example: UNIX make
Edit output.c at a client
output.o is at a server (compile at server)
Client machine clock can be lagging behind the
server machine clock
4
Lack of Global Time – Example
When each machine has its own clock, an event that occurred after
another event may nevertheless be assigned an earlier time.
Physical Clock….
• Computers have a CMOS clock circuit for keeping track of time.
• Instead of clock , timer is a better word
• A computer timer is a precisely machined quartz crystal, oscillating at a
well
defined frequency
• Associated with each crystal are two registers:
– A Counter , Holding Register
7
Physical Clock
The problems:
1. Crystals cannot be tuned perfectly. Temperature and other external
factors can also influence their frequency.
Therefore, two computers will never agree on time .
The phenomenon of clocks ticking at different rates, creating a gap
in the perceived time is known as clock drift
2. Two crystals are never identical.
When a system has n computers , all n crystals will run at slightly
different rates, causing the (software)clocks to get out of sync and
give different values when read out. This difference in time values is
called clock skew.
Therefore, the computer clocks on different processors of the
distributed system show different time.
8
Need for Precise Time
• Social networking services
• Stock market buy and sell orders
• Secure document timestamps (with cryptographic certification)
• Aviation traffic control and position reporting
• Radio and TV programming launch and monitoring
• Intruder detection, location and reporting
• Multimedia synchronization for real-time teleconferencing
• Interactive simulation event synchronization and ordering
• Network monitoring, measurement and control
• Early detection of failing network infrastructure devices and air
conditioning equipment
• Differentiated services traffic engineering
• Distributed network gaming and training 9
Clock Synchronization
Cristian Berkley
Passive Time Server…
There is one time server node which is used as a reference time, in
centralized algorithms.
14
Cristian’s Algorithm….
Cristian’s Algorithm
To improve the accuracy, :-
– Any measurements in which (t1-t0) exceeds some
threshold is discarded.
Assuming they are due to network congestion and
thus are unreliable.
- The estimates derived from remaining probes are
then averaged to get a better value.
NTP Server
Secondary Server
NTP Server NTP Server
Tertiary Server 22
Network Time Protocol….
24
Summary
Summary
29
Logical Clock…
● Assumes no central time source –
● Logical clock assigns timestamp(sequence number) to
events for sequencing them in the order agreed upon
by all processes.
● The timestamp is the agreed upon relation amongst
the events.
● This timestamp style event ordering is called termed
as logical clock .
30
Logical Clock
If a and b are 2 events, a b, would mean that a “happened before” b
1. If a is the event corresponding to the sending of message m in one process,
and
b is the event corresponding to receiving the same message m in another
process.
C1(a) P1
t
t
C2(a) P2
1. If a and b are events internal in the same process
a b
C1(a) C2(b)
One can assign logical time by assigning a time value to the events a and b.
If a b, then clock(a)< clock(b) as time cannot run backwards.This
monotonicity
property is called the clock consistency condition .
31
Lamport’s Timestamps
• To synchronize logical clocks, Lamport defined a relation called happens - before
.
Situations:
1. If a and b are events in the same process, and a comes before b, then a → b.
1. HBR is Transitive:
If a → b and b → c then a → c.
Note: Two distinct events a and b happens in different process that do not
exchange messages then these events are said to be concurrent
a -/->b and b -/->a
33
Implementation of Logical clocks
Conditions for correct functioning:
• C1: If a and b are two events in the same process, and a→ b,
then we demand that C(a) < C(b).
• C2: If a corresponds to sending a message m, and b
corresponds to receiving that message, then also C(a)<C(b).
• C3: A clock C associated with the process P must always go
forward, never backwards.
Three processes, 3 machines, each with its own clock. The clocks run at different
rates.
Clock has ticked 6 times in P0 , 8 times in process 1 and 10 times in process 2.
Lamport’s Logical Clocks
38
• Lamports solution follows from the happens-before
relation.
Since C left at 60, it must arrive at 61 or later.
• Therefore, each message carries the sending time
according to the senders clock.
P2
P3
P2
P3
• Clock synchronization
– Rely on a time-stamped network messages
– Estimate delay for message transmission
– Can synchronize to UTC or to local source
53