13
0
geforkt von Mirrors/Velocity

Introduce TCP_FASTOPEN support

For best results, use Linux 4.11+ and a server modified to set the
TCP_FASTOPEN flag.

This should in particular benefit users of legacy forwarding.
Dieser Commit ist enthalten in:
Andrew Steinborn 2019-07-29 17:32:56 -04:00
Ursprung 0acb1ed7d4
Commit 121ab41d96
2 geänderte Dateien mit 25 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -372,6 +372,10 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
return advanced.isProxyProtocol(); return advanced.isProxyProtocol();
} }
public boolean useTcpFastOpen() {
return advanced.tcpFastOpen;
}
public Metrics getMetrics() { public Metrics getMetrics() {
return metrics; return metrics;
} }
@ -608,6 +612,10 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
@ConfigKey("proxy-protocol") @ConfigKey("proxy-protocol")
private boolean proxyProtocol = false; private boolean proxyProtocol = false;
@Comment("Enables TCP fast open support on the proxy. Requires the proxy to run on Linux.")
@ConfigKey("tcp-fast-open")
private boolean tcpFastOpen = false;
private Advanced() { private Advanced() {
} }
@ -619,6 +627,7 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
this.connectionTimeout = toml.getLong("connection-timeout", 5000L).intValue(); this.connectionTimeout = toml.getLong("connection-timeout", 5000L).intValue();
this.readTimeout = toml.getLong("read-timeout", 30000L).intValue(); this.readTimeout = toml.getLong("read-timeout", 30000L).intValue();
this.proxyProtocol = toml.getBoolean("proxy-protocol", false); this.proxyProtocol = toml.getBoolean("proxy-protocol", false);
this.tcpFastOpen = toml.getBoolean("tcp-fast-open", false);
} }
} }
@ -646,6 +655,10 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
return proxyProtocol; return proxyProtocol;
} }
public boolean isTcpFastOpen() {
return tcpFastOpen;
}
@Override @Override
public String toString() { public String toString() {
return "Advanced{" return "Advanced{"
@ -655,6 +668,7 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
+ ", connectionTimeout=" + connectionTimeout + ", connectionTimeout=" + connectionTimeout
+ ", readTimeout=" + readTimeout + ", readTimeout=" + readTimeout
+ ", proxyProtocol=" + proxyProtocol + ", proxyProtocol=" + proxyProtocol
+ ", tcpFastOpen=" + tcpFastOpen
+ '}'; + '}';
} }
} }

Datei anzeigen

@ -15,6 +15,7 @@ import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.WriteBufferWaterMark; import io.netty.channel.WriteBufferWaterMark;
import io.netty.channel.epoll.EpollChannelOption;
import io.netty.resolver.dns.DnsAddressResolverGroup; import io.netty.resolver.dns.DnsAddressResolverGroup;
import io.netty.resolver.dns.DnsNameResolverBuilder; import io.netty.resolver.dns.DnsNameResolverBuilder;
import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.EventExecutor;
@ -102,6 +103,11 @@ public final class ConnectionManager {
.childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.TCP_NODELAY, true)
.childOption(ChannelOption.IP_TOS, 0x18) .childOption(ChannelOption.IP_TOS, 0x18)
.localAddress(address); .localAddress(address);
if (server.getConfiguration().useTcpFastOpen()) {
bootstrap.option(EpollChannelOption.TCP_FASTOPEN, 3);
}
bootstrap.bind() bootstrap.bind()
.addListener((ChannelFutureListener) future -> { .addListener((ChannelFutureListener) future -> {
final Channel channel = future.channel(); final Channel channel = future.channel();
@ -151,13 +157,17 @@ public final class ConnectionManager {
* @return a new {@link Bootstrap} * @return a new {@link Bootstrap}
*/ */
public Bootstrap createWorker(@Nullable EventLoopGroup group) { public Bootstrap createWorker(@Nullable EventLoopGroup group) {
return new Bootstrap() Bootstrap bootstrap = new Bootstrap()
.channel(this.transportType.socketChannelClass) .channel(this.transportType.socketChannelClass)
.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())
.group(group == null ? this.workerGroup : group) .group(group == null ? this.workerGroup : group)
.resolver(this.resolverGroup); .resolver(this.resolverGroup);
if (server.getConfiguration().useTcpFastOpen()) {
bootstrap.option(EpollChannelOption.TCP_FASTOPEN_CONNECT, true);
}
return bootstrap;
} }
/** /**