Skip to content

Commit 48689bf

Browse files
committed
SpigotMC#3392: Consolidate flushes to reduce syscalls, improves performance
Based on Netty FlushConsolidationHandler
1 parent cd3ce7a commit 48689bf

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

proxy/src/main/java/net/md_5/bungee/ServerConnector.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public void handle(Login login) throws Exception
327327
user.setServer( server );
328328
ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user, server ) );
329329

330-
// Updates the flush handler connections, the methods add the handler if needed
330+
// Updates the flush handler connections (the get/set methods add the channel handlers if needed)
331331
ch.setFlushSignalingTarget( user.getCh().getFlushConsolidationHandler( false ) );
332332
user.getCh().setFlushSignalingTarget( ch.getFlushConsolidationHandler( true ) );
333333

proxy/src/main/java/net/md_5/bungee/UserConnection.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Queue;
2222
import java.util.UUID;
2323
import java.util.logging.Level;
24+
import lombok.AccessLevel;
2425
import lombok.Getter;
2526
import lombok.NonNull;
2627
import lombok.RequiredArgsConstructor;
@@ -72,7 +73,7 @@ public final class UserConnection implements ProxiedPlayer
7273
/*========================================================================*/
7374
@NonNull
7475
private final ProxyServer bungee;
75-
@Getter
76+
@Getter(AccessLevel.PACKAGE)
7677
@NonNull
7778
private final ChannelWrapper ch;
7879
@Getter

proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,27 @@ public void setVersion(int protocol)
4949
ch.pipeline().get( MinecraftEncoder.class ).setProtocolVersion( protocol );
5050
}
5151

52+
/**
53+
* Set the {@link FlushSignalingHandler} target. If the handler is absent, one will be added.
54+
* @param target the (new) target for the flush signaling handler
55+
*/
5256
public void setFlushSignalingTarget(BungeeFlushConsolidationHandler target)
5357
{
5458
FlushSignalingHandler handler = ch.pipeline().get( FlushSignalingHandler.class );
5559
if ( handler == null )
5660
{
57-
ch.pipeline().addFirst( PipelineUtils.FLUSH_SIGNALING, handler = new FlushSignalingHandler( target ) );
61+
ch.pipeline().addFirst( PipelineUtils.FLUSH_SIGNALING, new FlushSignalingHandler( target ) );
62+
} else
63+
{
64+
handler.setTarget( target );
5865
}
59-
handler.setTarget( target );
6066
}
6167

68+
/**
69+
* Get the flush consolidation handler of this channel. If none is present, one will be added.
70+
* @param toClient whether this channel is a bungee-client connection
71+
* @return the flush consolidation handler for this channel
72+
*/
6273
public BungeeFlushConsolidationHandler getFlushConsolidationHandler(boolean toClient)
6374
{
6475
BungeeFlushConsolidationHandler handler = ch.pipeline().get( BungeeFlushConsolidationHandler.class );

proxy/src/main/java/net/md_5/bungee/netty/flush/BungeeFlushConsolidationHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public final class BungeeFlushConsolidationHandler extends ChannelDuplexHandler
8484
/**
8585
* Creates a new instance with bungee's default values
8686
*
87-
* @param toClient whether this handler is for a client connection
87+
* @param toClient whether this handler is for a bungee-client connection
8888
* @return a new instance of BungeeFlushConsolidationHandler
8989
*/
9090
public static BungeeFlushConsolidationHandler newInstance(boolean toClient)

0 commit comments

Comments
 (0)