CH 6
CH 6
1
Synchronization
• Data Integrity: Ensures that data remains consistent across all nodes, preventing
conflicts and inconsistencies.
5
Types of Synchronization
1. Time/clock Synchronization
6
Importance of Time
Synchronization:
• Event Ordering: Ensures that events are recorded in the correct sequence across
different nodes.
7
Techniques:
8
2. Data Synchronization
• Data synchronization ensures that multiple copies of data across different nodes
in a distributed system remain consistent. This involves coordinating updates and
resolving conflicts to maintain a unified state.
• Importance of Data Synchronization:
Consistency: Ensures that all nodes have the same data, preventing
inconsistencies.
Fault Tolerance: Maintains data integrity in the presence of node failures and
network partitions.
Performance: Optimizes data access and reduces latency by ensuring data is
correctly synchronized.
9
Techniques:
10
3. Process Synchronization
11
Techniques:
• Mutual Exclusion: Ensures that only one process accesses a critical section or
shared resource at a time (e.g., using locks, semaphores).
12
Clock Synchronization
• Centralized systems do not need clock synchronization, as they work under a common
clock. But the distributed systems do not follow common clock: each system functions
based on its own internal clock and its own notion of time.
15
Conti..
16
Conti..
• There are 2 types of clock synchronization algorithms: Centralized and
Distributed.
1. Centralized is the one in which a time server is used as a reference. The single
time-server propagates it’s time to the nodes, and all the nodes adjust the time
accordingly. It is dependent on a single time-server, so if that node fails, the whole
system will lose synchronization. Examples of centralized are-Berkeley the
Algorithm, Passive Time Server, Active Time Server etc.
17
Cont..
18
Conti..
They are subject to a single-point failure. If the time-server node fails, the clock
synchronization operation cannot be performed. This makes the system
unreliable. Ideally, a distributed system should be more reliable than its individual
nodes. If one goes down, the rest should continue to function correctly.
From a scalability point of view, it is generally not acceptable to get all the time
requests serviced by a single-time server. In a large system, such a solution puts a
heavy burden on that one process. 19
Conti..
20
Types of Clock Synchronization
21
1. physical clock
synchronization
• In physical clock synchronization, All the computers will have their own clocks.
• The physical clocks are needed to adjust the time of nodes. All the nodes in the system can
share their local time with all other nodes in the system.
• The time will be set based on UTC (Universal Coordinate Timer). UTC is used as a reference
time clock for the nodes in the system.
• Physical clocks keeps the time of the day. It will be consistent across systems.
• The time difference between the two computers is known as “Time drift”. Clock drifts over
the time is known as “Skew”. Synchronization is necessary here.
22
Cont..
• If two events, E1 and E2, having different time stamps t1 and t2, the order of the
event occurring will be considered and not on the exact time or the day at which
they are occur.
23
Cont..
• Several methods are used to attempt the synchronization of the physical clocks in
Distributed synchronization:
2. Christian’s algorithm
3. Berkely’s algorithm
24
Universal Coordinate Time (UTC)
25
Christian’s Algorithm:
• The simplest algorithm for setting time, it issues a remote procedure call (RPC) to
the time sever and obtains the time.
• The machine which send requests to the time server is “d/z” seconds, where d is
the maximum difference between the clock and the UTC.
• The time server sends the reply with current UTC when receives the request from
the receiver.
26
CRISTIAN’S ALGORITHM
Algorithm:
- Let S be the time server and Ts be its time.
- Process P requests the time from S.
- After receiving the request from P, S prepares a response and appends time Ts
from its own clock
and then sends it back to P 27
Berkeley Algorithm
28
BERKELEY’S ALGORITHM
29
2. Logical Clocks
synchronization
• If two systems do not interact with each other then there is no need of
synchronization. So, what usually matters is that processes agree on the order in
which events occur rather than the time at which they occurred.
• Logical clocks does not need exact time. So, absolute time is not a constrain in
logical clocks.
• Logical clocks just bothers about the message to be delivered and not about the
timings of the events occurred.
30
Cont..
• The most common logical clock synchronization algorithms for distributed systems is
Lamport’s algorithm. It is used in the situation where ordering is important not the time.
• Lamport’s logical clock (or timestamp) was proposed by Leslie Lamport in the 1970s and
widely used in almost all distributed systems since then, almost all cloud computing
systems use some form of logical ordering of events.
• Lamport’s logical clock (or timestamp) was proposed by Leslie Lamport in the 1970s and
widely used in almost all distributed systems since then, almost all cloud computing
systems use some form of logical ordering of events.
31
Lamport’s algorithm
• Lamport define the relation happens-before (->) between any pair of events with 3 rules:
1. If a and b are events on the same process, then a -> b if a occurs before b based on the local
clock.
2. If a process sends a message m to another process, then send(m) -> receive(m) where send(m)
and receive(m) are events from first and second processes respectively.
4. If two events, a and b, happen in different processes that do not exchange messages , then
a__>b is not true, but neither is b __> a. These events are said to be concurrent (a || b).
32
Cont..
• The goal of Lamport’s logical clock is to assign timestamps to all events such that
these timestamps obey causality - if an event B is caused by an earlier event A,
then everyone must see A before seeing B. Formally, if an event A causally
happens before another event B, then timestamp(A) < timestamp(B). The
timestamp must always go forward and not backward.
33
Cont..
• Let’s look at an example where 3 processes in the system with the following
conditions:
1. We assume the clocks use local counter which is an integer (initial value of
counter is 0) but the increment of each clock is different.
34
• The messages m1 and m2 obey happens-before, however messages m3
and m4 do not and we need to correct the local clock. For example, m3 is
sent at 50, them m3 should only be received at 51 or later. The algorithm
to update Lamport’s counter is:
35
Cont..
3. Upon receiving the message, B will adjust local clock and the counter is then
incremented by 1 before the message is considered received., i.e.
timestamp(B) = max(timestamp(A), timestamp(B)) + 1.
36
Cont..
37
Cont..
• On the other hand, if events happen from different processes and do not
exchange message directly or indirectly, then nothing can be said about their
relation, and these events are said to be concurrent. Concurrent events are not
casually related and their order is not guaranteed.
38
Thank you!
39