From 195a506117a3c08182c1da52c8a3c14d59f4dfeb Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 7 Aug 2019 15:02:48 -0400 Subject: [PATCH 1/2] Flush consolidation --- .../proxy/connection/backend/VelocityServerConnection.java | 7 ++++++- .../com/velocitypowered/proxy/network/Connections.java | 1 + .../proxy/network/ServerChannelInitializer.java | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index 5922238a1..2f0a45333 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -3,12 +3,14 @@ package com.velocitypowered.proxy.connection.backend; import static com.velocitypowered.proxy.VelocityServer.GSON; import static com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants.HANDSHAKE_HOSTNAME_TOKEN; import static com.velocitypowered.proxy.network.Connections.FLOW_HANDLER; +import static com.velocitypowered.proxy.network.Connections.FLUSH_CONSOLIDATION; import static com.velocitypowered.proxy.network.Connections.FRAME_DECODER; import static com.velocitypowered.proxy.network.Connections.FRAME_ENCODER; import static com.velocitypowered.proxy.network.Connections.HANDLER; import static com.velocitypowered.proxy.network.Connections.MINECRAFT_DECODER; import static com.velocitypowered.proxy.network.Connections.MINECRAFT_ENCODER; import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT; +import static io.netty.handler.flush.FlushConsolidationHandler.DEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHES; import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ProtocolVersion; @@ -37,6 +39,7 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelInitializer; import io.netty.handler.flow.FlowControlHandler; +import io.netty.handler.flush.FlushConsolidationHandler; import io.netty.handler.timeout.ReadTimeoutHandler; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; @@ -90,7 +93,9 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, .addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolUtils.Direction.CLIENTBOUND)) .addLast(MINECRAFT_ENCODER, - new MinecraftEncoder(ProtocolUtils.Direction.SERVERBOUND)); + new MinecraftEncoder(ProtocolUtils.Direction.SERVERBOUND)) + .addLast(FLUSH_CONSOLIDATION, new FlushConsolidationHandler( + DEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHES, true)); } }) .connect(registeredServer.getServerInfo().getAddress()) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/Connections.java b/proxy/src/main/java/com/velocitypowered/proxy/network/Connections.java index 33112a089..1ac5635a0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/Connections.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/Connections.java @@ -15,6 +15,7 @@ public class Connections { public static final String MINECRAFT_DECODER = "minecraft-decoder"; public static final String MINECRAFT_ENCODER = "minecraft-encoder"; public static final String READ_TIMEOUT = "read-timeout"; + public static final String FLUSH_CONSOLIDATION = "flush-consolidation"; private Connections() { throw new AssertionError(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java index b71aa01e2..f91c8b5eb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.network; +import static com.velocitypowered.proxy.network.Connections.FLUSH_CONSOLIDATION; import static com.velocitypowered.proxy.network.Connections.FRAME_DECODER; import static com.velocitypowered.proxy.network.Connections.FRAME_ENCODER; import static com.velocitypowered.proxy.network.Connections.LEGACY_PING_DECODER; @@ -7,6 +8,7 @@ import static com.velocitypowered.proxy.network.Connections.LEGACY_PING_ENCODER; import static com.velocitypowered.proxy.network.Connections.MINECRAFT_DECODER; import static com.velocitypowered.proxy.network.Connections.MINECRAFT_ENCODER; import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT; +import static io.netty.handler.flush.FlushConsolidationHandler.DEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHES; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftConnection; @@ -22,6 +24,7 @@ import com.velocitypowered.proxy.protocol.netty.MinecraftVarintLengthEncoder; import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; import io.netty.handler.codec.haproxy.HAProxyMessageDecoder; +import io.netty.handler.flush.FlushConsolidationHandler; import io.netty.handler.timeout.ReadTimeoutHandler; import java.util.concurrent.TimeUnit; @@ -45,7 +48,9 @@ public class ServerChannelInitializer extends ChannelInitializer { .addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolUtils.Direction.SERVERBOUND)) - .addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolUtils.Direction.CLIENTBOUND)); + .addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolUtils.Direction.CLIENTBOUND)) + .addLast(FLUSH_CONSOLIDATION, new FlushConsolidationHandler( + DEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHES, true)); final MinecraftConnection connection = new MinecraftConnection(ch, this.server); connection.setSessionHandler(new HandshakeSessionHandler(connection, this.server)); From 32ef77f9541229d04bdc35c4d5d2ade2ef86b772 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 7 Aug 2019 16:04:34 -0400 Subject: [PATCH 2/2] Flush consolidation tweaks --- .../proxy/connection/backend/VelocityServerConnection.java | 6 +++--- .../proxy/network/ServerChannelInitializer.java | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index 2f0a45333..c67d32608 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -84,6 +84,8 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, @Override protected void initChannel(Channel ch) throws Exception { ch.pipeline() + .addLast(FLUSH_CONSOLIDATION, new FlushConsolidationHandler( + DEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHES, true)) .addLast(READ_TIMEOUT, new ReadTimeoutHandler(server.getConfiguration().getReadTimeout(), TimeUnit.MILLISECONDS)) @@ -93,9 +95,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, .addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolUtils.Direction.CLIENTBOUND)) .addLast(MINECRAFT_ENCODER, - new MinecraftEncoder(ProtocolUtils.Direction.SERVERBOUND)) - .addLast(FLUSH_CONSOLIDATION, new FlushConsolidationHandler( - DEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHES, true)); + new MinecraftEncoder(ProtocolUtils.Direction.SERVERBOUND)); } }) .connect(registeredServer.getServerInfo().getAddress()) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java index f91c8b5eb..9f54a4e53 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java @@ -14,7 +14,6 @@ import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler; import com.velocitypowered.proxy.protocol.ProtocolUtils; -import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.netty.LegacyPingDecoder; import com.velocitypowered.proxy.protocol.netty.LegacyPingEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; @@ -40,6 +39,8 @@ public class ServerChannelInitializer extends ChannelInitializer { @Override protected void initChannel(final Channel ch) { ch.pipeline() + .addLast(FLUSH_CONSOLIDATION, new FlushConsolidationHandler( + DEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHES, true)) .addLast(READ_TIMEOUT, new ReadTimeoutHandler(this.server.getConfiguration().getReadTimeout(), TimeUnit.MILLISECONDS)) @@ -48,9 +49,7 @@ public class ServerChannelInitializer extends ChannelInitializer { .addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolUtils.Direction.SERVERBOUND)) - .addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolUtils.Direction.CLIENTBOUND)) - .addLast(FLUSH_CONSOLIDATION, new FlushConsolidationHandler( - DEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHES, true)); + .addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolUtils.Direction.CLIENTBOUND)); final MinecraftConnection connection = new MinecraftConnection(ch, this.server); connection.setSessionHandler(new HandshakeSessionHandler(connection, this.server));