How to become a Time Lord // A discussion about Time representation in the digital world
For technical and non-technical readers
Do you have time for time // Problem introduction
Time is an abstract concept, an idea that should not be tamed. However, we humans try to force our laws on it, breaking time’s spirit into days and hours and then confusing it even further by stating that the time now in Arizona is different than the time In Belgium! But, if we’re watching a TV show and texting a friend who is also watching, we expect the final scene to be shown in the exact same moment in the real world, even though it’s taking place at different times in different countries.
We learned that a machine must have some data about it’s physical location in order to determine the time zone. Another major issue is the hardware clock that’s built-in into the machine will eventually drift, just like a watch, and needs to be synced again.
But that drift may be one millisecond a day, should we even care for that?
The answer is yes. For example, I work with a product sending video from one machine to another, in each frame I also tell the presentation time — when should this frame be displayed to the user. The picture will be processed and manipulated in different ways: de-encryption, scaling from 480 to 1080 because the user wants a nice HD video, adding closed-captions, or million other things. While running this process, the machine knows how much time it has left until the presentation time, where a ready-to-display frame is sent to the monitor. If the system time is drifted, even in several micro-seconds, this may cause the frame to arrive too late, and not be displayed at all.
To conclude the problem, being in sync with the rest of the world is crucial for the success of any application that has ‘real-time’ aspects.
Well, we can be in ‘absolute’ sync, each system allows a margin of error, usually around several hundred milliseconds to several nanoseconds.
Cut it where it hurts // Epoch time
I will state right away my favorite solution- Epoch time simply tracks the time starting 1.1.1970 at midnight, so the machine can say something like “I think that it’s 5 billion seconds since Epoch” and be answered with “well, I think it’s 5 billion and 2 seconds since Epoch”. Of course, some milliseconds have passed just by the time this conversation was happening, which is yet another problem in syncing time.
The similarity to the AC/BC in not so uncanny, I suspect that Jesus Christ may file for copyrights here, but unlike BC in the real world - there is no “before Epoch” concept because the uses of this time are mostly to find out the “now” and not to represent a past time.
Epoch solves a few problems- it allows us to address the “now” as an integer, a number of seconds, and spares us the trouble with different time formats. It’s much more practical and generic to pass a number of seconds between machines, other than creating one final and clear standard for dd/mm//yy or m/dd/yyyy and so on.
Note that this also relieves us completely from time-zone troubles.
“Excuse me, what time is it” // Network protocols
A parallel solution that co-exists with Epoch, is having a machine constantly asks its neighbors what time it is. The idea is that some of our neighbors will be more accurate than us, and we will fix the less-accurate one according to the others. The term neighbor here means the network, practically the internet for most of our machines, such as laptops and smartphones, but can also be a closed network of several computers, it’s all the same for our propose.
An Important example is NTP (Network Time Protocol), which was developed in the 70s, when it was too pricy to add GPS hardware to each machine (GPS allows you to check the precise time with a satellite), and still, NTP is the default in Linux and in constant use since 1985. NTP tries to define what machine is less accurate than others using a sectioning algorithm. For more in-depth explanations with some numerics I added a link in the end.
An alternative to NTP is PTP (Precision Time Protocol) which also synchronizes clocks, but its algorithm focuses on local area network, and the user can declare one machine as Grandmaster, so the time updates cannot be in any direction but are more similar to a tree form.
Since we have a final number of machines in the local network, and it’s more clear who should listen to who, PTP achieves clock accuracy in the sub-microsecond range.
To summarize, NTP is more common and is generic, but less precise, usually up to tens of milliseconds.
Are we late? // Summary
So, let’s get back to humans. We broke the infinite concept of time and quantized it, translated it into the digital world, had our machine infinitely asking each other what time is it, and now, we complain that there isn’t enough time left!