From 7cb86067bc41185c41712772e4f064ad116047a1 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 8 Aug 2019 18:39:22 -0400 Subject: [PATCH] Lower the explicit flush count Initial testing suggests this makes flush consolidation stable, although the CPU usage will be increased as we are more aggressive in flushing messages to the channels. --- .../proxy/connection/backend/VelocityServerConnection.java | 4 ++-- .../java/com/velocitypowered/proxy/network/Connections.java | 2 ++ .../proxy/network/ServerChannelInitializer.java | 4 ++-- 3 files changed, 6 insertions(+), 4 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 c67d32608..2a1910c4c 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 @@ -4,13 +4,13 @@ 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.FLUSH_CONSOLIDATION_AMOUNT; 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; @@ -85,7 +85,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, protected void initChannel(Channel ch) throws Exception { ch.pipeline() .addLast(FLUSH_CONSOLIDATION, new FlushConsolidationHandler( - DEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHES, true)) + FLUSH_CONSOLIDATION_AMOUNT, true)) .addLast(READ_TIMEOUT, new ReadTimeoutHandler(server.getConfiguration().getReadTimeout(), TimeUnit.MILLISECONDS)) 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 1ac5635a0..a0e124003 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/Connections.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/Connections.java @@ -17,6 +17,8 @@ public class Connections { public static final String READ_TIMEOUT = "read-timeout"; public static final String FLUSH_CONSOLIDATION = "flush-consolidation"; + public static final int FLUSH_CONSOLIDATION_AMOUNT = 10; + 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 9f54a4e53..4ed9a8e39 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java @@ -1,6 +1,7 @@ package com.velocitypowered.proxy.network; import static com.velocitypowered.proxy.network.Connections.FLUSH_CONSOLIDATION; +import static com.velocitypowered.proxy.network.Connections.FLUSH_CONSOLIDATION_AMOUNT; 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; @@ -8,7 +9,6 @@ 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; @@ -40,7 +40,7 @@ public class ServerChannelInitializer extends ChannelInitializer { protected void initChannel(final Channel ch) { ch.pipeline() .addLast(FLUSH_CONSOLIDATION, new FlushConsolidationHandler( - DEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHES, true)) + FLUSH_CONSOLIDATION_AMOUNT, true)) .addLast(READ_TIMEOUT, new ReadTimeoutHandler(this.server.getConfiguration().getReadTimeout(), TimeUnit.MILLISECONDS))