MOD4
MOD4
Solved Ex:
• A client synchronizes with an NTP server, and the following
timestamps are recorded:
• T1 = 100.500 seconds (Client request sent).
• T2 = 200.800 seconds (Server receives request).
• T3 = 200.805 seconds (Server sends response).
• T4 = 100.520 seconds (Client receives response).
• Find:
• Round-Trip Delay (RTT)
• Clock Offset (θ)
How to Compute RTT ?
•RTT = 15 ms
•Clock Offset = 100.2925 seconds (Client’s clock is behind by this much).
Problem 1 - Cristian’s Algorithm
• A distributed system uses Cristian’s Algorithm for time
synchronization. A client sends a time request at T₀ = 45 ms.
The server receives it at T₁ = 60 ms, processes it, and sends
a reply at T₂ = 70 ms, which reaches the client at T₃ = 90 ms.
• Using Cristian’s equation, find the estimated clock offset θ.
Problem II - Network Time Protocol
(NTP) Offset & Delay
• Scenario:
A system using NTP records the following timestamps:
• T₁ (Client Request Sent): 100 ms
• T₂ (Server Receive Time): 130 ms
• T₃ (Server Reply Sent): 135 ms
• T₄ (Client Reply Received): 160 ms
• Using the NTP equations, compute the offset (θ) and round-
trip delay (δ).
Ctd..
Problem III - Berkeley’s Algorithm
• A master node (M) synchronizes the clocks of three client nodes
C1, C2, and C3 in a distributed system using Berkeley’s
Algorithm. The master first collects time readings from all
nodes:
A master node sends time requests to three client nodes C1, C2, and C3.
The round-trip times (RTT) for each client are as follows:
Logical Clocks - Concept
1. Logical clocks assign a numerical value (timestamp) to events.
2. These timestamps help determine the order of events across different
processes. Logical time progresses based on events rather than real-
time clocks.
• Lamport Timestamps
• Proposed by Leslie Lamport in 1978. Every process maintains a
counter that increments for every event. When sending
messages, the timestamp is included, and the receiver updates
its counter accordingly:
• Lci = Lci +1 before an internal event.
• Lci = Lci +1 before sending a message.
• Lci =max(Lci, Lcj)+1 upon receiving a message.
Logical Clocks (Lc) Criteria
1. Only based on order of events
2. Can only advance forward, cannot reverse
3. Non-interacting processes cannot share logical clock
4. Use Interrupts to update the logical clocks, More interrupts
increases overhead
5. Common Method , Lamports Algorithm
Problem IV – Lamport Logical Clock
Two processes, P1 and P2, communicate using messages.
•At P1:
1.Logical clock at P1 is 3.
2.P1 sends a message to P2, and the message timestamp is
3. 4 (clock incremented by 1 before sending).
•At P2:
1.P2 receives the message when its clock is at 2.
4.P2 updates its clock to max(2, 4) = 4, then increments it by 1. So,
the logical clock at P2 becomes 5.
This ensures that the event "P1 sends a message" happens-before "P2
receives the message," maintaining a causal relationship.
Event Ordering sample
Practice Problem Solving
Logical Clocks & Lamport Timestamps
Scenario:
In a distributed system, three processes P1, P2, and P3
communicate as follows:
• P1 starts at time t = 1 and sends a message to P2 at t = 5.
• P2 receives it at t = 12, processes it, and sends a message to
• P3 at t = 18.
• P3 receives the message at t = 25.
•P1 Send Time: 5
•P2 Receive Time: 13
•P2 Send Time: 14
•P3 Receive Time: 26
Vector Timestamp
• A vector timestamp is an extension of Lamport’s logical clock that
provides a way to determine causality between events in a
distributed system. Unlike a single counter, a vector timestamp
maintains a vector of counters, one for each process in the system.
• How It Works:
• Each process maintains a vector of timestamps, where the i-th
element represents the logical clock value for process i.
• When a process performs an event, it increments its own counter
in the vector.
• When a process sends a message, it attaches its vector
timestamp.
• When a process receives a message, it updates its vector clock
by taking the element-wise maximum of its own vector and the
received vector, then increments its own counter.
Simple Rules
Causal Relationship Using Vector
Timestamps:
• For two events A and B,
• A happened before B (A→B) if and only if VA[i] ≤VB[i] for all i
and VA[j]<VB[j] for at least one j.
• If neither A→B nor B→A, then the events are concurrent
Example Scenario
• System Setup
• Consider three processes P1,P2,P3 communicating via messages.
• Process P1 initiates a snapshot at time t1.
• P1 records its local state and sends marker messages to P2 and
P3.
• P2 receives the marker from P1, records its state, and sends
markers to P3.
• P3 receives markers from both P1 and P2, ensuring a consistent
state.
• The final snapshot includes:
• The local states of P1,P2,P3.
• Any in-transit messages (messages sent but not yet received).
Example Scenario