Garbage-collect self before making final decision about termination

parent 835f82aa
...@@ -320,7 +320,7 @@ check_queue_overflow(#state{last_queue_check = LastCheck} = S) -> ...@@ -320,7 +320,7 @@ check_queue_overflow(#state{last_queue_check = LastCheck} = S) ->
true -> true ->
{noreply, S}; {noreply, S};
false -> false ->
case do_check_queue_overflow() of case do_check_queue_overflow(true) of
ok -> ok ->
{noreply, S#state{last_queue_check = NowMs}}; {noreply, S#state{last_queue_check = NowMs}};
overflow -> overflow ->
...@@ -328,7 +328,7 @@ check_queue_overflow(#state{last_queue_check = LastCheck} = S) -> ...@@ -328,7 +328,7 @@ check_queue_overflow(#state{last_queue_check = LastCheck} = S) ->
end end
end. end.
do_check_queue_overflow() -> do_check_queue_overflow(Gc) ->
[{_, QLen}, {_, Mem}, {_, Bin}] = [{_, QLen}, {_, Mem}, {_, Bin}] =
erlang:process_info(self(), [message_queue_len, memory, binary]), erlang:process_info(self(), [message_queue_len, memory, binary]),
%% BinSum = sum_binary(Bin), %% BinSum = sum_binary(Bin),
...@@ -339,6 +339,9 @@ do_check_queue_overflow() -> ...@@ -339,6 +339,9 @@ do_check_queue_overflow() ->
RefcBinSize = sum_binary(Bin), RefcBinSize = sum_binary(Bin),
TotalMem = Mem + RefcBinSize, TotalMem = Mem + RefcBinSize,
case TotalMem > ?QUEUE_CHECK_MAX_MEM of case TotalMem > ?QUEUE_CHECK_MAX_MEM of
true when Gc->
erlang:garbage_collect(self()),
do_check_queue_overflow(false);
true -> true ->
lager:warning( lager:warning(
"Process too large queue_len=~w, memory=~w, binary_sum=~w, binary=~p", "Process too large queue_len=~w, memory=~w, binary_sum=~w, binary=~p",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment