Hacker News new | ask | show | jobs
by bradknowles 11 days ago
Years ago, I wrote a document on support.ntp.org that laid out the math for how NTP servers are chosen, and how many upstream time servers you need to protect yourself from a given number of falsetickers. That article seems to have gone by the wayside, otherwise I would refer you to it.

However, during my time working on the EC2-Chronos team that managed all NTP time servers for all of AWS and Amazon worldwide, in every single region, availability zone, and datacenter, I learned the old rules aren’t quite right.

Ultimately, the NTP algorithm works something like this:

1. Get a statistically significant set of time samples for each upstream time server. That will give you a range of time that it looks like the upstream time server is sending to you, and what you can’t really control is the latency, jitter, wander, etc… that is induced by the network between you. You can measure and account for some of what the network does to you, but not all of it. That’s why you get error bars back.

2. Take the median for each upstream time server, plus the error bars, and plot that on a line. Fastest at one end, slowest at the other.

3. Do some calculations to figure out what the median value is for all of these time servers.

4. If you have more than a selected number of servers on that line, it selects the one that is furthest from the median and throws it out.

5. Then recalculate the new median. If you are now down to three timeservers on that list (or whatever you have configured), then take the one closest to that median and it becomes your SYSPEER. That’s the server you will sync yourself to, since it seems to have the best idea of what the “real” time should be.

6. If you still have servers that can be “voted off the island”, then go back to step #4.

7. Periodically re-evaluate the servers you have configured and which one should be your new SYSPEER.

Now, this assumes you don’t have a local refclock attached (e.g., GPS). If you do, then you probably “PREFER” it over everyone else.

The idea here is that each server that gets voted off the island is potentially a false ticker that is trying to get you to choose the wrong SYSPEER. So, make sure you have enough extra servers defined in your configuration file to survive having a number of falstickers and still get to the right answer. Or, at least one that is close enough.

Historically, the limit was ten upstream timeservers. Any more than that, and `ntpd` would still monitor them, but wouldn’t use them for selecting a SYSPEER. You could monitor up to about 600 upstream timeservers this way, and IIRC, this is actually how the early versions of the NTP Pool operated. You can now adjust how many time servers you want to use for that consideration, but if everyone did this, then it would be chaos. So, you do need to restrict yourself to a reasonable number of upstreams.

More recent NTP servers (e.g., Chrony) will actively use a more upstreams if you configure them, but again you should be courteous to your neighbors and not abuse this feature.

Another trick you can use is to select numbered time servers inside of each NTP Pool zone. So, not just “us.pool.ntp.org”, but also “0.us.pool.ntp.org” and “1.us.pool.ntp.org” and “2.us.pool.ntp.org” and “3.us.pool.ntp.org”. If you were to choose all five of these names, each one will come back with multiple IP addresses, and you should have way more upstream time servers defined than you will ever need.

You should also choose upstream servers and zones that are relatively close to your topological location, where possible. So, don’t choose any upstream servers in Europe or Asia, if you are located in the US. And so on.

Some vendors have signed up to have their own subdomains under the NTP Pool. So, you could add them as time servers for your machine, if you’re on one of those platforms. And they usually have numbered subdomains as well.

If you are an Amazon or AWS customer, then you can also use time.aws.com as one of your upstream time servers. That service was designed to serve all Amazon and AWS customers, worldwide. Every Kindle. Every Alexa device. Every Ring camera. And there are numbered subdomains under time.aws.com, too. I made sure those were created, based on my own experience in helping to set up the NTP Pool and in talking to Ask Bjørn Hansen.

Of course, Apple and Google run their own time server infrastructures. So, you can use them, as well as the NTP Pool. And plenty of other vendors also run their own time server infrastructures.

I’ve been doing this off and on for over twenty years. I can keep going, if you want. Feel free to ask me anything related to NTP.

1 comments

Could you please shed some light on why EC2 instances are recommended to sync to the single link-local address (say, I care only about EC2 instances without PTP for now)? I presume that traffic never leaves the hardware node, and since underlying HW needs precise enough time, it just serves that time downstream to the instance.
So, on EC2 nodes, the internal Stratum-2 servers provide time to the NTP client on the hypervisor card. From there, it is provided via the link-local address to the EC2 instances. That’s the best quality of time sync that you could possibly get to those instances. The Stratum-1 servers inside the AWS network in each availability zone are providing the signal to the Stratum-2 distribution servers, and those Stratum-2 distribution servers are what feed the hypervisors across all regions, all availability zones, and all datacenters.

On the newer instances, your local NTP client could also be configured to receive a 1PPS signal from the hypervisor card, and in that case you can get an SLA of 20 microseconds or better from “true time”. For these systems, there are Stratum-1 servers within the same datacenter as the hardware where your instance is running. That’s what allows AWS to run a custom fabric for 1PPS signals that is very high fidelity, low jitter and wander, etc….

Older instances aren’t running on hardware that has access to that proprietary fabric where 1PPS is transmitted with very high fidelity, and so there is no 1PPS signal that can be fed to your instance. In that case, you get an SLA of one millisecond (or better).

Either way, this is at least an order of magnitude better than you can get from any other source, since that source would have to be from outside of the AWS network. You might be able to get yourself down to single-digit millisecond accuracy, but still not down as low as you can get from AWS if you just use the link-local service.