[erlang-patches] [patch] fix excessive CPU consumption of timer_server

Aliaksey Kandratsenka <>
Mon Apr 8 16:55:26 CEST 2013

On Mon, Apr 8, 2013 at 7:40 AM, Aliaksey Kandratsenka <
> wrote:

> On Mon, Apr 8, 2013 at 7:04 AM, Björn Gustavsson <>wrote:
>> Thanks for the bug report and patch!
>> The patch, however, is not acceptable since
>> it replaces a call to erlang:now/0 with a call to
>> os:timestamp/0. os:timestamp/0 does no
>> time correction while erlang:now/0 does, so there
>> will be trouble if time correction is being done.
>> Did you have any particular reason to use
>> os:timestamp/0? It seems to me that using
>> erlang:now/0 should work just as well.
> It would work reasonably well.
> But here's my thinking.
> If wall clock time jumps backward then os:timestamp will also jump
> backwards and we're screwed. I.e. no ticks will happen until time will
> naturally advance to a time before jump. erlang:now will not jump
> backwards, but it will not do any "time correction" either. It'll just
> "crawl forward" by 1 microsecond per erlang:now call which is in my
> definition screwed either.

Actually I forgot but my thinking was a bit more elaborate.

If we use erlang:now and time jumps backwards. We'll have time as seen by
receive X -> X after AfterMillis -> ok end flow normally, but erlang:now
will crawl. Which can be seen to cause same busy wait in timer server but
just for much longer (i.e. until erlang:now overtakes os:timestamp where
that "never go back" code path stops being hit and time flows normal again).

I should have noted that in git comment but forgot.

Let me know if you need anything more from me. Like adjusted git comment.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20130408/9ed3e6b8/attachment.html>

More information about the erlang-patches mailing list