#3828: Set allocator using Netty system property to apply pooled allocator default globally

This commit is contained in:
onebeastchris 2025-05-12 20:39:24 +10:00 committed by md_5
parent 2bafb70581
commit ae2fc30b7b
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 8 additions and 4 deletions

View File

@ -262,6 +262,14 @@ public class BungeeCord extends ProxyServer
ResourceLeakDetector.setLevel( ResourceLeakDetector.Level.DISABLED ); // Eats performance ResourceLeakDetector.setLevel( ResourceLeakDetector.Level.DISABLED ); // Eats performance
} }
// https://github.com/netty/netty/wiki/Netty-4.2-Migration-Guide
// The adaptive allocator, the new default allocator since Netty 4.2, has some memory issues.
// Setting it globally also ensures that any plugins would also use the pooled allocator.
if ( System.getProperty( "io.netty.allocator.type" ) == null )
{
System.setProperty( "io.netty.allocator.type", "pooled" );
}
eventLoops = PipelineUtils.newEventLoopGroup( 0, new ThreadFactoryBuilder().setNameFormat( "Netty IO Thread #%1$d" ).build() ); eventLoops = PipelineUtils.newEventLoopGroup( 0, new ThreadFactoryBuilder().setNameFormat( "Netty IO Thread #%1$d" ).build() );
File moduleDirectory = new File( "modules" ); File moduleDirectory = new File( "modules" );

View File

@ -1,7 +1,6 @@
package net.md_5.bungee.netty; package net.md_5.bungee.netty;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
@ -219,9 +218,6 @@ public class PipelineUtils
{ {
// IP_TOS is not supported (Windows XP / Windows Server 2003) // IP_TOS is not supported (Windows XP / Windows Server 2003)
} }
// https://github.com/netty/netty/wiki/Netty-4.2-Migration-Guide
// TODO: check for AdaptiveByteBufAllocator
ch.config().setAllocator( PooledByteBufAllocator.DEFAULT );
ch.config().setWriteBufferWaterMark( MARK ); ch.config().setWriteBufferWaterMark( MARK );
ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() ); ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() );