Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 6

CS3551-Distributed

Computing
Logical time: Physical Clock Synchronization-NTP
Logical Time

• Logical time is a way to order events in a distributed system without


relying on physical clocks. It ensures that the system can reason about
the sequence of events, even if physical clocks are not perfectly
synchronized.
Types of logical clocks
• Two main types of logical clocks are
1.Lamport Timestamps:
1. Proposed by Leslie Lamport, Lamport timestamps provide a simple mechanism to order events.
2. Each process maintains a local counter. Before sending a message, the process increments its counter and
attaches it to the message. When a process receives a message, it updates its counter to be greater than the
maximum of its current value and the received timestamp, plus one.
3. This ensures a partial ordering of events, meaning we can determine a happened-before relationship but not
the exact time.
2.Vector Clocks:
1. Vector clocks provide a more detailed mechanism to capture causality.
2. Each process maintains a vector of counters, with each element representing the last known counter value of
every other process.
3. When a process sends a message, it increments its own counter and includes the entire vector clock. Upon
receiving a message, a process updates each element of its vector to be the maximum of its current value and
the received value for each process.
4. Vector clocks provide a total ordering of events, allowing for the detection of concurrent events.
Physical Clock Synchronization
• Physical clock synchronization aims to align the actual time across different nodes in a distributed
system. Network Time Protocol (NTP) is the most widely used protocol for this purpose.
1. Network Time Protocol (NTP):
1. NTP is designed to synchronize the clocks of computers over a network.
2. It uses a hierarchical system of time sources, with each level referred to as a stratum. Stratum 0 represents highly
accurate time sources like atomic clocks, while higher strata are further away in terms of network hops from these
sources.
3. NTP clients synchronize their clocks by exchanging time-stamped messages with NTP servers. The protocol
accounts for network delays and jitter to estimate the accurate time.
2. How NTP Works:
1. Time Request and Response: An NTP client sends a request to an NTP server, and the server responds with its
current time. The client uses the timestamps from the request and response, along with its own send and receive
times, to estimate the round-trip delay and offset.
2. Clock Adjustment: The client adjusts its clock gradually to avoid abrupt changes, which could disrupt ongoing
processes.
3. Precision and Accuracy: NTP can achieve synchronization within milliseconds over the public internet and within
microseconds on a local network.
Practical Considerations
Choosing Between Them:
•Use logical time for systems where event ordering and causality are more important than
precise timing (e.g., distributed databases, version control).
•Use physical clock synchronization for applications requiring precise timing and coordination
(e.g., financial transactions, real-time monitoring systems).
Hybrid Approaches:
•Many distributed systems use a combination of logical and physical time. For instance, they
may use NTP to ensure physical clocks are reasonably synchronized and logical clocks to order
events within the system.
Technological Implementations:
•Logical clocks are often implemented in distributed databases and concurrency control
mechanisms.
•NTP is implemented at the operating system level and is critical for maintaining synchronized
system logs, security protocols, and scheduling tasks.
THANK YOU

You might also like