Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable IP_TRANSPARENT on epoll channel bind #1653

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions zuul-core/src/main/java/com/netflix/zuul/netty/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.netflix.zuul.netty.server;

import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.VisibleForTesting;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.config.DynamicBooleanProperty;
Expand Down Expand Up @@ -63,9 +64,6 @@
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.EventExecutorChooserFactory;
import io.netty.util.concurrent.ThreadPerTaskExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetSocketAddress;
import java.nio.channels.spi.SelectorProvider;
import java.util.ArrayList;
Expand All @@ -80,21 +78,19 @@
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import static com.google.common.base.Preconditions.checkNotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
* NOTE: Shout-out to <a href="https://github.com/adamfisk/LittleProxy">LittleProxy</a> which was great as a reference.
*
* User: michaels
* Date: 11/8/14
* Time: 8:39 PM
* <p>
* User: michaels Date: 11/8/14 Time: 8:39 PM
*/
public class Server {

/**
* This field is effectively a noop, as Epoll is enabled automatically if available. This can be disabled by
* using the {@link #FORCE_NIO} property.
* This field is effectively a noop, as Epoll is enabled automatically if available. This can be disabled by using
* the {@link #FORCE_NIO} property.
*/
@Deprecated
public static final DynamicBooleanProperty USE_EPOLL =
Expand Down Expand Up @@ -141,9 +137,9 @@ public class Server {
public static final AtomicReference<Class<? extends Channel>> defaultOutboundChannelType = new AtomicReference<>();

/**
* Use {@link #Server(Registry, ServerStatusManager, Map, ClientConnectionsShutdown, EventLoopGroupMetrics,
* EventLoopConfig)}
* instead.
* Use
* {@link #Server(Registry, ServerStatusManager, Map, ClientConnectionsShutdown, EventLoopGroupMetrics,
* EventLoopConfig)} instead.
*/
@SuppressWarnings("rawtypes")
@Deprecated
Expand All @@ -161,9 +157,9 @@ public Server(
}

/**
* Use {@link #Server(Registry, ServerStatusManager, Map, ClientConnectionsShutdown, EventLoopGroupMetrics,
* EventLoopConfig)}
* instead.
* Use
* {@link #Server(Registry, ServerStatusManager, Map, ClientConnectionsShutdown, EventLoopGroupMetrics,
* EventLoopConfig)} instead.
*/
@SuppressWarnings({"unchecked", "rawtypes"
}) // Channel init map has the wrong generics and we can't fix without api breakage.
Expand Down Expand Up @@ -298,6 +294,11 @@ private ChannelFuture setupServerBootstrap(
serverBootstrap.childOption(ChannelOption.TCP_NODELAY, true);
serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);

if (epollIsAvailable()) {
LOG.info("******* Enabling IP_TRANSPARENT for epoll channel bound to {}", listenAddress);
serverBootstrap.childOption(EpollChannelOption.IP_TRANSPARENT, true);
}

// Apply transport specific socket options.
for (Map.Entry<ChannelOption<?>, ?> optionEntry : serverGroup.transportChannelOptions.entrySet()) {
serverBootstrap = serverBootstrap.option((ChannelOption) optionEntry.getKey(), optionEntry.getValue());
Expand Down Expand Up @@ -329,14 +330,18 @@ private ChannelFuture setupServerBootstrap(
/**
* Override for metrics or informational purposes
*
* @param clientToProxyBossPool - acceptor pool
* @param clientToProxyBossPool - acceptor pool
* @param clientToProxyWorkerPool - worker pool
*/
public void postEventLoopCreationHook(
EventLoopGroup clientToProxyBossPool, EventLoopGroup clientToProxyWorkerPool) {}
EventLoopGroup clientToProxyBossPool, EventLoopGroup clientToProxyWorkerPool) {
}

private final class ServerGroup {
/** A name for this ServerGroup to use in naming threads. */

/**
* A name for this ServerGroup to use in naming threads.
*/
private final String name;

private final int acceptorThreads;
Expand Down Expand Up @@ -543,4 +548,4 @@ private static boolean kqueueIsAvailable() {
}
return available;
}
}
}