13
0
geforkt von Mirrors/Velocity

Use the player's event loop for their server connections.

This approach reduces context switching, giving us that much extra boost
in throughput.
Dieser Commit ist enthalten in:
Andrew Steinborn 2019-01-19 03:21:46 -05:00
Ursprung 865f9e5ef9
Commit 56873712ec
3 geänderte Dateien mit 16 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -41,6 +41,7 @@ import com.velocitypowered.proxy.util.VelocityChannelRegistrar;
import com.velocitypowered.proxy.util.ratelimit.Ratelimiter; import com.velocitypowered.proxy.util.ratelimit.Ratelimiter;
import com.velocitypowered.proxy.util.ratelimit.Ratelimiters; import com.velocitypowered.proxy.util.ratelimit.Ratelimiters;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.EventLoopGroup;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.file.Files; import java.nio.file.Files;
@ -239,6 +240,10 @@ public class VelocityServer implements ProxyServer {
return this.cm.createWorker(); return this.cm.createWorker();
} }
public Bootstrap initializeGenericBootstrap(EventLoopGroup group) {
return this.cm.createWorker(group);
}
public boolean isShutdown() { public boolean isShutdown() {
return shutdown; return shutdown;
} }

Datei anzeigen

@ -71,7 +71,9 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
*/ */
public CompletableFuture<ConnectionRequestBuilder.Result> connect() { public CompletableFuture<ConnectionRequestBuilder.Result> connect() {
CompletableFuture<ConnectionRequestBuilder.Result> result = new CompletableFuture<>(); CompletableFuture<ConnectionRequestBuilder.Result> result = new CompletableFuture<>();
server.initializeGenericBootstrap() // Note: we use the event loop for the connection the player is on. This reduces context
// switches.
server.initializeGenericBootstrap(proxyPlayer.getMinecraftConnection().eventLoop())
.handler(new ChannelInitializer<Channel>() { .handler(new ChannelInitializer<Channel>() {
@Override @Override
protected void initChannel(Channel ch) throws Exception { protected void initChannel(Channel ch) throws Exception {

Datei anzeigen

@ -108,15 +108,21 @@ public final class ConnectionManager {
}); });
} }
public Bootstrap createWorker() {
return this.createWorker(this.workerGroup);
}
/** /**
* Creates a TCP {@link Bootstrap} using Velocity's event loops. * Creates a TCP {@link Bootstrap} using Velocity's event loops.
* *
* @param group the event loop group to use
*
* @return a new {@link Bootstrap} * @return a new {@link Bootstrap}
*/ */
public Bootstrap createWorker() { public Bootstrap createWorker(EventLoopGroup group) {
return new Bootstrap() return new Bootstrap()
.channel(this.transportType.socketChannelClass) .channel(this.transportType.socketChannelClass)
.group(this.workerGroup) .group(group)
.option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, .option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
this.server.getConfiguration().getConnectTimeout()) this.server.getConfiguration().getConnectTimeout())