13
0
geforkt von Mirrors/Velocity

Implment simple backpressure support

In most cases this should only trigger on initial spawns and server
switches.
Dieser Commit ist enthalten in:
Andrew Steinborn 2018-09-08 01:00:21 -04:00
Ursprung 8d045c9140
Commit 0b1f95147a
4 geänderte Dateien mit 25 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -107,6 +107,13 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
} }
} }
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
if (sessionHandler != null) {
sessionHandler.writabilityChanged();
}
}
public void write(Object msg) { public void write(Object msg) {
if (channel.isActive()) { if (channel.isActive()) {
channel.writeAndFlush(msg, channel.voidPromise()); channel.writeAndFlush(msg, channel.voidPromise());

Datei anzeigen

@ -29,4 +29,8 @@ public interface MinecraftSessionHandler {
default void exception(Throwable throwable) { default void exception(Throwable throwable) {
} }
default void writabilityChanged() {
}
} }

Datei anzeigen

@ -4,6 +4,7 @@ import com.velocitypowered.api.event.connection.DisconnectEvent;
import com.velocitypowered.api.proxy.messages.ChannelSide; import com.velocitypowered.api.proxy.messages.ChannelSide;
import com.velocitypowered.api.proxy.messages.MessageHandler; import com.velocitypowered.api.proxy.messages.MessageHandler;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.packet.*; import com.velocitypowered.proxy.protocol.packet.*;
@ -151,6 +152,15 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
.build()); .build());
} }
@Override
public void writabilityChanged() {
VelocityServerConnection server = player.getConnectedServer();
if (server != null) {
boolean writable = player.getConnection().getChannel().isWritable();
server.getMinecraftConnection().getChannel().config().setAutoRead(writable);
}
}
public void handleBackendJoinGame(JoinGame joinGame) { public void handleBackendJoinGame(JoinGame joinGame) {
resetPingData(); // reset ping data; resetPingData(); // reset ping data;
if (!spawned) { if (!spawned) {

Datei anzeigen

@ -16,11 +16,7 @@ import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftVarintLengthEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftVarintLengthEncoder;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel; import io.netty.channel.*;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.Epoll; import io.netty.channel.epoll.Epoll;
import io.netty.channel.epoll.EpollDatagramChannel; import io.netty.channel.epoll.EpollDatagramChannel;
import io.netty.channel.epoll.EpollEventLoopGroup; import io.netty.channel.epoll.EpollEventLoopGroup;
@ -48,6 +44,8 @@ import java.util.concurrent.TimeUnit;
import static com.velocitypowered.proxy.network.Connections.*; import static com.velocitypowered.proxy.network.Connections.*;
public final class ConnectionManager { public final class ConnectionManager {
private static final WriteBufferWaterMark SERVER_WRITE_MARK = new WriteBufferWaterMark(1 << 16, 1 << 18);
private static final Logger logger = LogManager.getLogger(ConnectionManager.class); private static final Logger logger = LogManager.getLogger(ConnectionManager.class);
private final Set<Channel> endpoints = new HashSet<>(); private final Set<Channel> endpoints = new HashSet<>();
@ -72,6 +70,7 @@ public final class ConnectionManager {
final ServerBootstrap bootstrap = new ServerBootstrap() final ServerBootstrap bootstrap = new ServerBootstrap()
.channel(this.transportType.serverSocketChannelClass) .channel(this.transportType.serverSocketChannelClass)
.group(this.bossGroup, this.workerGroup) .group(this.bossGroup, this.workerGroup)
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, SERVER_WRITE_MARK)
.childHandler(new ChannelInitializer<Channel>() { .childHandler(new ChannelInitializer<Channel>() {
@Override @Override
protected void initChannel(final Channel ch) { protected void initChannel(final Channel ch) {