{"id":1517,"date":"2026-11-25T18:00:00","date_gmt":"2026-11-25T18:00:00","guid":{"rendered":"https:\/\/wade.one\/blog\/?p=1517"},"modified":"2026-11-25T18:00:00","modified_gmt":"2026-11-25T18:00:00","slug":"elapsed-time-needs-a-monotonic-clock","status":"publish","type":"post","link":"https:\/\/wade.one\/blog\/2026\/11\/25\/elapsed-time-needs-a-monotonic-clock\/","title":{"rendered":"Elapsed Time Needs a Monotonic Clock"},"content":{"rendered":"<p>If a request takes two seconds, I want the duration metric to say two seconds even if the machine&#8217;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.<\/p>\n<p>A monotonic clock is intended for measuring intervals. Python&#8217;s <a href=\"https:\/\/docs.python.org\/3\/library\/time.html#time.monotonic\">time.monotonic documentation<\/a>, 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.<\/p>\n<p>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.<\/p>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The clock that tells you what time it is is not always the clock you want for measuring how long something took.<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[13],"tags":[345,344,346],"class_list":["post-1517","post","type-post","status-publish","format-standard","hentry","category-programming","tag-monotonic-clock","tag-time","tag-timeouts"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Elapsed Time Needs a Monotonic Clock - wade.one<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wade.one\/blog\/2026\/11\/25\/elapsed-time-needs-a-monotonic-clock\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Elapsed Time Needs a Monotonic Clock - wade.one\" \/>\n<meta property=\"og:description\" content=\"The clock that tells you what time it is is not always the clock you want for measuring how long something took.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wade.one\/blog\/2026\/11\/25\/elapsed-time-needs-a-monotonic-clock\/\" \/>\n<meta property=\"og:site_name\" content=\"wade.one\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-25T18:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/Wade-Logo-cropped.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1518\" \/>\n\t<meta property=\"og:image:height\" content=\"1506\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@wadewomersley\" \/>\n<meta name=\"twitter:site\" content=\"@wadewomersley\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/11\\\/25\\\/elapsed-time-needs-a-monotonic-clock\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/11\\\/25\\\/elapsed-time-needs-a-monotonic-clock\\\/\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"Elapsed Time Needs a Monotonic Clock\",\"datePublished\":\"2026-11-25T18:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/11\\\/25\\\/elapsed-time-needs-a-monotonic-clock\\\/\"},\"wordCount\":294,\"publisher\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#\\\/schema\\\/person\\\/8b4739f8f8bb2cff5d792d4b8779fcc3\"},\"keywords\":[\"monotonic-clock\",\"time\",\"timeouts\"],\"articleSection\":[\"Programming\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/11\\\/25\\\/elapsed-time-needs-a-monotonic-clock\\\/\",\"url\":\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/11\\\/25\\\/elapsed-time-needs-a-monotonic-clock\\\/\",\"name\":\"Elapsed Time Needs a Monotonic Clock - wade.one\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#website\"},\"datePublished\":\"2026-11-25T18:00:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/11\\\/25\\\/elapsed-time-needs-a-monotonic-clock\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/11\\\/25\\\/elapsed-time-needs-a-monotonic-clock\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/2026\\\/11\\\/25\\\/elapsed-time-needs-a-monotonic-clock\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/wade.one\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Elapsed Time Needs a Monotonic Clock\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/wade.one\\\/blog\\\/\",\"name\":\"wade.one\",\"description\":\"wade womersley - york based software engineer\",\"publisher\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#\\\/schema\\\/person\\\/8b4739f8f8bb2cff5d792d4b8779fcc3\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/wade.one\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/#\\\/schema\\\/person\\\/8b4739f8f8bb2cff5d792d4b8779fcc3\",\"name\":\"Wade Womersley\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/200px.png\",\"url\":\"https:\\\/\\\/wade.one\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/200px.png\",\"contentUrl\":\"https:\\\/\\\/wade.one\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/200px.png\",\"width\":202,\"height\":200,\"caption\":\"Wade Womersley\"},\"logo\":{\"@id\":\"https:\\\/\\\/wade.one\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/02\\\/200px.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Elapsed Time Needs a Monotonic Clock - wade.one","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wade.one\/blog\/2026\/11\/25\/elapsed-time-needs-a-monotonic-clock\/","og_locale":"en_GB","og_type":"article","og_title":"Elapsed Time Needs a Monotonic Clock - wade.one","og_description":"The clock that tells you what time it is is not always the clock you want for measuring how long something took.","og_url":"https:\/\/wade.one\/blog\/2026\/11\/25\/elapsed-time-needs-a-monotonic-clock\/","og_site_name":"wade.one","article_published_time":"2026-11-25T18:00:00+00:00","og_image":[{"width":1518,"height":1506,"url":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/Wade-Logo-cropped.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_creator":"@wadewomersley","twitter_site":"@wadewomersley","twitter_misc":{"Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/wade.one\/blog\/2026\/11\/25\/elapsed-time-needs-a-monotonic-clock\/#article","isPartOf":{"@id":"https:\/\/wade.one\/blog\/2026\/11\/25\/elapsed-time-needs-a-monotonic-clock\/"},"author":{"name":"","@id":""},"headline":"Elapsed Time Needs a Monotonic Clock","datePublished":"2026-11-25T18:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/wade.one\/blog\/2026\/11\/25\/elapsed-time-needs-a-monotonic-clock\/"},"wordCount":294,"publisher":{"@id":"https:\/\/wade.one\/blog\/#\/schema\/person\/8b4739f8f8bb2cff5d792d4b8779fcc3"},"keywords":["monotonic-clock","time","timeouts"],"articleSection":["Programming"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/wade.one\/blog\/2026\/11\/25\/elapsed-time-needs-a-monotonic-clock\/","url":"https:\/\/wade.one\/blog\/2026\/11\/25\/elapsed-time-needs-a-monotonic-clock\/","name":"Elapsed Time Needs a Monotonic Clock - wade.one","isPartOf":{"@id":"https:\/\/wade.one\/blog\/#website"},"datePublished":"2026-11-25T18:00:00+00:00","breadcrumb":{"@id":"https:\/\/wade.one\/blog\/2026\/11\/25\/elapsed-time-needs-a-monotonic-clock\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wade.one\/blog\/2026\/11\/25\/elapsed-time-needs-a-monotonic-clock\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wade.one\/blog\/2026\/11\/25\/elapsed-time-needs-a-monotonic-clock\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wade.one\/blog\/"},{"@type":"ListItem","position":2,"name":"Elapsed Time Needs a Monotonic Clock"}]},{"@type":"WebSite","@id":"https:\/\/wade.one\/blog\/#website","url":"https:\/\/wade.one\/blog\/","name":"wade.one","description":"wade womersley - york based software engineer","publisher":{"@id":"https:\/\/wade.one\/blog\/#\/schema\/person\/8b4739f8f8bb2cff5d792d4b8779fcc3"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wade.one\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":["Person","Organization"],"@id":"https:\/\/wade.one\/blog\/#\/schema\/person\/8b4739f8f8bb2cff5d792d4b8779fcc3","name":"Wade Womersley","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/200px.png","url":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/200px.png","contentUrl":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/200px.png","width":202,"height":200,"caption":"Wade Womersley"},"logo":{"@id":"https:\/\/wade.one\/blog\/wp-content\/uploads\/2015\/02\/200px.png"}}]}},"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1441,"url":"https:\/\/wade.one\/blog\/2026\/10\/22\/a-scheduled-job-needs-a-time-zone-not-just-an-hour\/","url_meta":{"origin":1517,"position":0},"title":"A Scheduled Job Needs a Time Zone, Not Just an Hour","author":"","date":"October 22, 2026","format":false,"excerpt":"\"Run it at six\" is incomplete information for a scheduled job.","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/wade.one\/blog\/category\/programming\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":885,"url":"https:\/\/wade.one\/blog\/2015\/05\/24\/nvidia-geforce-gtx-980-ti-possible-details-and-performance-leaked\/","url_meta":{"origin":1517,"position":1},"title":"Nvidia Geforce GTX 980 Ti &#8211; possible details and performance leaked","author":"Wade","date":"May 24, 2015","format":false,"excerpt":"\u00a0 It appears that Nvidia might launch the Geforce GTX 980 Ti even earlier as expected as we are now hearing plenty of new rumors regarding it, including most of the specifications.According to a fresh report coming from the Korean HWBattle website, spotted by Techpowerup.com, and despite earlier report, Nvidia\u2026","rel":"","context":"In &quot;Gaming&quot;","block_context":{"text":"Gaming","link":"https:\/\/wade.one\/blog\/category\/gaming\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/wade.one\/blog\/wp-content\/uploads\/2015\/05\/6986cf9ad43446411c85715627bcb4c8_L.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/wade.one\/blog\/wp-content\/uploads\/2015\/05\/6986cf9ad43446411c85715627bcb4c8_L.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/wade.one\/blog\/wp-content\/uploads\/2015\/05\/6986cf9ad43446411c85715627bcb4c8_L.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":164,"url":"https:\/\/wade.one\/blog\/2009\/10\/02\/asus-en8800gtshtdp-geforce-8800gts-640-mb-for-sale\/","url_meta":{"origin":1517,"position":2},"title":"ASUS EN8800GTS\/HTDP GeForce 8800GTS (640 MB) For Sale!","author":"Wade","date":"October 2, 2009","format":false,"excerpt":"Finally upgraded to a GTX 260 896MB graphics card so I'm getting rid of my old card, it's a Geforce 8800 GTS, with 640MB RAM and a clock speed set to 575Mhz (overclocked.) And yes, it can run Crysis! (Not at max details of course, but at 1680x1050 with settings\u2026","rel":"","context":"In &quot;Hardware&quot;","block_context":{"text":"Hardware","link":"https:\/\/wade.one\/blog\/category\/hardware\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1445,"url":"https:\/\/wade.one\/blog\/2026\/10\/26\/request-ids-are-useful-when-they-survive-the-whole-journey\/","url_meta":{"origin":1517,"position":3},"title":"Request IDs Are Useful When They Survive the Whole Journey","author":"Wade","date":"October 26, 2026","format":false,"excerpt":"A request ID in one log line is useful.","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/wade.one\/blog\/category\/programming\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":215,"url":"https:\/\/wade.one\/blog\/2009\/10\/12\/volkswagen-the-fun-theory\/","url_meta":{"origin":1517,"position":4},"title":"Volkswagen &#8211; The Fun Theory","author":"Wade","date":"October 12, 2009","format":false,"excerpt":"Volkswagen have decided to give the world of viral video a go and have pretty much nailed it. These two video's are spreading over the internet like wildfire. The first is a \"deep bin,\" a trash can that when you throw rubbish in, sounds like it's dropping for a long\u2026","rel":"","context":"In &quot;Random Stuff&quot;","block_context":{"text":"Random Stuff","link":"https:\/\/wade.one\/blog\/category\/random-stuff\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1160,"url":"https:\/\/wade.one\/blog\/2026\/03\/27\/what-makes-a-legacy-system-dangerous\/","url_meta":{"origin":1517,"position":5},"title":"What Makes a Legacy System Dangerous","author":"Wade","date":"March 27, 2026","format":false,"excerpt":"A legacy system is not dangerous just because it is old. It becomes dangerous when nobody can change it safely, nobody can see what it is doing, and the business depends on it anyway.","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/wade.one\/blog\/category\/programming\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/posts\/1517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/comments?post=1517"}],"version-history":[{"count":1,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/posts\/1517\/revisions"}],"predecessor-version":[{"id":1532,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/posts\/1517\/revisions\/1532"}],"wp:attachment":[{"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/media?parent=1517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/categories?post=1517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wade.one\/blog\/wp-json\/wp\/v2\/tags?post=1517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}