Improved performance of byte buf allocator for UDP connections

This commit is contained in:
nathan 2018-01-03 22:30:06 +01:00
parent 5ff2f348a0
commit a9ba4a5b52
2 changed files with 12 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import java.net.InetSocketAddress;
import org.slf4j.Logger;
import dorkbox.network.connection.Connection;
import dorkbox.network.connection.EndPointBase;
import dorkbox.network.connection.RegistrationWrapper;
import dorkbox.network.connection.registration.MetaChannel;
import dorkbox.network.connection.registration.Registration;
@ -33,6 +34,7 @@ import dorkbox.util.crypto.CryptoAES;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.FixedRecvByteBufAllocator;
public
class RegistrationRemoteHandlerClientUDP<C extends Connection> extends RegistrationRemoteHandlerClient<C> {
@ -56,6 +58,10 @@ class RegistrationRemoteHandlerClientUDP<C extends Connection> extends Registrat
.getSimpleName());
}
// Netty4 has default of 2048 bytes as upper limit for datagram packets.
channel.config()
.setRecvByteBufAllocator(new FixedRecvByteBufAllocator(EndPointBase.udpMaxSize));
ChannelPipeline pipeline = channel.pipeline();
// UDP

View File

@ -38,6 +38,7 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.socket.DatagramPacket;
import io.netty.handler.codec.MessageToMessageCodec;
@ -73,6 +74,11 @@ class RegistrationRemoteHandlerServerUDP<C extends Connection> extends MessageTo
@Override
public
void channelActive(final ChannelHandlerContext context) throws Exception {
// Netty4 has default of 2048 bytes as upper limit for datagram packets.
context.channel()
.config()
.setRecvByteBufAllocator(new FixedRecvByteBufAllocator(EndPointBase.udpMaxSize));
// do NOT want to add UDP channels, since they are tracked differently for the server.
}