Correct input buffer sizing 99/83299/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 29 Jul 2019 11:44:28 +0000 (13:44 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 29 Jul 2019 12:56:13 +0000 (14:56 +0200)
We are always reading at most one message at a time, but provide
a bed initial buffer sizing hint -- we always start with one byte,
which is far from optimal.

This patch corrects this mistake by seeding the session with an
allocator, which allocates 4K buffers.

Change-Id: I865f8c2c949c226d69be8981e1070e96089b3ccb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPMessageHeaderDecoder.java

index 60d9cf0221a70a831efb4e00fc1f586f39ec0023..13b31c7e084f125b7946fc1afa7111f192f37735 100644 (file)
@@ -18,7 +18,6 @@ import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelInitializer;
 import io.netty.channel.ChannelOption;
 import io.netty.channel.EventLoopGroup;
-import io.netty.channel.FixedRecvByteBufAllocator;
 import io.netty.channel.WriteBufferWaterMark;
 import io.netty.channel.epoll.Epoll;
 import io.netty.channel.epoll.EpollChannelOption;
@@ -53,7 +52,6 @@ import org.slf4j.LoggerFactory;
 public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(BGPDispatcherImpl.class);
     private static final int SOCKET_BACKLOG_SIZE = 128;
-    private static final int FIX_BUFFER_SIZE = 1;
     private static final long TIMEOUT = 10;
 
     private static final WriteBufferWaterMark WATER_MARK = new WriteBufferWaterMark(128 * 1024, 256 * 1024);
@@ -110,7 +108,7 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
         }
 
         // Make sure we are doing round-robin processing
-        bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(FIX_BUFFER_SIZE));
+        bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, BGPMessageHeaderDecoder.getRecvAllocator());
         bootstrap.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
         bootstrap.option(ChannelOption.WRITE_BUFFER_WATER_MARK, WATER_MARK);
         bootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress);
@@ -183,7 +181,7 @@ public class BGPDispatcherImpl implements BGPDispatcher, AutoCloseable {
         serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, WATER_MARK);
 
         // Make sure we are doing round-robin processing
-        serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(FIX_BUFFER_SIZE));
+        serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, BGPMessageHeaderDecoder.getRecvAllocator());
 
         if (serverBootstrap.config().group() == null) {
             serverBootstrap.group(this.bossGroup, this.workerGroup);
index 2645401c61e84fa91a188621055c9bcb5e43e741..bc1cf5b9c6ea32492eb7be9321ef3d42e137e863 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.protocol.bgp.rib.impl;
 
+import io.netty.channel.FixedRecvByteBufAllocator;
 import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
 
 /**
@@ -26,6 +27,11 @@ final class BGPMessageHeaderDecoder extends LengthFieldBasedFrameDecoder {
 
     private static final int EXTENDED_MAX_FRAME_SIZE = 65535;
 
+    // Allocators
+    private static final FixedRecvByteBufAllocator RECV_ALLOCATOR = new FixedRecvByteBufAllocator(MAX_FRAME_SIZE);
+    private static final FixedRecvByteBufAllocator EXTENDED_RECV_ALLOCATOR =
+            new FixedRecvByteBufAllocator(EXTENDED_MAX_FRAME_SIZE);
+
     /*
 
      0                   1                   2                   3
@@ -49,6 +55,14 @@ final class BGPMessageHeaderDecoder extends LengthFieldBasedFrameDecoder {
         super(maxFrameSize, MARKER_SIZE, LENGTH_SIZE, -MARKER_SIZE - LENGTH_SIZE, 0);
     }
 
+    static FixedRecvByteBufAllocator getRecvAllocator() {
+        return RECV_ALLOCATOR;
+    }
+
+    static FixedRecvByteBufAllocator getExtendedRecvAllocator() {
+        return EXTENDED_RECV_ALLOCATOR;
+    }
+
     static BGPMessageHeaderDecoder getBGPMessageHeaderDecoder() {
         return new BGPMessageHeaderDecoder(MAX_FRAME_SIZE);
     }
@@ -56,6 +70,4 @@ final class BGPMessageHeaderDecoder extends LengthFieldBasedFrameDecoder {
     static BGPMessageHeaderDecoder getExtendedBGPMessageHeaderDecoder() {
         return new BGPMessageHeaderDecoder(EXTENDED_MAX_FRAME_SIZE);
     }
-
-
 }