Skip to content

tech0ver/Network-Time-Protocol0ver

Repository files navigation

NTP

Demo of Network Time Protocol using Vagrant and chrony, with watchers written in Java, Go, Python, and JavaScript.

What it shows

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).

Watchers

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

  1. Install VirtualBox
  2. Install Vagrant
  3. Check versions:
     vagrant -v
     VBoxManage -v

Run

  1. Start VM:
    vagrant up
  2. SSH into it:
    vagrant ssh
  3. Attach to a watcher screen session:
    screen -r java  # or: go / py / js
    Example output:
    Java 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...
    
  4. Cleanup:
    vagrant destroy -f

About

About Network Time Protocol (NTP)

Resources

License

Stars

Watchers

Forks