The NTP documentation says:
Under ordinariy conditions, ntpd adjusts the clock in small steps so that the timescale is effectively continuous and without discontinuities - http://doc.ntp.org/4.1.0/ntpd.htm
However, this is not at all what I have noticed in practice. If I manually change the system time backwards or forwards 5 or 10 seconds then start ntpd
, I notice that it adjusts the clock in one shot.
For example, with this code:
#!/usr/bin/env python
import time
last = time.time()
while True:
time.sleep(1)
print time.time() - last
last = time.time()
When I first change the time, I'll notice something like:
1.00194311142 8.29711604118 1.0010509491
Then when I start NTPd, I'll see something like:
1.00194311142 -8.117301941 1.0010509491
Is there any way to force ntpd
to make the adjustments in smaller steps?
Passing
ntpd -x
when starting the daemon will keep changes very small: there will be no stepping of the clock. Of course, setting slewing only means it may take a while to correct for larger gaps if you start with your clock very far off the correct time. Quoting a few paragraphs from the man pageSince you adjusted your clock by 10 seconds, you definitely exceeded the realm of what NTP was expecting to see, thus the stepping.
Running
ntpdate
before starting major services and then runningntpd -x
after that may be a good combined solution to make sure any major steps happen before step-less timekeeping is needed.If this is for code you want to write, this may be the answer you're looking for: https://stackoverflow.com/questions/1205722/how-do-i-get-monotonic-time-durations-in-python