Sincronización de reloj en una red con retrasos asimétricos.

38

Assume a computer has a precise clock which is not initialized. That is, the time on the computer's clock is the real time plus some constant offset. The computer has a network connection and we want to use that connection to determine the constant offset B.

El método simple es que la computadora envía una consulta a un servidor horario, señalando la hora local B+C1 . El servidor horario recibe la consulta en un momento T y envía una respuesta que contiene T al cliente, que la recibe en un momento B+C2 . Entonces B+C1TB+C2 , es decir, TC2BTC1 .

Si el tiempo de transmisión de la red y el tiempo de procesamiento del servidor son simétricos, entonces B=TC1+C22 . Hasta donde yo sé,NTP, el protocolo de sincronización de tiempo utilizado en la naturaleza, opera bajo esta suposición.

¿Cómo se puede mejorar la precisión si los retrasos no son simétricos? ¿Hay alguna manera de medir esta asimetría en una infraestructura típica de Internet?

Gilles 'SO- stop being evil'
fuente
2
There is a related patent but who wants to read those...
Raphael
@Raphael Thanks. More friendly Google link to US patent 7602873, official USPTO link.
Gilles 'SO- stop being evil'
First thoughts: It's probably impossible with 2 entities. Using (n2) pairs of n entities a better synchronization is likely possible. Then the clocks can be used to measure one-trip times.
rgrig
can you clarify the application/context or is this mainly a theoretical question?
vzn

Respuestas:

10

Inability to measure asymmetry

No, you can't measure the asymmetry. Consider these two communication diagrams, the first with a negative clock offset and equal delays and the second with no clock offset and entirely asymmetric delays (but the same round trip time).

communication diagram

The important thing to notice is that, from the perspective of both the PC and the server, the two interactions are exactly identical. They receive messages at the same time. They send messages at the same time.

You can create more cases by 'grabbing' the PC timeline and 'sliding' it, holding the message send/receive points fixed relative to their respective timelines. The asymmetries you cause are exactly negated by the clock offset. In fact, you can even make messages go BACKWARDS IN TIME one way (as long as the round trip time is still the same) and the server/client STILL can't tell!

Therefore it is impossible to measure latency asymmetries. In the worst case, where you have no information other than that one way latencies are positive and sum to the round trip time, the accuracy of clock synchronization is limited to the round trip time.

Can intermediate infrastructure help?

Whether or not the intermediate infrastructure can help will be heavily dependent upon your theoretical model of the situation.

If the asymmetry is constant and the intermediate infrastructure is the routers on the communication path between you and the server, then no. Even if each router synchronized their clock with the adjacent router, the errors would compound in the same way as if you had synchronized with the server via communication across the routers.

In the real world you can rely on delays being somewhat symmetric for architectural reasons, repeated synchronizations to reduce asymmetry due to queuing delays (etc), and multiple communication paths to reduce other sorts of asymmetry.

If you put your model's assumptions somewhere in between (because it's interesting to explore model space, of course) I expect the result should also be somewhere in between.

Craig Gidney
fuente
This should be an answer to your question. Here I'm asking about a more concrete setting, where we may get help from the underlying infrastructure.
Gilles 'SO- stop being evil'
I added more content for you.
Craig Gidney
this appears to me to be wrong & it can be seen by noting that while the PC send and receive times are the same (upper timeline events coincide in the two cases), the server times are different (lower line in the two cases) & therefore the formula computed by the NTP client is different in the two cases. this can be understood better by labelling the NTP values for t1,t2,t3,t4 in each case (where t2,t3 are values recorded in server time and sent back to client). as in my answer, the NTP time protocol can indeed measure and adjust for (t1t0)(t3t2)
vzn
@vzn The server times with respect t messages are the same in both examples. The server's timeline moving to the left represents the starting clock drift being different. The effects of initial clock drift and latency asymmetry happen to be equivalent, so adjusting them both in opposite directions allows the resulting behavior to be equivalent.
Craig Gidney
further study, the client/server can tell when their clocks are far out of sync at least outside the round trip time. more info in the polycos et al ref I cite below where they measure different "unidirectional latencies" larger than the NTP uncertainty (which seems to be less than round trip time to NTP servers— ie ~10ms)
vzn
2

Consider a network of time servers known to be synchronous, θ={A,B,C}, and a client machine P.

Let TXY be the one way time of flight from machine X to machine Y, with the possibility that TXYTYX.

Let ΔXY=|TXYTYX| be the measure of the asymmetry between machine X and Y.

Now, consider that the asymmetry between two synchronous machines can be measured by having the synchronous machines agree to send a one way message to each other at the same time. The difference in the arrival times is Δ between those machines, i.e.:

ΔAB=|TABTBA|

ΔBC=|TBCTCB|

ΔCA=|TCATAC|

can be measured.

Now consider the time of flight of circuits:

PABP, denoted by CAB,

PBAP, denoted by CBA.

CAB=TPA+TAB+TBP

CBA=TPB+TBA+TAP

Consider the client machine P to initiate both of these circuits simultaneously, and measures the difference in arrival times, x:

x=CABCBA=ΔPA+ΔAB+ΔBP

Both x and ΔAB are known by previously mentioned measurements, so moving the unknowns to the left hand side:

xΔAB=ΔPA+ΔBP

Similarly, for {CAC,CCA} and {CBC,CCB} it can be shown that:

yΔBC=ΔPB+ΔCP

zΔCA=ΔPC+ΔAP

Inspecting carefully, we note that ΔXYΔYX. The left sides contain values known from measurements, the right sides contain 3 unknowns in 3 equations.

Solving simultaneously,

ΔAP=r+st2

ΔBP=rs+t2

ΔCP=tr+s2

where,

r=xΔAB

s=yΔBC

t=zΔCA

Bingo
fuente
How does this circumvent the problem my answer and others have?
Raphael
Well, for one l am using 3 timing serves, not one. And it requires something like 12 messages to be sent - 6 to find the asymmetry between the time servers and 6 to find the asymmetry between the client and the servers. It is not a 1-dimensional solution space because the comprison is between 3 servers and not one. And it does not assume time can go backward.
Bingo
It does rely heavily on 3 perfectly synchronised time servers, the synchronisation of which is left as an exercise for the reader. ^^
Bingo
@Raphael l think l understand your comment now. Time shifting doesn't work because it is more constrained. eg. Time shifting A w.r.t. P doesn't just affect the time between A and P but also the circuts PACP,PABP,PBAP,PCAP, the differences of which are measured and factored into the calculation. Maybe I am still wrong? Not sure :P
Bingo
0

If you only control the endpoints. You can't. See Craig's answer.

Even if you add more machines and a more complex set of computers, like in Bingo's answer, you can reduce to just to machines making the synchronized ones have instantaneous access to the others (delay TXY = 0).

Notice that if you do TAB=TBC=TCA=0, you get ΔAP=ΔBP=ΔCP=0.

So what's wrong? x=CABCBA=ΔPA+ΔAB+ΔBP

ΔPA=|TPATAP|, not ΔPA=TPATAP

And if you use the second, then you can not use the assumption ΔXYΔYX (and if you don't use this, your final equations cancel each other).

So, what can you do? Send a really good clock through mail. ;)

Or, if you have control over all nodes between them, you can check the time to process each packet and calculate the delay between each consecutive pair, that should be symmetrical, if they use the same physical medium both ways.

You may need to account for general relativity, and remember that simultaneity doesn't exist.

Luiz Afonso
fuente
“You may need to account for general relativity” No, I don't. I'm perfectly fine with a solution that only works if all the clocks involved are in a fixed frame. There is relativity in a distributed system, but it comes from network latency, not from physics. Its mathematics are completely different.
Gilles 'SO- stop being evil'
-1

NTP actually uses 4 time measurements t0,t1,t2,t3 to compute the "offset". they are the "time points" in the round trip of the packet from client to server back to client but can be regarded as time offsets. its assumed that the time offset can be off between client and server but that both can count local elapsed time offsets accurately.

the client after receiving the return packet has all 4 values and computes the actual offset. once the relative offset is calculated between client and server, the "absolute time" offset can be synchronized ie the client can accurately estimate the servers exact offset measured wrt its local time offset, ie the "delta".

t0 = time [offset] sent at client
t1 = time [offset] recd at server
t2 = time [offset] sent at server
t3 = time [offset] recd at client

the actual formula is θ=(t1t0)+(t2t3)2

note this formula can handle the case where the time from client to server t1t0 is not the same as from server to client t3t2 (either shorter or longer).

on networks, delay time is due to two major factors, mainly latency and bandwidth.

  • latency is the brief delay in routers on sending new [small] packets and is roughly a different constant at each router. it can be measured with the traceroute utility.
  • bandwidth is the rate at which large amts of data can be sent eg "upload vs download time" and can also be measured by remote "bandwidth measuring" web sites.

in many modern home/business internet connections the upload rate is much smaller than download rates & this would probably affect the t1t0 vs t3t2 difference whereas latency may be small or somewhat similar between client-to-server and server-to-client.

a basic algorithm to improve accuracy of calculating the offset used in NTP (and can correct for some degree of random network latency) is to repeat the process multiple times and use the "apex of the wedge scattergram". this can be seen on the "clock filter algorithm" on slide 10 of this PPT on NTP by David Mills. see also clock filter algorithm by Mills. (note it can still be employed between a single server and client although the general code is written to allow multiple servers.) this is part of the "mitigation algorithms" described in NTP architecture & algorithms.

vzn
fuente
1
The question is specifically about the case where the latency is not symmetric. Taking multiple measures won't tell you anything about the constant component in the asymmetry.
Gilles 'SO- stop being evil'
the question does not actually contain the word "latency". if you want to sketch out what case you actually have in mind in math form instead of words esp wrt the real NTP formulas, it would certainly help. the formulas & algorithms can indeed measure/handle/cover various cases of "latency" and "asymmetry".
vzn
C1 and C2 are the latency values (I called them “delay”, the two words are synonymous in this context).
Gilles 'SO- stop being evil'
C1 and C2 are influenced by latency but are not really equal to it. in a sense the scattergram actually plots latency....
vzn
note (maybe its not totally obvious in above acct) the t1,t2 server values are sent in the return packet from server to client.
vzn
-3

If only we could send packets back in time

enter image description here

B=Tf+TbTf2C1+C22

Assumptions:

(B+C2)Tb=Tf(B+C1)

Tf(B+C2)=(B+C1)Tb

Pratik Deoghare
fuente
1
This clever solution is ruled out by the assumption of a “typical Internet infrastructure”.
Gilles 'SO- stop being evil'
1
@Gilles I know. :D
Pratik Deoghare
-4

Here is an idea that sounds absolutely convincing to me and might therefore be absolutely wrong in a dumb way.

Consider the following scenario. We have two nodes N1 and N2 with clocks C1 and C2, respectively. For sake of simplicity, let us assume that the clocks run with the same speed; we denote their difference by δ=C1C2 which is constant for our purposes. Let us furthermore assume that transmission delays d12 and d21 are constant¹.

Have N1 send a message timestamped with T1m to N2 and let T2r the current time on C2 upon receiving it (do the same for the other direction). In addition, measure round trip time (on either node) D by sending a message back and forth. Now set up this equation system:

T2rT1m=d12+δT1rT2m=d21δD=d12+d21

As this system consists of three equations, has three unknowns and we know there is a solution, it can be solved. Of course the nodes have to exchange their measurements so that they can both compute the same value for δ (if necessary).

1] I think the assumptions are natural and necessary. They can be justified with the hope that the respective quantities do not change too much for the duration of our synchronisation attempt.

Raphael
fuente
(d12+δ)+(d21δ)(d12+d21)=0. There are three equations and three unknowns, but the family of solutions is 1-dimensional. It's the same problem we had with Ran's now-deleted answer and briefly discussed in chat: time is relative; we can't distinguish between delays in transmission and skewed clocks.
Gilles 'SO- stop being evil'
@Gilles Too bad. We should probably leave one instance of the fallacy for all to see?
Raphael
1
I can restore the wrong answer I wrote. It might be useful due to the comments made by Gilles.
Ran G.