准确测量机器之间的经过时间

时间:2014-01-12 18:48:11

标签: time amazon-ec2 ntp

我正在尝试测量从一台计算机发送的消息与另一台计算机正在接收的消息之间经过的时间。最初我在EC2实例的网络中测量它。使用NTP对EC2实例进行时间同步。我在发送消息时占用发送机器的系统时间,并在收到消息时从接收机器的系统时间中减去它。我不确定这种方法的准确性;有时我得到奇怪的结果,即负数。我假设问题是时间同步的准确性。有没有人有更好的方法来测量机器之间的经过时间?注意:我不想测量往返时间,因为协议的细节对我需要测量的内容没有用。

1 个答案:

答案 0 :(得分:0)

正确计算经过的时间只能通过“ntp计划”安全地完成:

为此目的,必须来回发送消息。这样您就可以计算往返延迟时间和偏移量。往返延迟计算为

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

,其中

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. 

因此

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.

偏移θ由

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

当客户端和服务器之间的传入和传出路由都具有对称的标称延迟时,同步是正确的。如果路线没有共同的标称延迟,则同步系统偏差为前进和后退行程时间差异的一半。

必须进行双向通信才能实现同步。知道偏移量将允许计算从一台机器发送的消息与另一台机器正在接收的消息之间的时间elapsed