[erlang-questions] inaccurate interval timer

Per Hedeland per@REDACTED
Thu Nov 15 23:44:31 CET 2012


Mark Geib <mark.geib.44@REDACTED> wrote:
>
>The machine is running on bare hardware, not virtualized. In fact all the machines I have used in the testing are copies of the same image. I am sure it is not configuration. Is it possible that the issue is the clock of the computer it's self.? Since is is synchronized via NTP we never see clock drift.

I think you're on the right track there - I would say that the most
likely cause for the behavior you see is that the OS clock has been
stepped forward while the Erlang VM was running, and that it's doing its
"gradual catchup" scheme by running "erlang time" 1% faster than "real"
time - see the description of the +c argument in the erl(1) man page.

Running NTP is no guarantee against time steps (by default NTP will step
the system clock if it is more than 128 ms off), although when it is
functioning correctly there should be at most a single step at boot
time. However some computers have bad enough clocks that NTP is unable
to keep them sane by the normal "smooth" adjustment (at most 500 ppm)
and is forced to keep stepping them. Normally it should log such steps
to /var/log/messages or the like, though.

Anyway, you should be able to check this theory out (assuming you can
get a shell or equivalent) by comparing the return values from
erlang:now/0 ("compensated" time) and os:timestamp/0 (straight off the
OS clock) - e.g. as timer:now_diff(now(), os:timestamp()). There will
always be some microseconds of diff due to the calls being made in
sequence, of course. Also stopping and starting the VM should get rid of
any diff and thereby the "catchup" scheme - until the clock is stepped
again...

--Per Hedeland



More information about the erlang-questions mailing list