in reply to Re^2: The most precise second (timer)
in thread The most precise second (timer)
I am running chronyd service, but not running ntpd
Yes, AFAIK the two are mutually exclusive. I updated my node here to suggest some of the chrony configuration directives to look at that might be relevant for clock jumps.
So if sleep is not the right tool for the job, what would it be?
I checked, and interestingly, libev uses nanosleep(2) (or select(2)), which is apparently quite similar to what Time::HiRes's usleep does - so the method actually isn't as fundamentally different from your approach as I initially thought (but Perl's built-in sleep is of course too inaccurate). However, in libev, the calculations for the next event time happen at the C level, so I think it could be a little bit more accurate than if you do the same on the Perl level.
And why does the EV ... seconds diff is greater than the original code (below is simplified version of the original code; on my computer it has diff bellow 0.0004, sometimes the avg is 0.0002)?
The difference might just be from inaccuracies in the calculation of the sleep time, or the time period over which you measured (e.g. there might have been different jitter during the two). I ran a test where I ran my code from here over almost an hour, with the addition that I wrote out the timestamp for each time the event fired. Although my gettimeofday on each event was on average 0.0017s after the whole second (max 0.0021), I could see no signs of a cumulative error - perhaps it would be best if you run your own tests over a longer period of time (like a day) to see if it suits your needs.
Update: Oh, and Average over 3312 deltas: 1.00001844328777194271613548903407496361, I'd hope you'd see this number shrink over an even longer test. Also minor edits.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: The most precise second (timer)
by tukusejssirs (Beadle) on Nov 27, 2019 at 22:08 UTC | |
by haukex (Archbishop) on Nov 27, 2019 at 23:29 UTC | |
by tukusejssirs (Beadle) on Nov 28, 2019 at 11:33 UTC |