Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Force shrinking on never-connected drains
Browse files Browse the repository at this point in the history
Only a successful connection will grow the drain size.
  • Loading branch information
ferd committed Oct 25, 2013
1 parent 6cd725a commit 4b39434
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/logplex_tcpsyslog_drain.erl
Expand Up @@ -403,15 +403,17 @@ reconnect(State = #state{failures = F, last_good_time=LastGood, buf=Buf}) ->
end,
NewBuf = case logplex_msg_buffer:len(Buf) =:= ?SHRINK_BUF_SIZE of
true -> Buf;
false when is_tuple(LastGood), tuple_size(LastGood) =:= 3 ->
case now_to_msec(LastGood) < now_to_msec(os:timestamp())-?SHRINK_TIMEOUT of
true -> % more than SHRINK time since last connect
false ->
%% Shrink if we have never connected before or the last update time
%% is more than ?SHRINK_TIMEOUT milliseconds old
case (is_tuple(LastGood) andalso tuple_size(LastGood) =:= 3 andalso
now_to_msec(LastGood) < now_to_msec(os:timestamp())-?SHRINK_TIMEOUT)
orelse LastGood =:= undefined of
true ->
logplex_msg_buffer:resize(?SHRINK_BUF_SIZE, Buf);
false ->
Buf
end;
false -> % we don't resize if we never connected
Buf
end
end,
%% We hibernate only when we need to reconnect with a timer. The timer
%% acts as a rate limiter! If you remove the timer, you must re-think
Expand Down

0 comments on commit 4b39434

Please sign in to comment.