[erlang-questions] [whishlist] Adjustable erlang:now() resync speed

Vincent de Phily vincent.dephily@REDACTED
Mon Apr 8 13:32:58 CEST 2013


Hi list,

I keep wishing for this feature, and because I am very naive and not doing the 
work myself, I assume it wouldn't be all that hard to implement :

It would be great to have an emulator argument to specify how fast the VM time 
adjusts to system time. Basically "+c" but with a number appended.

For example defined as the number of millisecond per second that the VM is 
allowed to add/subtract to converge to system time :
 * "+C 10" would correspond to the current behaviour.
 * "+C 1000" would take an hour to catch up an hour.
 * "+C 99999999999999" would be equivalent to "+c".
 * "+C 0" would not try to do any sync.

Or a fancyer definition to make big jumps at first, and smaller ones at the 
end : Add max(10, Percent * TimeDifference) millisecond per second to catch up 
the TimeDifference :
 * "+C 0.01" whould catch up a second in 100 seconds, a minute in 8 minutes,
   an hour in 15 minutes, and a day in 20 minutes.
 * "+C 0.1" would catch up a day in 140 seconds; the first jump being a hefty
   2.4 hours, but jumping just 15 seconds after a minute, and less than a
   second 16 seconds later (see script below).
 * "+C 1.0" would be equivalent to "+c".


Why ?
 * How far timers are allowed to jump is very application-dependant. A cache
   TTL for a website is much less sensitive than a sound processing pipeline.
   They should have different settings.
 * The current behaviour is a pain for devices that sleep frequently. I put my
   work laptop to sleep every evening, and every morning I have to restart all
   my erlang VMs because they are otherwise unusable (more than a month to
   sync). On a system like Android that sleeps willy-nilly, it would be even
   worse.
 * The existing "+c" argument is too drastic for most cases; if you're using
   that maybe you should be using system time in your code instead. Slow sync
   is a great feature.

Does that sound like a good idea to ye ?






#!/usr/bin/env escript

main([Percent]) ->
    main([Percent, "3600000", "10"]);
main([Percent, Delta]) ->
    main([Percent, Delta, "10"]);
main([Percent, Delta, Min]) ->
    P = list_to_float(Percent),
    D = list_to_integer(Delta),
    M = list_to_integer(Min),
    io:format("Converged in ~p seconds.~n", [converge(0, P, 0, D, M)]);
main(_) ->
    io:format("Usage: converge_now.es speed [delta] [min]~n").

converge(N,P,Vm,Sys,M) when Sys > Vm ->
    D = max(M,round((Sys-Vm)*P)),
    io:format("~p ~p ~p ~p~n", [N,D,Vm,Sys]),
    converge(N + 1, P, Vm + 1000 + D, Sys + 1000, M);
converge(N,_,_,_,_) ->
    N.


-- 
Vincent de Phily




More information about the erlang-questions mailing list