Skip to content

Commit ce4553b

Browse files
committed
Adjust the formula to account for network hiccups
1 parent 965ce2b commit ce4553b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

deps/rabbit/src/rabbit_reader.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,11 @@ maybe_resize_buffer(State=#v1{sock=Sock, dynamic_buffer_size=BufferSize0,
546546
LowDynamicBuffer = 1024,
547547
HighDynamicBuffer = 131072,
548548
DataLen = byte_size(Data),
549-
MovingAvg = (MovingAvg0 + DataLen) div 2,
549+
MovingAvg = (MovingAvg0 * 31 + DataLen) div 32,
550550
if
551551
BufferSize0 < HighDynamicBuffer andalso MovingAvg > BufferSize0 * 0.9 ->
552552
BufferSize = min(BufferSize0 * 2, HighDynamicBuffer),
553+
% erlang:display({up,BufferSize}),
553554
case rabbit_net:setopts(Sock, [{buffer, BufferSize}]) of
554555
ok -> State#v1{
555556
dynamic_buffer_size=BufferSize,
@@ -560,6 +561,7 @@ maybe_resize_buffer(State=#v1{sock=Sock, dynamic_buffer_size=BufferSize0,
560561
end;
561562
BufferSize0 > LowDynamicBuffer andalso MovingAvg < BufferSize0 * 0.4 ->
562563
BufferSize = max(BufferSize0 div 2, LowDynamicBuffer),
564+
% erlang:display({down,BufferSize}),
563565
case rabbit_net:setopts(Sock, [{buffer, BufferSize}]) of
564566
ok -> State#v1{
565567
dynamic_buffer_size=BufferSize,

0 commit comments

Comments
 (0)