Demo of Network Time Protocol using Vagrant and chrony, with watchers written in Java, Go, Python, and JavaScript.
Inside the VM we manually shift the system clock forward by ~120 seconds.
Then chrony synchronizes back to real network time, performing a backward step.
The watchers continuously compare:
wall(system clock, subject to jumps)mono(monotonic clock, never jumps)
You will see a large positive delta (manual forward step), followed by a large negative delta
(chrony correcting the clock back).
Each watcher prints the difference between wall clock (subject to NTP steps) and monotonic clock (steady). Different languages expose these via different APIs:
| Language | Wall clock method | Monotonic method |
|---|---|---|
| Java | System.currentTimeMillis() |
System.nanoTime() |
| Go | time.Now() |
time.Since(start) / time.Now().Sub() uses monotonic component |
| Python | time.time() |
time.monotonic() |
| JavaScript | Date.now() |
performance.now() (from perf_hooks) |
- Install VirtualBox
- Install Vagrant
- Check versions:
vagrant -v VBoxManage -v
- Start VM:
vagrant up
- SSH into it:
vagrant ssh
- Attach to a watcher screen session:
Example output:
screen -r java # or: go / py / jsJava watcher: printing deltas; waiting for backward step... Δwall=1276 ms, Δmono=1275 ms Δwall=121041 ms, Δmono=1041 ms Δwall=1014 ms, Δmono=1013 ms OK: wall BACKWARD 118980 ms | Δwall=-118980 ms, Δmono=1004 ms. Exit. [java] Done. Press ENTER to exit... - Cleanup:
vagrant destroy -f