diff --git a/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java b/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java index 06cd3a3f50..6c1139cc6b 100644 --- a/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java +++ b/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java @@ -27,6 +27,7 @@ import io.netty.util.Recycler; import io.netty.util.Recycler.Handle; import io.netty.util.ReferenceCountUtil; import io.netty.util.internal.PlatformDependent; +import io.netty.util.internal.SystemPropertyUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -42,7 +43,14 @@ public class ChannelOutboundBuffer { private static final InternalLogger logger = InternalLoggerFactory.getInstance(ChannelOutboundBuffer.class); - protected static final int INITIAL_CAPACITY = 32; + protected static final int INITIAL_CAPACITY = + SystemPropertyUtil.getInt("io.netty.outboundBufferInitialCapacity", 4); + + static { + if (logger.isDebugEnabled()) { + logger.debug("-Dio.netty.outboundBufferInitialCapacity: {}", INITIAL_CAPACITY); + } + } private static final Recycler RECYCLER = new Recycler() { @Override diff --git a/transport/src/test/java/io/netty/channel/socket/nio/NioSocketChannelOutboundBufferTest.java b/transport/src/test/java/io/netty/channel/socket/nio/NioSocketChannelOutboundBufferTest.java index 7f825d4b0e..d42100ceb6 100644 --- a/transport/src/test/java/io/netty/channel/socket/nio/NioSocketChannelOutboundBufferTest.java +++ b/transport/src/test/java/io/netty/channel/socket/nio/NioSocketChannelOutboundBufferTest.java @@ -36,7 +36,7 @@ public class NioSocketChannelOutboundBufferTest { NioSocketChannelOutboundBuffer buffer = NioSocketChannelOutboundBuffer.newInstance(channel); assertEquals(0, buffer.nioBufferCount()); ByteBuffer[] buffers = buffer.nioBuffers(); - assertEquals(32, buffers.length); + assertNotNull(buffers); for (ByteBuffer b: buffers) { assertNull(b); } @@ -50,7 +50,7 @@ public class NioSocketChannelOutboundBufferTest { NioSocketChannelOutboundBuffer buffer = NioSocketChannelOutboundBuffer.newInstance(channel); assertEquals(0, buffer.nioBufferCount()); ByteBuffer[] buffers = buffer.nioBuffers(); - assertEquals(32, buffers.length); + assertNotNull(buffers); for (ByteBuffer b: buffers) { assertNull(b); } @@ -66,7 +66,7 @@ public class NioSocketChannelOutboundBufferTest { } buffer.addFlush(); buffers = buffer.nioBuffers(); - assertEquals(32, buffers.length); + assertNotNull(buffers); assertEquals("Should still be 0 as not flushed yet", 1, buffer.nioBufferCount()); for (int i = 0; i < buffers.length; i++) { if (i == 0) {