Skip to content
Wade Womersley

wade.one

wade womersley – york based software engineer

  • Home
  • 2026
  • November
  • 25
  • Elapsed Time Needs a Monotonic Clock

Elapsed Time Needs a Monotonic Clock

Posted on November 25, 2026 By
Programming

If a request takes two seconds, I want the duration metric to say two seconds even if the machine’s system clock is corrected while it runs. Subtracting two wall-clock timestamps assumes that the clock moved forwards normally between them. That is a reasonable-looking assumption which the operating system is allowed to spoil.

A monotonic clock is intended for measuring intervals. Python’s time.monotonic documentation, for example, describes a clock that cannot go backwards and is unaffected by system clock updates. Its reference point is undefined, so the useful value is the difference between readings. Keep ordinary timestamps for questions such as when an event happened; use the appropriate duration clock for how long an operation has been running.

That distinction matters for deadlines too. Record a deadline on a monotonic clock, then calculate the remaining allowance using the same clock. Do not mix a monotonic reading with a Unix timestamp because both happen to be represented as numbers. I would keep those values local to the timing operation rather than saving an arbitrary monotonic deadline as durable business data or sending it to another machine. It is not a portable appointment time.

There are details worth checking for the chosen platform, including whether the clock advances while the machine is suspended and which units the API returns. A monotonic clock does not make a scheduler exact or guarantee that a timeout handler runs immediately. It gives the calculation a more suitable basis. For code that depends on time, I would test the duration decision with a controllable clock and keep a separate check that production uses the intended time source. A negative request duration should not be the first indication that the wrong clock was chosen.

Share:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit

Related

Comments

comments

Tags: monotonic-clock time timeouts

Post navigation

❮ Previous Post: Soft Delete Still Leaves You With Hard Decisions

You may also like

Programming
Soft Delete Still Leaves You With Hard Decisions
November 24, 2026
Programming
Optimistic Locking Stops an Old Tab Overwriting New Work
November 13, 2026
Programming
Cloudant (IBM) Query – Indexing arrays directly using Erlang
July 6, 2015
Programming
Graceful Shutdown Is Part of a Successful Deployment
November 23, 2026
  • AI
  • artificial intelligence
  • Ego-centric
  • Events
  • Films
  • Food
  • Gaming
  • Gym
  • Hardware
  • Holidays
  • News
  • PHP
  • Programming
  • Random Stuff
  • Reviews
  • Science
  • SEO
  • Software
  • Software Engineer
  • Support
  • Uncategorized
  • Work

Copyright © 2026 wade.one.

Theme: Oceanly News Dark by ScriptsTown