Research Library · Idea
Logical clocks
Logical clocks are counters that give the events of a distributed system a consistent order without relying on physical time. Leslie Lamport introduced them in "Time, Clocks, and the Ordering of Events in a Distributed System", published in Communications of the ACM in July 1978.1 The paper examines the concept of one event happening before another in a distributed system and shows that it defines a partial ordering of events. It then gives a distributed algorithm for synchronizing a system of logical clocks that can be used to totally order the events.1
Lamport defines a distributed system as a collection of distinct, spatially separated processes that communicate by exchanging messages, and as one in which message transmission delay is not negligible compared with the time between events in a single process. In such a system it is sometimes impossible to say which of two events occurred first, so the "happened before" relation is only a partial ordering. He defines the relation without physical clocks, because real clocks are not perfectly accurate and do not keep precise physical time.1
Each process keeps a clock that assigns a number to each of its events. The paper's Clock Condition requires that if one event happened before another, the first has the lower clock value. Two implementation rules meet it. IR1 says each process increments its clock between any two successive events. IR2 says a message carries a timestamp equal to the clock value at its sending, and on receiving a message a process sets its clock greater than or equal to its present value and greater than the timestamp.1
To turn the partial order into a total order, events are ordered by clock value, with ties broken by an arbitrary fixed ordering of the processes. The resulting order depends on the clocks and is not unique, but every such order extends the happened-before relation.1 Lamport illustrates its use with a mutual exclusion algorithm for processes sharing a single resource, in which requests are granted in the order in which they were made.1
The paper also describes anomalous behavior. An ordering derived from logical clocks can disagree with the order that users observe through channels outside the system, such as telephone calls. The paper offers two ways to avoid this, one of which is to introduce real, physical clocks satisfying a Strong Clock Condition, and it analyzes how closely such clocks must be synchronized.1 The 1982 Byzantine generals paper separately states that detecting a missing message by time-out requires clocks synchronized to within some fixed maximum error.2
Source · Time, Clocks, and the Ordering of Events in a Distributed System (opens in a new tab) · Communications of the ACM (author: Leslie Lamport)
References
- Time, Clocks, and the Ordering of Events in a Distributed System (opens in a new tab) · Communications of the ACM (author: Leslie Lamport) · CACM 21(7), July 1978, pp. 558-565. Abstract, partial ordering, rules IR1 and IR2, total ordering, mutual exclusion, anomalous behavior. ↩ ↩ ↩ ↩ ↩ ↩ ↩
- The Byzantine Generals Problem (opens in a new tab) · ACM Transactions on Programming Languages and Systems (authors: Leslie Lamport, Robert Shostak and Marshall Pease) · July 1982; discussion of time-outs and synchronized clocks. ↩
Research articles
- How machines and networks are put together: operating systems, the internet and distributed systems, and what their designers prioritized · Computer science
See what connects to it on the map of ideas →

SecSIG