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

Aliaksey Kandratsenka <>
Mon Apr 8 16:40:19 CEST 2013


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.

If wall clock time jumps forward same behavior of both time reading
functions is same. We'll tick all missed ticks in that jumped interval.
Which is btw a behavior we should consider fixing either. But that's a
separate topic.

Overall I believe exposing OS monotonic clock is best option for handling
clock jumps. Which is a separate topic.

Anyway let me know if you insist on erlang:now


> How did you find the bug? Do you have a
> test case or a program to provoke the bug?
>

I've spotted timer_server in etop in highest position in our program
(management layer of couchbase server) that has few tens of interval timers
and started tracing it. Which is how I discovered those weird sequences of
timeouts at same timestamp. So no I don't have a test case.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20130408/305560f5/attachment.html>


More information about the erlang-patches mailing list