Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-12-23 23:00:35 +01:00
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:
Ursprung
865f9e5ef9
Commit
56873712ec
@ -41,6 +41,7 @@ import com.velocitypowered.proxy.util.VelocityChannelRegistrar;
|
||||
import com.velocitypowered.proxy.util.ratelimit.Ratelimiter;
|
||||
import com.velocitypowered.proxy.util.ratelimit.Ratelimiters;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.file.Files;
|
||||
@ -239,6 +240,10 @@ public class VelocityServer implements ProxyServer {
|
||||
return this.cm.createWorker();
|
||||
}
|
||||
|
||||
public Bootstrap initializeGenericBootstrap(EventLoopGroup group) {
|
||||
return this.cm.createWorker(group);
|
||||
}
|
||||
|
||||
public boolean isShutdown() {
|
||||
return shutdown;
|
||||
}
|
||||
|
@ -71,7 +71,9 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
*/
|
||||
public CompletableFuture<ConnectionRequestBuilder.Result> connect() {
|
||||
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>() {
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception {
|
||||
|
@ -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.
|
||||
*
|
||||
* @param group the event loop group to use
|
||||
*
|
||||
* @return a new {@link Bootstrap}
|
||||
*/
|
||||
public Bootstrap createWorker() {
|
||||
public Bootstrap createWorker(EventLoopGroup group) {
|
||||
return new Bootstrap()
|
||||
.channel(this.transportType.socketChannelClass)
|
||||
.group(this.workerGroup)
|
||||
.group(group)
|
||||
.option(ChannelOption.TCP_NODELAY, true)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
|
||||
this.server.getConfiguration().getConnectTimeout())
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren