Skip to content
Browse files

Force shrinking on never-connected drains

Only a successful connection will grow the drain size.
  • Loading branch information...
1 parent 6cd725a commit 4b3943494e59a3b6c5748673ad596011b6d7c314 @ferd ferd committed Oct 25, 2013
Showing with 8 additions and 6 deletions.
  1. +8 −6 src/logplex_tcpsyslog_drain.erl
View
14 src/logplex_tcpsyslog_drain.erl
@@ -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

0 comments on commit 4b39434

Please sign in to comment.
Something went wrong with that request. Please try again.