How to set a machines clock using time stamps and round trip time

79 Views Asked by At

A machine synchronizing with a single time server records the timestamps and round trip times from it. How would you know from the timestamps and round trip times which of the times you should use to set the clock? What time should the machine set its clock to? How would you approximate the accuracy of the setting?

1

There are 1 best solutions below

0
On

I'll use an example to illustrate how you can do this.

Let your machine M have a clock ahead of time server S by x=50ms. The job is for M to figure out this 50ms. Further assume network delay is d=10ms.

  • At time 1000 M thinks the time were 1050. It sends 1050 out to S.
  • At time 1010 S receives the message, and sends back its current time 1010.
  • At time 1020 S thinks the time were 1070, and it receives the message containing 1010.

Now M sets up two equations:

  • (1050-x)+d = 1010 // M sends message at (1050-x); arrives S with delay d.
  • 1070-x = 1010+d // M receives message at 1070-x, which was 1010 plus delay d.

By solving the equations, M knows its clock is ahead by x=50ms.