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

Patrik Nyblom <>
Tue Apr 9 11:58:48 CEST 2013


On 04/08/2013 04:55 PM, Aliaksey Kandratsenka wrote:
>
>
>
> On Mon, Apr 8, 2013 at 7:40 AM, Aliaksey Kandratsenka 
> < <mailto:>> wrote:
>
>
>
>
>     On Mon, Apr 8, 2013 at 7:04 AM, Björn Gustavsson
>     < <mailto:>> 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).
Erlang:now() will not crawl. It will move forward at a steady pace which 
is the best approximation of time moving forward, exactly as the timers. 
It will very slowly *converge* with the wall clock time. Time, as now() 
presents it, might move one percent slower or faster than what your 
wall-clock shows, but it will never "crawl".

now() is the best approximation of the time in the system. If the wall 
clock moves it will try to converge, as the assumption is the wall clock 
has moved for a reason. now() uses a monotonic timer together with the 
wall clock to estimate a "real" time, which is the best we can get given 
normal hardware.

Unfortunately someone also thought that now() should give unique values, 
which makes it a bottleneck and has prompted more use of os:timestamp() 
than what's really good. timestamp() will jump around like crazy if 
someone decides to "fix the time" on the box, giving all kinds of 
troubles. It can be used for logging, debugging, profiling etc, but 
never for real timeouts.

Best regards,
/Patrik
>
> I should have noted that in git comment but forgot.
>
> Let me know if you need anything more from me. Like adjusted git comment.
>
>
> _______________________________________________
> erlang-patches mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-patches

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20130409/712a833a/attachment-0001.html>


More information about the erlang-patches mailing list