diff --git a/transport/src/main/java/io/netty/channel/AdaptiveRecvByteBufAllocator.java b/transport/src/main/java/io/netty/channel/AdaptiveRecvByteBufAllocator.java index 1b4020d79b..f6c06d33b7 100644 --- a/transport/src/main/java/io/netty/channel/AdaptiveRecvByteBufAllocator.java +++ b/transport/src/main/java/io/netty/channel/AdaptiveRecvByteBufAllocator.java @@ -122,7 +122,7 @@ public class AdaptiveRecvByteBufAllocator extends DefaultMaxMessagesRecvByteBufA } private void record(int actualReadBytes) { - if (actualReadBytes <= SIZE_TABLE[max(0, index - INDEX_DECREMENT - 1)]) { + if (actualReadBytes <= SIZE_TABLE[max(0, index - INDEX_DECREMENT)]) { if (decreaseNow) { index = max(index - INDEX_DECREMENT, minIndex); nextReceiveBufferSize = SIZE_TABLE[index]; diff --git a/transport/src/test/java/io/netty/channel/AdaptiveRecvByteBufAllocatorTest.java b/transport/src/test/java/io/netty/channel/AdaptiveRecvByteBufAllocatorTest.java index 762db6970b..8f95b2bdd0 100644 --- a/transport/src/test/java/io/netty/channel/AdaptiveRecvByteBufAllocatorTest.java +++ b/transport/src/test/java/io/netty/channel/AdaptiveRecvByteBufAllocatorTest.java @@ -54,6 +54,26 @@ public class AdaptiveRecvByteBufAllocatorTest { allocReadExpected(handle, alloc, 8388608); } + @Test + public void memoryAllocationIntervalsTest() { + computingNext(512, 512); + computingNext(8192, 1110); + computingNext(8192, 1200); + computingNext(4096, 1300); + computingNext(4096, 1500); + computingNext(2048, 1700); + computingNext(2048, 1550); + computingNext(2048, 2000); + computingNext(2048, 1900); + } + + private void computingNext(long expectedSize, int actualReadBytes) { + assertEquals(expectedSize, handle.guess()); + handle.reset(config); + handle.lastBytesRead(actualReadBytes); + handle.readComplete(); + } + @Test public void lastPartialReadDoesNotRampDown() { allocReadExpected(handle, alloc, 512);