2.0 - replace 'now/0' with 'erlang:monotonic_time/0'
This commit is contained in:
parent
710890dd22
commit
2370e7dfcb
|
@ -624,7 +624,7 @@ unregister_name(_Name) -> ok.
|
||||||
extend_backoff(undefined) ->
|
extend_backoff(undefined) ->
|
||||||
undefined;
|
undefined;
|
||||||
extend_backoff({backoff, InitialTimeout, MinimumTimeout, DesiredHibPeriod}) ->
|
extend_backoff({backoff, InitialTimeout, MinimumTimeout, DesiredHibPeriod}) ->
|
||||||
{backoff, InitialTimeout, MinimumTimeout, DesiredHibPeriod, now()}.
|
{backoff, InitialTimeout, MinimumTimeout, DesiredHibPeriod, rand:seed(exsplus)}.
|
||||||
|
|
||||||
%%%========================================================================
|
%%%========================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
|
@ -636,8 +636,10 @@ loop(GS2State = #gs2_state { time = hibernate,
|
||||||
timeout_state = undefined,
|
timeout_state = undefined,
|
||||||
queue = Queue }) ->
|
queue = Queue }) ->
|
||||||
case priority_queue:is_empty(Queue) of
|
case priority_queue:is_empty(Queue) of
|
||||||
true -> pre_hibernate(GS2State);
|
true ->
|
||||||
false -> process_next_msg(GS2State)
|
pre_hibernate(GS2State);
|
||||||
|
false ->
|
||||||
|
process_next_msg(GS2State)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
loop(GS2State) ->
|
loop(GS2State) ->
|
||||||
|
@ -693,7 +695,9 @@ wake_hib(GS2State = #gs2_state { timeout_state = TS }) ->
|
||||||
undefined ->
|
undefined ->
|
||||||
undefined;
|
undefined;
|
||||||
{SleptAt, TimeoutState} ->
|
{SleptAt, TimeoutState} ->
|
||||||
adjust_timeout_state(SleptAt, now(), TimeoutState)
|
adjust_timeout_state(SleptAt,
|
||||||
|
erlang:monotonic_time(),
|
||||||
|
TimeoutState)
|
||||||
end,
|
end,
|
||||||
post_hibernate(
|
post_hibernate(
|
||||||
drain(GS2State #gs2_state { timeout_state = TimeoutState1 })).
|
drain(GS2State #gs2_state { timeout_state = TimeoutState1 })).
|
||||||
|
@ -701,7 +705,8 @@ wake_hib(GS2State = #gs2_state { timeout_state = TS }) ->
|
||||||
hibernate(GS2State = #gs2_state { timeout_state = TimeoutState }) ->
|
hibernate(GS2State = #gs2_state { timeout_state = TimeoutState }) ->
|
||||||
TS = case TimeoutState of
|
TS = case TimeoutState of
|
||||||
undefined -> undefined;
|
undefined -> undefined;
|
||||||
{backoff, _, _, _, _} -> {now(), TimeoutState}
|
{backoff, _, _, _, _} -> {erlang:monotonic_time(),
|
||||||
|
TimeoutState}
|
||||||
end,
|
end,
|
||||||
proc_lib:hibernate(?MODULE, wake_hib,
|
proc_lib:hibernate(?MODULE, wake_hib,
|
||||||
[GS2State #gs2_state { timeout_state = TS }]).
|
[GS2State #gs2_state { timeout_state = TS }]).
|
||||||
|
@ -746,7 +751,8 @@ post_hibernate(GS2State = #gs2_state { state = State,
|
||||||
|
|
||||||
adjust_timeout_state(SleptAt, AwokeAt, {backoff, CurrentTO, MinimumTO,
|
adjust_timeout_state(SleptAt, AwokeAt, {backoff, CurrentTO, MinimumTO,
|
||||||
DesiredHibPeriod, RandomState}) ->
|
DesiredHibPeriod, RandomState}) ->
|
||||||
NapLengthMicros = timer:now_diff(AwokeAt, SleptAt),
|
NapLengthMicros = erlang:convert_time_unit(AwokeAt - SleptAt,
|
||||||
|
native, micro_seconds),
|
||||||
CurrentMicros = CurrentTO * 1000,
|
CurrentMicros = CurrentTO * 1000,
|
||||||
MinimumMicros = MinimumTO * 1000,
|
MinimumMicros = MinimumTO * 1000,
|
||||||
DesiredHibMicros = DesiredHibPeriod * 1000,
|
DesiredHibMicros = DesiredHibPeriod * 1000,
|
||||||
|
@ -758,7 +764,7 @@ adjust_timeout_state(SleptAt, AwokeAt, {backoff, CurrentTO, MinimumTO,
|
||||||
true -> lists:max([MinimumTO, CurrentTO div 2]);
|
true -> lists:max([MinimumTO, CurrentTO div 2]);
|
||||||
false -> CurrentTO
|
false -> CurrentTO
|
||||||
end,
|
end,
|
||||||
{Extra, RandomState1} = random:uniform_s(Base, RandomState),
|
{Extra, RandomState1} = rand:uniform_s(Base, RandomState),
|
||||||
CurrentTO1 = Base + Extra,
|
CurrentTO1 = Base + Extra,
|
||||||
{backoff, CurrentTO1, MinimumTO, DesiredHibPeriod, RandomState1}.
|
{backoff, CurrentTO1, MinimumTO, DesiredHibPeriod, RandomState1}.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue