Synchronization-Unit 2
Synchronization-Unit 2
CLOCK SYNCHRONIZATION
Introduction
A distributed system consist of multiple concurrent processes.
It is economical to share the system resources among these
processes.
Sharing may be:
– Competitive
– Co-operative
Tape drive cannot be used simultaneously , A process must wait if
another process is using it.
Two process Client-Server relationship, for file access operation
they cooperate each other.
• Sharing requires certain rules of behavior that guarantee that
correct interaction occurs .The rules for enforcing correct
interaction are implemented in the form of synchronization
mechanism
SYNCHRONIZATION
• Synchronization-related issues
– Clock synchronization
– Event ordering
– Mutual exclusion
– Deadlock
– Election algorithms
ClOCK SYNCHRONIZATION
Every computer needs a computer clock to keep track of
computer time and calculating the time spent by a process
in execution on processor.
An application may have many processes that concurrently
running on different nodes of the system.
Every node need clock that should be synchronized.
Example, Air-line Reservation System
If the clock of these nodes are not synchronized ,it is
difficult to achieve the correct result. That problem is
called the clock synchronization problem.
Need some suitable ways to properly synchronizing the
clocks. 4
ClOCK SYNCHRONIZATION
• How Computer Clocks are Implemented?
• Three components are
i. Quartz Crystal- Oscillates at well defined
frequency
ii. Constant Register- To store the constant value
that is decided based on the frequency of
oscillation of Quartz crystal
iii. Counter Register-To keep track of oscillation of
Quartz crystal
Quarts crystal (vibrating crystal create an electrical signal with a precise frequency)
6
ClOCK SYNCHRONIZATION
• To make the computer clock function as an
ordinary clock life, the following things are done:
1 . The value in the constant register is chosen
so that 60 clock ticks occur in a second.
2. The computer clock is synchronized with real
time (external clock).
For this, two more values are stored in the system
- a fixed starting date and time
- the number of ticks.
Drifting of Clocks
A clock always runs at a constant rate because its quartz crystal oscillates at a
well- defined frequency
Due to differences in crystals ,two clock rates different from each other.
Difference is small but observable , no matter how accurately initialized.
The difference accumulated over many oscillations leads to an observable
difference in the times of the two clocks
For every 1,000,000 second there may be drift of 1 sec.(After 11.6 days of 1
second)
Therefore, Passage of time, a computer clock drifts from the real-time clock.
Hence, Computer clock must be periodically synchronized with the real-time
clock called non-faulty.
Even non-faulty clocks do not always maintain perfect time.
A clock is called non-faulty if there is bound on the amount of drift.
9
DRIFTING OF CLOCKS
Suppose that when the real time is t, the time
value of a clock p is Cp(t).
If all clocks in the world were perfectly
synchronized, we would have Cp(t) =t for all p
and all t.
That is, if C denotes the time value of a clock, in
the ideal case dc/dt should be 1.
Distributed Algorithms
16
Passive Time server Algorithm
Each node periodically sends a message (“ Time = ? “) to the time server.
Server quickly responds with a message (“Time = T”).
T is the current time of the server node.
When client node sends the request of time, its clock time is To .
When client node receives the time from server, its clock time is T1 .
Propagation time of the message from server to client node is estimated
to be (T1-To) / 2.
Therefore, Clock of client node is readjusted to T+(T1-To)/2 .
Due to unpredictable propagation time between two nodes , is not very
good estimation.
Two methods are described below to solve this problem.
17
1. This method assumes the availability of some additional information.
2. This methods assumes the no additional information, several measurements of T1-To are
The average of remaining measurements is calculated and half of this value is added to T.
Alternative way is, Measurements for which (T1-To) is minimum is considered to be most
18
Active Time Server
In this approach , Time server periodically broadcast its clock time (“ Time = T” ) .
Other nodes receive broadcast message and use the clock time in the message for
Major Faults:
Broadcast message reaches too late at the client node due to some communication
Time server periodically sends a message (Time= “?”) to all nodes in a group.
Server has prior knowledge of propagation time from client to server node.
Based on prior knowledge it first readjust the clock values of reply messages.
Time server choses a subset of all clocks values that do not differ from one another by
From scalability point of view , adding more node will put more burden on
21
Distributed Algorithms
Externally synchronized clocks are also internally synchronized
Each node’s clock is independently synchronized with real time.
All clocks of system remain mutually synchronized.
Each node is equipped with real time receiver so that each node can be
independently synchronized.
Theoretically internal synchronization of clock is not required.
In practice, due to inherent inaccuracy of real time clocks, different real time clocks
produce different time.
Internal synchronization is performed for better accuracy.
Types of internal Synchronization:
– Global averaging
– Localized Averaging 22
Global Averaging
• Each node broadcasts its local clock time in the form of a special “resync” message.
• After broadcasting the clock value , the clock process of a node waits for time T ( T
is calculated by algorithm).
• During this period, clock process collects the resync messages broadcast by other
nodes.
• Clock process estimates the skew of its clock with respect to other nodes (when
message received) .
23
Global Averaging cont..
• 1st simplest algorithm is to take the average of estimated
skews and use it as the correction for the local clock. And only
below a threshold are taken into account, and other are set to
zero before computing the average.
• Where node has direct communication to every other node (fully connected
topology) .
algorithm.
• Nodes of a distributed system are logically arranged in some kind of pattern such
as Ring.
• Periodically each node exchange its clock time with is neighbors in the ring.
• Average is calculated by , its own clock time and clock times of its neighbors.
25