13
0
geforkt von Mirrors/Velocity

Force a flush after a certain threshold of packets have been queued for sending

Fixes #486.
Dieser Commit ist enthalten in:
Andrew Steinborn 2021-05-04 18:51:01 -04:00
Ursprung e0153267db
Commit d42cc4f984

Datei anzeigen

@ -56,12 +56,16 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
private static final Logger logger = LogManager.getLogger(BackendPlaySessionHandler.class); private static final Logger logger = LogManager.getLogger(BackendPlaySessionHandler.class);
private static final boolean BACKPRESSURE_LOG = Boolean private static final boolean BACKPRESSURE_LOG = Boolean
.getBoolean("velocity.log-server-backpressure"); .getBoolean("velocity.log-server-backpressure");
private static final int MAXIMUM_PACKETS_TO_FLUSH = Integer
.getInteger("velocity.max-packets-per-flush", 8192);
private final VelocityServer server; private final VelocityServer server;
private final VelocityServerConnection serverConn; private final VelocityServerConnection serverConn;
private final ClientPlaySessionHandler playerSessionHandler; private final ClientPlaySessionHandler playerSessionHandler;
private final MinecraftConnection playerConnection; private final MinecraftConnection playerConnection;
private final BungeeCordMessageResponder bungeecordMessageResponder; private final BungeeCordMessageResponder bungeecordMessageResponder;
private boolean exceptionTriggered = false; private boolean exceptionTriggered = false;
private int packetsFlushed;
BackendPlaySessionHandler(VelocityServer server, VelocityServerConnection serverConn) { BackendPlaySessionHandler(VelocityServer server, VelocityServerConnection serverConn) {
this.server = server; this.server = server;
@ -271,16 +275,25 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
((PluginMessage) packet).retain(); ((PluginMessage) packet).retain();
} }
playerConnection.delayedWrite(packet); playerConnection.delayedWrite(packet);
if (++packetsFlushed >= MAXIMUM_PACKETS_TO_FLUSH) {
playerConnection.flush();
packetsFlushed = 0;
}
} }
@Override @Override
public void handleUnknown(ByteBuf buf) { public void handleUnknown(ByteBuf buf) {
playerConnection.delayedWrite(buf.retain()); playerConnection.delayedWrite(buf.retain());
if (++packetsFlushed >= MAXIMUM_PACKETS_TO_FLUSH) {
playerConnection.flush();
packetsFlushed = 0;
}
} }
@Override @Override
public void readCompleted() { public void readCompleted() {
playerConnection.flush(); playerConnection.flush();
packetsFlushed = 0;
} }
@Override @Override