9

Just as the questions says, why there would be an NTP server when the devices already got the internal clock and are accurate.

Jugert Mucoimaj
  • 193
  • 1
  • 3
  • 6
    What alternate method would let you deal with keeping your clocks synched ? Even setting two clocks to the same time, accurate to the millisecond is impossible by hand and they'll soon diverge. Consumer-grade clocks are kinda rubbish. – Criggie Nov 06 '22 at 22:36
  • 24
    How do you know the internal clock is accurate? – OrangeDog Nov 07 '22 at 09:58
  • 2
    How do you tell your devices what time it is? – vidarlo Nov 07 '22 at 22:10
  • Is there something wrong with NTP in your environment ? – Criggie Nov 08 '22 at 01:34
  • 4
    Show me a device with an "accurate" internal clock and after a few months I'll show you how the clock in that device no longer displays the correct time. @vidarlo I've never seen a device that will display its system time where you cannot manually set the system time. So that's how you would tell the devices what time it is. It's about the same amount of work as telling all of your devices what their NTP servers are. – Todd Wilcox Nov 08 '22 at 04:03
  • @ToddWilcox or even more work... hence my question. – vidarlo Nov 08 '22 at 08:35
  • @vidarlo I’ve worked with more than 1000 network devices and servers over the last 25 years. I’ve never found it very much work to set the system time on any of them, and it’s always been more work to configure NTP. Which doesn’t mean I didn’t configure NTP. It’s just to say I don’t understand your question. Setting system time on devices and servers is super easy. In some cases, NTP won’t even work if the system time isn’t close to the time at the time source. – Todd Wilcox Nov 08 '22 at 08:40
  • Because internal clock are not accurate. They are precise, but not accurate. Precision is being able to measure time down to fractions of a millisecond. Accuracy is knowing that 2:00am on December 1 2022 is actually 2:00am – slebetman Nov 09 '22 at 07:58

7 Answers7

30

Internal clocks are only so accurate. With an uptime of months or sometimes years, your nodes can drift considerably from correct time. Also, some nodes lack a battery-powered RTC, so they default to some point in time on bootup and need to be set somehow. Incorrect time may cause confusion and even break some protocols.

NTP can provide accuracy within a few milliseconds, so if you e.g. analyze logs from various sources the time stamps will match very nicely.

Of course, you can use alternative protocols for synchronization, with more or less precision. Keeping the clocks manually on dozens or even hundreds of nodes does not look like a viable option.

Zac67
  • 84,333
  • 4
  • 69
  • 133
  • 3
    Now if only the designers of those battery-less devices would set things up to be able to run ntpd -g (the just set the clock whatever the difference option) at boot... – Chris H Nov 08 '22 at 15:42
  • @ChrisH Now if only NTP didn't have a bunch of dependencies, like network... – Aron Nov 09 '22 at 06:31
  • @Aron, of course, but the use cases here tend to be inherently networked and the example that jumped to mind was a NAS drive that broke the timestamps on a backup after a power cut. Network can include cellular which gives you the time on connection (guessing here but NTP to the base station then part of the GSM or later protocol). Without network you could use GPS to set your RTC, but that depends on putting an antenna somewhere useful. In some places there's a good broadcast radio time service - my watch uses the UK one for example. – Chris H Nov 09 '22 at 06:57
26

Your question is based on a number of inaccurate assumptions.

First off, not all systems actually have an internal clock. The Raspberry Pi is a trivial example of such a system, but there are many others out there. These systems can generally maintain some semblence of accurate time while running, but they can’t maintain time while turned off. Such systems need some way to figure out the time when they start up, and it needs to be possible to do so automatically.

Secondly, many systems don’t actually keep exceptionally accurate time. RTCs typically found in modern systems are accurate to somewhere within the 1-5ppm range. Worst case, this is about 0.425s of drift in 24 hours. That’s actually not horrible, and quite often most systems can keep even more accurate time while running. But these numbers are not guarantees, are almost never constant, and need to be measured against some external standard to be properly quantified and compensated for. Furthermore, it’s not unusual for even more accurate time to be required for network protocols to work correctly.

Thirdly, even if you ignore the above two points, you have to get the clock set accurately in the first place for it to be accurate. Humans cannot do this very well by hand (most people can manage no better than about 5-10 seconds of accuracy when setting a clock by hand), so there needs to be some way to set the time properly in the first place. This becomes even more important when dealing with large numbers of systems because of the second point above. If you need accurate time across more than about a dozen systems, you generally need some way to set the time on all of them at the same time, or some way to have them synchronize automatically.

  • To add to your point about not all systems having an internal clock, I'm reminded of the important thing a clock that runs when the device isn't powered needs to keep time - it needs a battery. That can become an issue when the battery dies, as it famously did with Pokemon Gold and Silver. – Alexander The 1st Nov 08 '22 at 09:52
  • Worse than about 1s setting by hand is either a poor UI or user error - take a typical Casio digital watch from any time in about the last 40 years, wait for your master clock to tick round to the top of the minute, and press the button to zero the seconds - you match to better than a human reaction time because of the rhythm – Chris H Nov 08 '22 at 15:44
13

A slightly different perspective than the other answers, in the context of information security.

We do not really care about how time is precise. What we want to make sure of is that time is the same everywhere and that this commonality derives from a single source of truth.

NTP is great for that - you set the "true time"* in one place, and then you have it maintained everywhere.

This is particularly important in time-sensitive services (where clocks must not differ by X seconds, but whether they are precise vs the world is not that important). The other typical case for homogenous time is system/services logs that must be correlated, and it is almost always done based on time.

Finally, you ultimately want to synchronize with a commonly agreed standard outside your company (typically ntp.org) because you can be asked to provide logs for a certain time period, and this is one of the most frustrating exercises.
If you have the capacity to answer with logs time-stamped against this standard reference you cut short a lot of discussions.

* this can be for instance the administrator's wristwatch time

WoJ
  • 243
  • 1
  • 7
7

Leap seconds

Nobody likes them, but they are a part of UTC, so if you want your clock to be in UTC ( to be able to have the same timestamps as everybody else on the internet uses ) rather than TAI, you need a mechanism to keep track of them. NTP is one of the options.

Strictly speaking if you are moving fast or are at unusal distances from the earth gravity well your clock might also drift more than allowed from TAI/UTC

PlasmaHH
  • 171
  • 4
4

If your device has an internal atomic clock, naturally you don't need it

NTP servers derive their times from atomic clocks, which are accurate to 1 second in 300 million years.

Most devices take their timing from crystal resonators. A really good crystal might be accurate to a millionth of the stated frequency. There are 31536000 seconds in a year. That means your crystal gains or loses 31.5 seconds over a year on average. In normal commercial equipment like PCs, the crystal is unlikely to be that good (because you pay more for better components) and it's likely to be 10 times that error.

If your device has its own atomic clock then sure, you don't need regular updates from an NTP server. With a regular PC though, you're probably going to want more accuracy than that.

Or do it yourself

Of course there are alternatives. NTP didn't always exist. There's nothing stopping you resetting the PC's time at reasonable intervals, and that's what we always used to do, back in the day. If you've got internet access though, it's way more convenient to have the PC do it automatically.

Graham
  • 141
  • 1
  • 4
    Even if you have an atomic clock (or, equivalently, a reliable GNSS signal, or some other PPS source), you still have to figure out what time it is supposed to be in the first place, because those can only indicate the passage of time, not the actual time. – Austin Hemmelgarn Nov 07 '22 at 02:22
  • 1
    @AustinHemmelgarn GNSS supplies a very accurate absolute time in UTC (derived from International Atomic Time (TAI)) so there’s no need to figure out what time it is. Just about every enterprise/telecoms grade NTP server on the market these days uses GNSS as a source of time, and the internal atomic oscillators (usually rubidium) are used to holdover the clocks should the GNSS signal be lost. – Darren Nov 07 '22 at 07:43
  • @Darren Depends on whether you’re actually parsing the GNSS data, or just taking a PPS signal from the transceiver. A lot of home setups take the second option, not the first. – Austin Hemmelgarn Nov 07 '22 at 12:58
  • @AustinHemmelgarn If you're just spewing out 1PPS, it's not an NTP server. Even if you are outputting ToD but it is hand-set and you've just used the GNSS to keep the time sync accurate (why???) it's certainly not a stratum 1 NTP server traceable to UTC, and shouldn't be claiming as such. – Darren Nov 07 '22 at 14:29
  • The best atomic clocks are even accurate to 1 second in 15 billion years. – PlasmaHH Nov 07 '22 at 15:18
  • 1
    Please also note that at least the GPS time is not following UTC exactly, there is currently a difference of 18 seconds (it is tied to TAI -19 seconds). GST is TAI exactly, not sure about other systems. – PlasmaHH Nov 07 '22 at 15:31
  • 1
    @Darren I’m not claiming it would be, and my comments above were not intended to be about NTP servers, they were addressing the first part of the answer about not needing any external time reference if you have an atomic clock. – Austin Hemmelgarn Nov 07 '22 at 15:57
  • @AustinHemmelgarn OK. It seemed like it was a direct response to my previous comment due to the mention. – Darren Nov 07 '22 at 16:28
  • 1
    Even if you have an atomic clock and synchronized it, it will start to disagree with other atomic clocks due to differences in altitude and gravity. If you want to have standard time, you need to communicate with other timekeepers. – Nayuki Nov 07 '22 at 20:03
  • @PlasmaHH the GPS signal contains information about UTC-GPS time difference and leap seconds. – Åsmund Nov 09 '22 at 09:31
2

NTP server can set the correct/exact time to more than one device. This is very important when you are working with systems that depend on the correct time.

If there is an internal clock it also needs to have starting value, someone has to enter the time at some point. How accurate can that entry be?

I saw a video Why is this PCIe Card RADIOACTIVE? some time ago and I think that it explains very well why exact time is important in specific scenarios.

KWriter
  • 121
  • 2
  • Is the information of the video already summarised in your answer? It’s not really clear to me whether the video is supportive, auxiliary or additional information. (Disclaimer: I am not able to view the video.) – MisterMiyagi Nov 08 '22 at 06:25
  • Yes, it covers one aspect - the performance of systems if they are kept in time sync. Here is part of the video description:

    By using an Atomic Clock the clocks between different computers can be synced to within a dozen nanoseconds, and with that performance can sky rocket.

    Check out the Open Compute Project: https://www.opencompute.org/ Build your own Time Card: https://github.com/opencomputeproject/Time-Appliance-Project

    And here is forum thread about this video: https://linustechtips.com/topic/1367776-why-is-this-pcie-card-radioactive/

    – KWriter Nov 08 '22 at 06:38
2

In addition to the many cases already mentioned (clocks not really that accurate, startup time, etc.), I've seen many cases of VMs (virtual machines) which keep reasonably accurate time... until the VM is paused, for instance for maintenance, to move it to another host, or other similar operations.

Then when the VM resumes, it continues to keep track of time... As if that interruption wasn't there. A pause of 5 minutes? The VM is now 5 minutes late! I've seen VMs with an hour or two of lag following maintenances. You definitely want NTP to fix that ASAP...

jcaron
  • 783
  • 3
  • 9
  • Fair point. Actually experienced that myself when our mail log jumped back and forth during backup - the dumb ntp implementation on ESXi was broken and needed resetting. And obviously, we set up better monitoring of the hosts. – Zac67 Nov 09 '22 at 18:18