[erlang-questions] Sending message at a specific and accurate time

Ola Bäckström Ola.Backstrom@REDACTED
Mon Feb 22 13:16:22 CET 2016

Do you get different result with power cable plugged in compared to not plugged in?

As Jesper mentioned earlier does OS X have some power saving stuff, it is called "timer coalescing".  
See for instance http://arstechnica.com/apple/2013/06/how-os-x-mavericks-works-its-power-saving-magic/
There seems to be ways to disable it, http://www.timoliver.com.au/2014/01/25/disabling-timer-coalescing-in-os-x-mavericks/
, but that is not something I've tried.

I thought this was "os X"-only stuff, but now when I google I see that linux seems to have coalescing since many years too. If it is in general enabled I don't know.

-----Original Message-----
From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Joe Armstrong
Sent: den 22 februari 2016 12:52
To: Jesper Louis Andersen <jesper.louis.andersen@REDACTED>
Cc: Erlang <erlang-questions@REDACTED>
Subject: Re: [erlang-questions] Sending message at a specific and accurate time

On Mon, Feb 22, 2016 at 12:04 PM, Jesper Louis Andersen <jesper.louis.andersen@REDACTED> wrote:
> On Mon, Feb 22, 2016 at 8:30 AM, Joe Armstrong <erlang@REDACTED> wrote:
>> Here's the slightly modified program.
> I *have* to nitpick this since I worry people will misuse the new 18.0 
> timing API. Changes to the program:
> * Use erlang:monotonic_time() which gives you native resolution by 
> default according to the precision of your systems clock (older 
> devices will give you micro_seconds, newer systems nano_seconds). 
> Also, by using monotonic_time we avoid time warping, which you may get with system_time.
> * Request the timestamps in native format, operate on the native 
> format and finally convert down to the desired output format. This 
> avoids rounding errors.
> I get the same bad results on OSX, but not on Linux. It would be 
> interesting to analyze why it takes so long to wake up on OSX after 
> having slept for 1 second. It definitely looks like a problem with 
> being woken up and having to do work different from the scheduler 
> loop, but I have yet to investigate why that happens.

I get the same effect irrespective of the sleep interval if I sleep for 100 ms then the wake-up still can be still 6ms later than the requested time ...

Is the timer code in linux and OS-X different, or do they call the same libraries and the libraries behave differently?

I have no idea


> -module(t).
> -compile(export_all).
> test() ->
>     process_flag(priority, max),
>     test(10, []).
> test(0, L) ->
>     L;
> test(K, L) ->
>     T1 = erlang:monotonic_time(),
>     erlang:send_after(1000, self(), ping),
>     receive
>       ping ->
>         T2 = erlang:monotonic_time(),
>         test(K-1, [erlang:convert_time_unit(T2-T1, native, 
> micro_seconds) | L ])
>     end.
> --
> J.
erlang-questions mailing list

More information about the erlang-questions mailing list