From a9ba4a5b5200af0c4e43209bdc7d8e1e4867afc4 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 3 Jan 2018 22:30:06 +0100 Subject: [PATCH] Improved performance of byte buf allocator for UDP connections --- .../remote/RegistrationRemoteHandlerClientUDP.java | 6 ++++++ .../remote/RegistrationRemoteHandlerServerUDP.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerClientUDP.java b/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerClientUDP.java index 156616c5..3906c504 100644 --- a/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerClientUDP.java +++ b/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerClientUDP.java @@ -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 extends RegistrationRemoteHandlerClient { @@ -56,6 +58,10 @@ class RegistrationRemoteHandlerClientUDP 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 diff --git a/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerServerUDP.java b/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerServerUDP.java index fedc18ac..afad2d5c 100644 --- a/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerServerUDP.java +++ b/src/dorkbox/network/connection/registration/remote/RegistrationRemoteHandlerServerUDP.java @@ -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 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. }