Wilbert's website at SocSci

> Computer> Clock Sync

computer/clockSync.html 2014-09-18

Clock synchronization

Most computer operating systems offer to synchronize the clock with some external source automatically. They use either NTP or SNTP for this. Unfortunately most OS'es do this only once at boot time by default. Bad clock sync can lead to several problems.

Difference with filesystem

For a computer that is on for several weeks this leads to problems with make such as:

make: Warning: File `xxxxxxxx.xxx' has modification time 6,1 s in the future

This leads to errors in the building of compiled software (C++) and similar problems in the running of automatically compiled software (Python).

Test your filesystem lag (or probably more accurately, your computer lead) with the following script: clocktest.py. Run it in a command window while the current directory is on a filesystem that is on the network.

Clock drift during an experiment

Computer clocks are bad. Typically they drift a second per day. This means that within a minute after starting your experiment, you loose millisecond accuracy.


Ubuntu help has a very good solution for this one. Note that the once a day update will not get you better than second accuracy. Do not use this. Make sure to use a local server such as ntp1.science.ru.nl. Solutions for other Linuces, BSD, Mac OS X, Solaris and AIX are similar. Next chapter describes the precise steps.

Microsoft does not offer a solution with better than 2 second resolution. But you can use third party software

Network Time Protocol


 sudo apt-get install ntp

Edit /etc/ntp.conf:

 # enable statistics
 statsdir /var/log/ntpstats/
 # The Science Faculty stratum 2 time server server is the closest source.
 server ntp1.science.ru.nl
 # We broadcast this time as stratum 3 server locally.
 # This ip-address is the broadcast address of eth0, the sled network
 sudo sudo /etc/init.d/ntp restart

Wait a few hours and test the time offset.

 set xlabel "time since midnight (s)"
 set ylabel "offset (s)"
 plot '/var/log/ntpstats/peerstats' u 2:5
Or to get the offset from just the science faculty server:
 grep 131.174 /var/log/ntpstats/peerstats > /tmp/peerstats
 set xlabel "time since midnight (s)"
 set ylabel "offset (s)"
 plot '/tmp/peerstats' u 2:5

The Microsoft Windows 7 implementation of NTP is only [http://support.microsoft.com/kb/939322 accurate to 2 s]. Install [http://www.meinbergglobal.com/english/sw/ntp.htm#ntp_stable Meinberg NTP] for better performance.