From 42c4100c2d3f91e78dc7ab4962e4caa1806825e7 Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Thu, 28 Mar 2019 13:23:37 +0000 Subject: [PATCH] Add GC are initialisation in OTP R16 (and perhaps other OTP releases) there is a failure to fully garbage collect leveled_sst files after thya have initialised. They sppear to maintain a 4MB "hangover" from the initialisation process. This can be removed by manually calling garbage_collect. So we do this now on all new non-L0 files. A L0 file will be short-lived or switched - short-lived and it doesn't matter, switched and this is already GC'd. --- src/leveled_sst.erl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/leveled_sst.erl b/src/leveled_sst.erl index d9accee..16861af 100644 --- a/src/leveled_sst.erl +++ b/src/leveled_sst.erl @@ -512,12 +512,14 @@ starting({sst_new, leveled_log:log_timer("SST08", [ActualFilename, Level, Summary#summary.max_sqn], SW), + erlang:send_after(?STARTUP_TIMEOUT, self(), timeout), + % always want to have an opportunity to GC - so force the timeout to + % occur whether or not there is an intervening message {reply, {ok, {Summary#summary.first_key, Summary#summary.last_key}, Bloom}, reader, UpdState#state{blockindex_cache = BlockIndex, - starting_pid = StartingPID}, - ?STARTUP_TIMEOUT}; + starting_pid = StartingPID}}; starting({sst_newlevelzero, RootPath, Filename, Penciller, MaxSQN, OptsSST, IdxModDate}, _From, State) -> @@ -715,6 +717,7 @@ reader(switch_levels, State) -> reader(timeout, State) -> case is_process_alive(State#state.starting_pid) of true -> + erlang:garbage_collect(self()), {next_state, reader, State}; false -> {stop, normal, State}