Skip to main content

Physical/logical clocks; NTP and Berkeley

Short answer

Physical clocks track real time and need synchronization; logical clocks are counters that only order events. NTP uses a stratum hierarchy and four timestamps to compute delay and offset, choosing the smallest-delay sample. Berkeley elects a master, averages all slave clocks, and sends each machine the required adjustment.

What do you mean by physical and logical clocks? Explain Network Time Protocol and Berkeley Algorithm for physical clock synchronization.

Physical and logical clocks

  • A physical clock is a hardware clock that tracks real time. Each machine's clock drifts, so physical clocks must be synchronised with each other or with UTC.
  • A logical clock is a software counter that only orders events (happened-before). It has no relation to real time. Examples: Lamport clock and vector clock.

Network Time Protocol

NTP synchronises clocks over the Internet to UTC. It uses a hierarchy of time servers in strata (stratum 0 = atomic/GPS reference, stratum 1 = servers attached to it, stratum 2 = clients of stratum 1, etc.). Clients query several servers over UDP and compute delay and offset from four timestamps:

  • offset o = ((Ti−2 − Ti−3) + (Ti−1 − Ti)) / 2
  • delay d = (Ti − Ti−3) − (Ti−1 − Ti−2)

Modes: multicast, procedure-call, symmetric. The sample with the smallest delay is chosen, and the clock is changed gradually. It tolerates server failure by using multiple servers, and is accurate to a few milliseconds on the Internet.

Berkeley algorithm

Internal synchronisation, used when no UTC receiver is available.

  1. A master machine polls all others for their time.
  2. Each replies; the master adjusts values for round-trip time.
  3. It averages all times (discarding outliers).
  4. It sends each machine the amount to adjust (plus or minus).
 Master: 3:00   polls   A: 2:50   B: 3:25
 average = (3:00 + 2:50 + 3:25)/3 = 3:05
 adjustments: Master +5, A +15, B -20

All clocks agree on the average, not necessarily on true time. If the master fails, another is elected.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Distributed System chapter 5 questions →