Question

I am trying to measure the time elapsed between a message being sent from one machine and it being received by another. Initially I am measuring this in a network of EC2 instances. The EC2 instances are time synchronised using NTP. I am taking the system time of the sending machine when it sends the message and subtracting it from the system time of the receiving machine when it receives the message. I am unsure of the accuracy of this method; sometimes I get odd results, i.e. negative numbers. I am presuming that the problem is the accuracy of the time synchronisation. Does any one have a better approach that is more accurate at measuring elapsed time between machines? Note: I do not want to measure round-trip time, as due to the specifics of the protocol that would not be useful in terms of what I need to measure.

Was it helpful?

Solution

Proper calculation of the elapsed time can only be done safely by means of "ntp schemes":

For this purpose messages have to be send back and forth. This way you can compute a round-trip delay time and the offset. The round-trip delay is computed as

delta = (t_3 - t_0) - (t_2- t_1)

where

t0 is the client's timestamp of the request packet transmission,
t1 is the server's timestamp of the request packet reception,
t2 is the server's timestamp of the response packet transmission and
t3 is the client's timestamp of the response packet reception. 

Therefore

t3 − t0 is the time elapsed on the client side between the emission 
        of the request packet and the reception of the response packet and
t2 − t1 is the time the server waited before sending the answer.

The offset theta is given by

theta = ((t_1 - t_0) + (t_2 - t_3))/2

The synchronization is correct when both the incoming and outgoing routes between the client and the server have symmetrical nominal delay. If the routes do not have a common nominal delay, the synchronization has a systematic bias of half the difference between the forward and backward travel times.

There has to be a two way communication to allow synchronization. Knowing the offset will allow to calculate the time elapsed between a message being sent from one machine and it being received by another.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top