{"id":1313,"date":"2010-03-14T11:55:49","date_gmt":"2010-03-14T18:55:49","guid":{"rendered":"https:\/\/mathpirate.net\/log\/?p=1313"},"modified":"2010-03-14T11:55:49","modified_gmt":"2010-03-14T18:55:49","slug":"temporal-mechanics-changing-the-speed-of-time","status":"publish","type":"post","link":"https:\/\/mathpirate.net\/log\/2010\/03\/14\/temporal-mechanics-changing-the-speed-of-time\/","title":{"rendered":"Temporal Mechanics: Changing the Speed of Time"},"content":{"rendered":"<p>Until last week, I never really thought about my computer&#8217;s system clock.\u00c2\u00a0 I simply thought that it hummed along at a constant, smooth rate, always heading toward the future.\u00c2\u00a0 I figured that once a week, it would call a time server tethered to atomic clock somewhere and make sure that it&#8217;s in sync.\u00c2\u00a0 If not, it would immediately correct the time and go about its business for another week.<\/p>\n<p>Turns out, I was wrong.\u00c2\u00a0 The way Windows handles time, particularly when a member of a domain is a tad more complicated.\u00c2\u00a0 And, as it turns out, you generally want it that way.<\/p>\n<p>Think about the implications of the method I described above.\u00c2\u00a0 If your system clock is bad, that means that in the span of a week, you can get ten or fifteen minutes off of real time.\u00c2\u00a0 Then, in one big jump, your clock gets corrected, jumping your system ten minutes into the future, or forcing it to re-live the past ten minutes over again.\u00c2\u00a0 On your home system, that&#8217;s probably not a huge deal.\u00c2\u00a0 Timestamps on all the movies you&#8217;re downloading might be off by a bit, big deal.\u00c2\u00a0 But in the business world, that would be bad.\u00c2\u00a0 Your Outlook reminders would fire off at different times for different people, e-mails and instant messages would have odd timestamps, and the Kerberos system used for authentication would randomly block people for being outside of an acceptable time range.<\/p>\n<p>In short:\u00c2\u00a0 Mayhem.<\/p>\n<p>So, when you&#8217;re joined to a domain, Windows typically gets a bit stricter over how it handles time synchronization.\u00c2\u00a0 It does this to keep all machines in line.\u00c2\u00a0 That&#8217;s why you hear the meeting reminder bell rising from fifteen machines in your cubicle farm at nearly the same moment.\u00c2\u00a0 The Windows Time Service is keeping everyone synchronized.<\/p>\n<p>Now, there&#8217;s a good chance that you already knew that, if you&#8217;ve been around networks long enough.\u00c2\u00a0 But, there&#8217;s an equally good chance that you don&#8217;t know how the Windows Time Service is keeping everyone synchronized.\u00c2\u00a0 I had always assumed that the Time Service was keeping everyone in sync by resetting everyone&#8217;s clocks to the correct time every hour or so, and that no one ever noticed because your internal system clock kept good time.\u00c2\u00a0 In other words, at 1:03:27 PM, your computer would be told that it was 1:03:27 PM, so it would set the time, and it would still be 1:03:27 PM.<\/p>\n<p>That ain&#8217;t what it does.<\/p>\n<p>In fact, your computer&#8217;s clock doesn&#8217;t really matter to Windows.\u00c2\u00a0 Windows really only pays attention to it when it first starts up.\u00c2\u00a0 Beyond that, the magic of the Windows Time Service keeps things in line.<\/p>\n<p>The Windows Time Service doesn&#8217;t really like setting your time at all, once it&#8217;s running.\u00c2\u00a0 It will do so, if your clock gets too far away from the time authority, but in general, it won&#8217;t set your time.\u00c2\u00a0 So, how does it keep a flock of computers running in perfect\u00c2\u00a0Outlook harmony?<\/p>\n<p>Simple.<\/p>\n<p>It changes the speed of time.<\/p>\n<p>I&#8217;ll get into that, but first, let&#8217;s change your perception of time.\u00c2\u00a0 Time, at least from the perspective of a Windows machine, is not linear.\u00c2\u00a0 Instead, it&#8217;s a step function.\u00c2\u00a0\u00c2\u00a0The exact values\u00c2\u00a0vary from system to system, but these are the basics:\u00c2\u00a0 Every 15 ms or so, the clock bumps its time value by 15 ms or so.\u00c2\u00a0 If you&#8217;ve ever done a Console.WriteLine(DateTime.Now.Ticks); inside a tight while loop ((Go ahead, try it.)), you&#8217;ve seen the effects of this. \u00c2\u00a0The value will remain constant for many iterations, then leap up, then stay at the new level for a while, then jump.\u00c2\u00a0 Similarly, if you&#8217;ve ever\u00c2\u00a0mistakenly tried to use DateTime for recording performance numbers, you&#8217;ve run into something similar.\u00c2\u00a0 All of your perf times are reporting 0ms, 15ms, or 31ms.\u00c2\u00a0 It&#8217;s always one of those three.\u00c2\u00a0 Never 7, never 12, never 24.\u00c2\u00a0 That&#8217;s because the resolution of the time is 15ms.<\/p>\n<p>In other words, time looks like this:<\/p>\n<p><a href=\"https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeEvenStep.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-1315\" title=\"TimeEvenStep\" src=\"https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeEvenStep-300x300.png\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeEvenStep-300x300.png 300w, https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeEvenStep-150x150.png 150w, https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeEvenStep.png 400w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The smooth black line is &#8220;real time&#8221; and the stepping red line is your computer&#8217;s time.<\/p>\n<p>All is well in graph-land.\u00c2\u00a0 The time your computer reads might move in discrete chunks, but it&#8217;s always centered around real time, so you&#8217;re never more than 7.5 ms off of reality.<\/p>\n<p>But what happens if the clock in your computer is bad?\u00c2\u00a0 The quartz crystal has gone on a vacation to a big sphinx with the Jackdaws or the cesium atom is vibrating 9192631771 times a second.\u00c2\u00a0 Your computer will think that it&#8217;s adding 15ms, but it&#8217;s actually adding slightly more or less time.\u00c2\u00a0 Let&#8217;s take a 5% error rate.\u00c2\u00a0 For every 15 ms of real time, your computer adds 15.75 ms to its clock.\u00c2\u00a0 That looks like this:<\/p>\n<p><a href=\"https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeGraph-FivePercent.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-1316\" title=\"TimeGraph-FivePercent\" src=\"https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeGraph-FivePercent-285x300.png\" alt=\"\" width=\"285\" height=\"300\" srcset=\"https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeGraph-FivePercent-285x300.png 285w, https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeGraph-FivePercent.png 400w\" sizes=\"(max-width: 285px) 100vw, 285px\" \/><\/a><\/p>\n<p>You&#8217;ve gone off the chart.\u00c2\u00a0 The error accumulates and time starts drifting.\u00c2\u00a0 At the end of this sample graph, which represents only 135 ms, your clock has already drifted so far that it now will never be correct.\u00c2\u00a0 At this rate, after ten minutes, you&#8217;ll be 30 seconds off.<\/p>\n<p>Obviously, that&#8217;s not good.\u00c2\u00a0 What the system could do is reset your clock every ten minutes to the correct time.\u00c2\u00a0 Except that you&#8217;d notice a jump like that and you&#8217;d get annoyed.\u00c2\u00a0 Granted, 5% is a large error for a system clock, but the premise is the same regardless of the size of the error.\u00c2\u00a0 Small errors add up to big problems.\u00c2\u00a0 Even if you only drifted a second every ten minutes, that one second skip would cause trouble to enough people that it would be a major issue.\u00c2\u00a0 So, like I said, the Windows Time Service will change the speed of time to correct the clock.<\/p>\n<p>It&#8217;s a bit like putting your finger on the second hand of a clock.\u00c2\u00a0 You can push it forward gently and the clock will move ahead, or you can resist the motion and the clock will fall behind.\u00c2\u00a0 That 15ms that the system adds to the clock is just a number.\u00c2\u00a0 On my machine, that number is 156250. ((So, I lied.\u00c2\u00a0 It&#8217;s not 15ms, it&#8217;s 15.6ms, but I&#8217;m not typing 15.6ms all the time.))\u00c2\u00a0 That&#8217;s the number of 100ns units of time that will get added to the clock every time it ticks.\u00c2\u00a0 ((100 nanoseconds is the base unit of time in the Windows world.\u00c2\u00a0 Windows File Time is given in the number of 100ns ticks since January 1st, 1601.\u00c2\u00a0 Why that date, I&#8217;m not sure, but I think it has something to do with the Illuminati and a Star Trek fan who wasn&#8217;t good at remembering numbers exactly.\u00c2\u00a0 There are 10000 of these in 1ms, and\u00c2\u00a010000000 of them in a second.))\u00c2\u00a0 But if your clock is too far ahead, all the system has to do is add a smaller number (Say, 150000) for a period of time, causing your computer&#8217;s clock to slow down, and letting reality catch up.<\/p>\n<p>Back to the graph, this time with a 50% error for illustration purposes.<\/p>\n<p><a href=\"https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeGraph-50Percent.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-1317\" title=\"TimeGraph-50Percent\" src=\"https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeGraph-50Percent-201x300.png\" alt=\"\" width=\"201\" height=\"300\" srcset=\"https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeGraph-50Percent-201x300.png 201w, https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeGraph-50Percent.png 400w\" sizes=\"(max-width: 201px) 100vw, 201px\" \/><\/a><\/p>\n<p>It&#8217;s adding 22.5ms for every 15ms of real time.\u00c2\u00a0 Very quickly, your clock is\u00c2\u00a0going off the rails.\u00c2\u00a0 Let&#8217;s change the speed of time and fix this problem.<\/p>\n<p><a href=\"https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeGraph-50PercentFix.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-1318\" title=\"TimeGraph-50PercentFix\" src=\"https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeGraph-50PercentFix-244x300.png\" alt=\"\" width=\"244\" height=\"300\" srcset=\"https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeGraph-50PercentFix-244x300.png 244w, https:\/\/mathpirate.net\/log\/wp-content\/uploads\/2010\/03\/TimeGraph-50PercentFix.png 400w\" sizes=\"(max-width: 244px) 100vw, 244px\" \/><\/a><\/p>\n<p>The\u00c2\u00a0Windows Time Service saw the fact that the time was way off and\u00c2\u00a0changed the speed of time, slowing down the clock to\u00c2\u00a0two-thirds of its normal speed.\u00c2\u00a0 It started adding only 10ms of computer time every 15ms of real time.\u00c2\u00a0 This solved the problem very quickly, but has the unfortunate side effect of leaving your computer&#8217;s clock running too slow.\u00c2\u00a0 Now, instead of zooming ahead, it&#8217;s going to be falling further and further behind reality.\u00c2\u00a0 The solution, of course, is to speed time back up.<\/p>\n<p>Now, the corrections don&#8217;t happen on this scale.\u00c2\u00a0 This is a huge simplification\u00c2\u00a0of the bizarre reality you&#8217;ll uncover if you ever watch the Windows Time\u00c2\u00a0Service work its magic. \u00c2\u00a0Usually you&#8217;ll see something like a drift of 20ms over 10 minutes, then over the next ten minutes, the time service will slow the clock to lose those extra 20ms.\u00c2\u00a0 All day long, you&#8217;ll see your system drift in and out of phase with reality, but it should never get that far out of tune, and you&#8217;ll never notice what it does just by watching the clock.<\/p>\n<p>Unless, of course, you deliberately set your clock ahead or behind&#8230;<\/p>\n<p>You have to be careful, because the time service has a couple of cutoff thresholds where it will force a corrective\u00c2\u00a0time jump in order to fix the problem.\u00c2\u00a0 However, if you stay within those thresholds, you can watch w32time do some pretty awesome things.\u00c2\u00a0 Like make your system time gain seven minutes over the course of five real minutes, or make every second last two seconds.<\/p>\n<p>TAKE THAT, EINSTEIN.<\/p>\n<p>Not that I&#8217;m suggesting you try this or anything, but while you&#8217;re at work tomorrow (On a computer that&#8217;s on a domain and synching regularly with an authoritative time source), get some popcorn, set your clock ahead or behind\u00c2\u00a0about 3.5 minutes, and compare your computer&#8217;s clock (You have to watch the view with the second hand) to some external time source, like your watch or cell phone.\u00c2\u00a0 When I&#8217;ve done this, it&#8217;ll start slowly.\u00c2\u00a0 The time will remain where it is for a while, then all of a sudden, time will accelerate (or decelerate) drastically for a period of a few minutes, then it will level off.\u00c2\u00a0 Within about half an hour,\u00c2\u00a0that 3.5 minute gap will be pretty much closed, and it never had to skip or repeat a second.<\/p>\n<p>Of course, the specifics change with different machines, different Windows versions, and different network time\u00c2\u00a0configurations.\u00c2\u00a0 You may have to fiddle and twizzle with knobs and dials to see any noticeable\u00c2\u00a0result.\u00c2\u00a0 Fortunately, there&#8217;s Registry Settings located under HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\w32time that give you lots of knobs and dials to fiddle and twizzle.\u00c2\u00a0 You don&#8217;t necessarily want to mess with any of them, and I&#8217;d strongly recommend finding a reference to what they do before you set out on a time bending adventure using them.\u00c2\u00a0 I&#8217;d also strongly recommend exporting a backup copy of that reg key before you go mucking about, otherwise be prepared to be late for everything for the rest of your life.<\/p>\n<p>Oh, and did I mention that you can change the speed of time yourself?\u00c2\u00a0 That makes this so much more fun, especially if it&#8217;s not your computer that you&#8217;re changing the speed of time on.\u00c2\u00a0 I&#8217;ll show you how to do that next time.<\/p>\n<p>(If there is a next time&#8230;\u00c2\u00a0 I think I may have triggered a paradox and my hand seems to be disappearing now&#8230;)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Until last week, I never really thought about my computer&#8217;s system clock.\u00c2\u00a0 I simply thought that it hummed along at a constant, smooth rate, always heading toward the future.\u00c2\u00a0 I figured that once a week, it would call a time server tethered to atomic clock somewhere and make sure that it&#8217;s in sync.\u00c2\u00a0 If not, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,34,1],"tags":[131,132,135,133,134],"_links":{"self":[{"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/posts\/1313"}],"collection":[{"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/comments?post=1313"}],"version-history":[{"count":4,"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/posts\/1313\/revisions"}],"predecessor-version":[{"id":1321,"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/posts\/1313\/revisions\/1321"}],"wp:attachment":[{"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/media?parent=1313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/categories?post=1313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/tags?post=1313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}