Skip to content

Commit

Permalink
Merge branch 'dgud/ct/improve-memory-usage/OTP-19489' into maint
Browse files Browse the repository at this point in the history
* dgud/ct/improve-memory-usage/OTP-19489:
  Reduce memory usage in io proxy process
  • Loading branch information
dgud committed Feb 14, 2025
2 parents 638d25d + b6e6804 commit d4c6e78
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/common_test/src/test_server_gl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ handle_call({set_props,PropList}, _From, St) ->
{reply,ok,do_set_props(PropList, St)};
handle_call({print,Detail,Msg,Printer}, {From,_}, St) ->
output(Detail, Msg, Printer, From, St),
do_gc(),
{reply,ok,St};
handle_call({capture, Who}, {_From, _}, St) ->
Cap = case Who of
Expand Down Expand Up @@ -240,16 +241,20 @@ handle_info({io_request,From,ReplyAs,Req}=IoReq, St) ->
_:_ ->
From ! {io_reply,ReplyAs,{error,arguments}}
end,
do_gc(),
{noreply,St};
handle_info({structured_io,ClientPid,{Detail,Str}}, St) ->
output(Detail, Str, ClientPid, ClientPid, St),
do_gc(),
{noreply,St};
handle_info({printout,Detail,["$tc_html",Format],Args}, St) ->
Str = io_lib:format(Format, Args),
output(Detail, ["$tc_html",Str], internal, none, St),
do_gc(),
{noreply,St};
handle_info({printout,Detail,Fun}, St) when is_function(Fun)->
output(Detail, Fun, internal, none, St),
do_gc(),
{noreply,St};
handle_info({printout,Detail,Format,Args}, St) ->
Str = io_lib:format(Format, Args),
Expand All @@ -258,6 +263,7 @@ handle_info({printout,Detail,Format,Args}, St) ->
true ->
output(Detail, Str, internal, none, St)
end,
do_gc(),
{noreply,St};
handle_info(Msg, #st{tc_supervisor=Pid}=St) when is_pid(Pid) ->
%% The process overseeing the testcase process also used to be
Expand All @@ -274,6 +280,13 @@ handle_info(_Msg, #st{}=St) ->
terminate(_, _) ->
ok.

do_gc() ->
%% Reduces the amount of memory used, in one example from 6.6 GB to 500MB
%% when running testsuites in parallel and doesn't take any longer
erlang:garbage_collect(self(), [{async, true}, {type, major}]),
ok.


do_set_props([{levels,Levels}|Ps], St) ->
do_set_props(Ps, St#st{levels=Levels});
do_set_props([{auto_nl,AutoNL}|Ps], St) ->
Expand Down

0 comments on commit d4c6e78

Please sign in to comment.