Skip to main content

4. Sample Processing and Selection Operations

At the very heart of the NTP design are the algorithms used to improve the accuracy of the estimated offsets and delays between the host and its various peers, as well as those used to select a particular peer for synchronization. The complexity of these algorithms depends on the statistical properties of the transmission path and the accuracies required. In the case of LANs operating at megabit speeds and above the path delays are usually smaller than the required accuracies, so the raw offsets delivered by the receive procedure can often be used directly to adjust the local clock. However, in the case of paths involving many network hops via regional and backbone networks such as NSFNET, the path delays and delay variances can be much larger than acceptable without further processing.

Since Internet paths often involve multiple hops over networks of widely varying characteristics, it is not possible to design one set of algorithms optimized for a particular path. Therefore, the development of algorithms appropriate for ubiquitous Internet application has involved a process of stepwise refinement, beginning with the designs suggested in [MIL85a], refined as the results of experiments described in [MIL85b] and [MIL89b] and evolved over several years of operation under widely varying conditions of path qualities and reliabilities. In following subsections the issues, approaches and designs of these algorithms are discussed.

4.1. Data Filtering​

A number of algorithms for deglitching and filtering time-offset data have been described previously, such as in [MIL85a], [HAL84] and [KOP87]. These fall in two classes: majority-subset algorithms, which attempt to separate good subsets from bad by comparing statistics such as mean and variance, and clustering algorithms, which attempt to improve the estimate by repeatedly casting out outlyers. The former class was suggested as a technique to select the best (i.e., the most reliable) clocks from a population, while the latter class was suggested as a technique to improve the offset estimate for a single clock given a series of observations.

After further development and experimentation using typical Internet paths, a better algorithm was found for casting out outlyers from a continuous stream of offset observations spaced at intervals in the order of minutes. The algorithm can be described as a variant of a median filter, in which a window consisting of the last n sample offsets is continuously updated and the median sample selected as the estimate. However, in the modified algorithm the outlyer (sample furthest from the median) is then discarded and the entire process repeated until only a single sample offset is left, which is then produced as the offset estimate. This algorithm was found to be more resistant to glitches and to provide a more accurate estimate than the unmodified one. It was used in the Fuzzball and Unix implementations for about two years until the end of 1987.

Figure 4. Offset vs Delay

Recent experiments have demonstrated an even better algorithm which provides higher accuracy together with a lower computational burden. The key to the new algorithm became evident through an examination of scatter diagrams plotting clock offset versus roundtrip delay. Recall that the roundtrip delay d_i and clock offset c_i are computed from the four most recently observed timestamps. Without making any assumptions about the delay distributions due to queueing delays for traffic in either direction along the path, but assuming the intrinsic frequency offsets of the host and peer clocks are relatively small, let d_0 and c_0 represent the delay and offset when no other traffic is present on the path and so represents the true values. The problem is to accurately estimate d_0 and c_0 from a sample population of d_i and c_i collected over a relatively long period.

Figure 4 shows a typical scatter diagram in which the points (d_i, c_i) are concentrated near the apex of a wedge defined by lines extending from the apex with slopes +0.5 and -0.5, corresponding to the locus of points as the delay in one direction increases while the delay in the other direction does not. From these data it is obvious that good estimators for (d_0, c_0) would be points near the apex.

Upon reflection, the reason for the particular distribution of points in the scatter diagram can be explained as follows. Packet-switching nets are most often operated well below the knee of the throughput-delay curve, which means the busy periods are relatively short and infrequent. In addition, the routing algorithm most often operates to minimize the number of packet-switch hops and thus the number of queues. Thus, not only is the probability that an arriving NTP packet finds a busy queue in one direction relatively low, but the probability of packets from a single exchange finding busy queues in both directions is even lower.

From the above discussion one would expect that, at low utilizations and hop counts, the points should be concentrated about the apex of the wedge and begin to extend rightward along the extrema lines as the utilizations and hop counts increase. As the utilizations and hop counts continue to increase, the points should begin to fill in the wedge as it expands even further rightward. This behavior is in fact what is observed on typical Internet paths involving ARPANET, NSFNET and regional nets.

These observations cast doubt on the median-filter approach as a good way to cast out offset outlyers and suggests another approach which might be called a minimum filter. From the scatter diagrams it is obvious that the best offset samples occur at the lower delays. Therefore, an appropriate technique would be simply to select from the n most recent samples the sample with lowest delay and use its associated offset as the estimate. Several experiments were designed to test this technique using measurements between selected hosts equipped with timecode receivers, so that delays and offsets could be determined independent of the measurement procedure itself. The experiments were performed over several paths involving ARPANET, NSFNET and local nets and using both median and minimum filters of varying lengths. The results show consistently lower errors for the minimum filter when compared with the median filter of similar length. Perhaps the most dramatic result of the minimum filter is the greatly reduced maximum error at the upper end of the throughput range [MIL89b]. Based on these data the minimum filter was selected as the preferred algorithm. Since its performance did not seem to much improve for values of n above eight, this value was chosen for use in the reference implementation.

In the reference implementation the clock filter procedure is executed upon arrival of an NTP message or other event that results in new delay/offset sample pairs. New sample pairs are shifted into an eight-stage shift register from the left end, causing old entries to shift off the right end. Then those entries in the register with nonzero delay are inserted on a temporary list and sorted in order of increasing delay. In case of ties an arbitrary choice is made. The delay and offset estimates are chosen as the corresponding values of the first entry on the list.

For subsequent processing and use in the clock selection algorithm it is useful to have an estimate of sample dispersion. A good dispersion estimate which weights samples near the apex of the wedge most heavily and is easily computable is simply the weighted sum of the offsets in the temporary list. Assume the shift register has n > 1 entries and the list contains m (0 ≤ m ≤ n) valid samples in order of increasing delay. If X_i (0 ≤ i < n) is the offset of the ith sample, then

si = |Xi - X0|    if i < m and |Xi - X0| < Dmax
si = Dmax otherwise

The dispersion estimate S is then

    n-1
S = ∑ si·v^i
i=0

where v ≤ 1 is a weighting factor and Dmax is an experimentally determined threshold adjusted to match typical offset distributions. The reference implementation use the values 0.5 for v and 65.535 for Dmax. The dispersion estimate is intended for use as a quality indicator, with increasing values associated with decreasing quality and given less weight in the clock selection algorithm. The sum of the total path dispersions to the root of the synchronization subnet is called the synchronizing dispersion.

In the hope that offset accuracy could be improved through the use of more than just the minimum-delay filter sample, experiments were made involving various types of averages weighted both by zero, first and second-order dispersion. The results using eleven peer paths measured over four weeks demonstrate little improvement over the simple method, which is now used in the reference implementation.

4.2. Peer Selection​

The single most important contributing factor in maintaining high reliability with NTP is the peer selection mechanism. When new offset estimates are produced for a peer or are revised as the result of timeout, this mechanism is used to determine which peer should be selected as the clock source. A good deal of research has gone into mechanisms to synchronize clocks in a community where some clocks cannot be trusted. Determining whether a particular clock is a truechimer or falseticker is an interesting abstract problem which can be attacked using methods such as described in [LAM78], [LAM85], [MAR85] and [SCH86].

In methods described in the literature a convergence function operates upon the offsets between the clocks in a system to increase the reliability by reducing or eliminating errors caused by falsetickers. There are two classes of convergence functions, those involving interactive convergence algorithms and those involving interactive consistency algorithms. Interactive convergence algorithms use statistical clustering techniques such as the fault-tolerant average algorithm of [HAL84], the CNV algorithm of [LUN84], the majority-subset algorithm of [MIL85a], the non-Byzantine algorithm of [RIC88], the egocentric algorithm of [SCH86] and the algorithm described below in this paper.

Interactive consistency algorithms are designed to detect faulty clock processes which might indicate grossly inconsistent offsets in successive readings or to different readers. These algorithms use an agreement protocol involving successive rounds of readings, possibly relayed and possibly augmented by digital signatures. Examples include the fireworks algorithm of [HAL84] and the optimum algorithm of [SRI87]. However, these algorithms require an excessive burden of messages, especially when large numbers of clocks are involved, and are designed to detect faults that have rarely been found in the Internet experience. For these reasons they are not considered further in this paper.

The basic principles guiding the design of the NTP clock selection procedure are based on maximum likelihood techniques and the experimental observation that the highest reliability is usually associated with the lowest stratum and synchronizing dispersion, while the highest accuracy is usually associated with the lowest stratum and synchronizing distance. A key design assumption is that truechimers are relatively numerous and represented by random variables narrowly distributed about UTC in the measurement space, while falsetickers are relatively rare and represented by random variables widely distributed throughout the measurement space.

OffsetDispersionResult
0,0,00,0,00,0,-
0,0,19,9,280,0,-
0,1,012,25,120,-,0
0,1,121,16,16-,1,1
1,0,021,16,16-,0,0
1,0,112,25,121,-,1
1,1,09,9,281,1,-
1,1,10,0,01,1,-

Table 1. Outlyer Selection Procedure

The NTP clock selection procedure begins by constructing a list of candidate peers sorted first by stratum and then by synchronizing dispersion via the peer to the root of the synchronization subnet. To be included on the candidate list the peer must pass certain sanity checks. One check requires that the clock selection for the peer must not be the host itself; otherwise, a synchronization loop would be formed. Another check requires that the dispersion be bounded by a value which insures that the filter registers are at least half full, which avoids using data from low quality associations or obviously broken implementations. If no candidates pass the sanity checks, the existing clock selection, if any, is cancelled and the local clock free-runs at its intrinsic frequency. The list is then pruned from the end to be no longer than a maximum size, currently set to five. Starting from the beginning, the list is truncated at the first entry where the number of different strata in the list exceeds a maximum, currently set to two. This particular procedure and choice of parameters has been found to produce reliable synchronization candidates over a wide range of system environments while minimizing the "pulling" effect of high-stratum, high-dispersion peers, especially when large numbers of peers are involved.

The final procedure is designed to detect falsetickers or other conditions which might result in gross errors. The pruned candidate list is resorted in the order first by stratum and then by synchronizing distance via the peer to the root of the synchronization subnet. Let m > 0 be the number of peers remaining in the list and let X_i be the offset of the ith peer. For each i (0 ≤ i < m) define the clock dispersion q_i relative to peer i:

    m-1
qi = ∑ |Xi - Xj|·w^j
j=0

where w ≤ 1 is a weighting factor experimentally adjusted for the desired characteristic (see below). Then cast out the entry with maximum q_i or, in case of ties, the maximum i, and repeat the procedure. When only a single peer remains on the list it becomes the clock source.

This procedure is designed to favor those peers near the head of the candidate list, which are at the lowest stratum and lowest delay and presumably can provide the most accurate time. With proper selection of weighting factor w, outlyers will be trimmed from the tail of the list, unless a few of them disagree significantly with respect to the remaining entries, in which case they are discarded first.

In order to see how this scheme works to cast out outlyers, consider the case of a host and three peers and assume that one or more of the offsets are clustered about zero and others are clustered about one. For w = 0.75 as used in the reference implementation and multiplying by 16 for convenience, the first entry has weight w_0 = 16, the second w_1 = 12 and the third w_2 = 9. Table 1 shows for all combinations of peer offsets the calculated clock dispersion about each of the three entries, along with the outcome. In the four cases where candidate 0 and candidate 1 disagree, the outcome is determined by candidate 2. Similar outcomes occur in the case of four candidates. While these outcomes depend on judicious choice of w, the behavior of the algorithm is substantially the same for values of w between 0.5 and 1.0.

Experience with this procedure shows it is vulnerable to frequent switching between peers, even if they have relatively low offsets and dispersions. Since switching can result in increased oscillator phase noise and increased polling rates, selection of a new peer is suppressed if its offset is less than the sum of the estimated maximum skew and stated precision of the host and peer clocks.