import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.PooledByteBufAllocator;
+import io.netty.channel.AdaptiveRecvByteBufAllocator;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
+import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.WriteBufferWaterMark;
import io.netty.channel.epoll.Epoll;
import io.netty.channel.epoll.EpollChannelOption;
private static final WriteBufferWaterMark WATER_MARK = new WriteBufferWaterMark(128 * 1024, 256 * 1024);
+ // An adaptive allocator, so we size our message buffers based on what we receive, but make sure we process one
+ // message at a time. This should be good enough for most cases, although we could optimize it a bit based on
+ // whether we actually negotiate use of large messages -- based on that the range of allocations can be constrained
+ // from the default 64-65536 range to 64-4096.
+ private static final RecvByteBufAllocator RECV_ALLOCATOR = new AdaptiveRecvByteBufAllocator().maxMessagesPerRead(1);
+
private final BGPHandlerFactory handlerFactory;
private final EventLoopGroup bossGroup;
private final EventLoopGroup workerGroup;
}
// Make sure we are doing round-robin processing
- bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, BGPMessageHeaderDecoder.getRecvAllocator());
+ bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, RECV_ALLOCATOR);
bootstrap.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
bootstrap.option(ChannelOption.WRITE_BUFFER_WATER_MARK, WATER_MARK);
bootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress);
serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, WATER_MARK);
// Make sure we are doing round-robin processing
- serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, BGPMessageHeaderDecoder.getRecvAllocator());
+ serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, RECV_ALLOCATOR);
if (serverBootstrap.config().group() == null) {
serverBootstrap.group(this.bossGroup, this.workerGroup);
*/
package org.opendaylight.protocol.bgp.rib.impl;
-import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.handler.codec.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
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);
}