Logical clocks (Lamport, Vector clocks)
Logical Clocks A logical clock is a distributed algorithm that allows multiple processes to maintain consistent time, even when they are located on diff...
Logical Clocks A logical clock is a distributed algorithm that allows multiple processes to maintain consistent time, even when they are located on diff...
Logical Clocks
A logical clock is a distributed algorithm that allows multiple processes to maintain consistent time, even when they are located on different machines with different clocks. This is achieved by using a combination of shared memories, messages, and a distributed algorithm called synchronization.
How it works:
Shared memory: Each process writes the current time into a shared memory location.
Synchronous reads: Other processes read the time from the shared memory and compare it to the local time.
Consensus: If enough processes read the same time, they conclude that all processes are on the same time.
Periodic updates: To maintain consistency, processes periodically send and receive updates to the shared memory.
Benefits of using logical clocks:
Consistency: Time is consistent across all participating processes.
Reliability: If a process fails, others can continue using the last known time.
Efficiency: Logical clocks are often faster than traditional clock synchronization methods.
Examples:
In Lamport clocks, each process maintains its own local clock and periodically sends updates to a shared memory. Other processes read the shared memory and update their clocks accordingly.
In Vector clocks, a central process generates a unique "vector" of timestamps that all processes receive and use to maintain time.
Conclusion:
Logical clocks are a powerful technique for maintaining time consistency in distributed systems. They provide a reliable and efficient way for multiple processes to agree on a common time, even when they are geographically distributed