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

Set specific keepalive options by default on supported platforms #59278

Merged
merged 18 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"Default TCP keepalive settings":
- do:
cluster.get_settings:
include_defaults: true

- match: { defaults.network.tcp.keep_idle: "60" }
- match: { defaults.network.tcp.keep_interval: "10" }
- match: { defaults.network.tcp.keep_count: "3" }
15 changes: 9 additions & 6 deletions docs/reference/modules/transport.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,22 @@ example above:
determines the time in seconds that a connection must be idle before
starting to send TCP keepalive probes.
ywelsch marked this conversation as resolved.
Show resolved Hide resolved
Only applicable on Linux and Mac, and requires JDK 11 or newer.
Defaults to -1, which does not set this option at the socket level, but
uses default system configuration instead.
Defaults to 60 on applicable configurations, and -1 otherwise, which does
ywelsch marked this conversation as resolved.
Show resolved Hide resolved
not set this option at the socket level, but uses the default system
configuration instead.
* `tcp.keep_interval`: Configures the `TCP_KEEPINTVL` option for this socket,
which determines the time in seconds between sending TCP keepalive probes.
Only applicable on Linux and Mac, and requires JDK 11 or newer.
Defaults to -1, which does not set this option at the socket level, but
uses default system configuration instead.
Defaults to 10 on applicable configurations, and -1 otherwise, which does
ywelsch marked this conversation as resolved.
Show resolved Hide resolved
not set this option at the socket level, but uses the default system
configuration instead.
* `tcp.keep_count`: Configures the `TCP_KEEPCNT` option for this socket, which
determines the number of unacknowledged TCP keepalive probes that may be
sent on a connection before it is dropped.
Only applicable on Linux and Mac, and requires JDK 11 or newer.
Defaults to -1, which does not set this option at the socket level, but
uses default system configuration instead.
Defaults to 3 on applicable configurations, and -1 otherwise, which does
not set this option at the socket level, but uses the default system
configuration instead.
* `tcp.reuse_address`: Configures the `SO_REUSEADDR` option for this socket
* `tcp.send_buffer_size`: Configures the send buffer size of the socket
* `tcp.receive_buffer_size`: Configures the receive buffer size of the socket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,23 @@ private Bootstrap createClientBootstrap(SharedGroupFactory.SharedGroup sharedGro
bootstrap.option(ChannelOption.TCP_NODELAY, TransportSettings.TCP_NO_DELAY.get(settings));
bootstrap.option(ChannelOption.SO_KEEPALIVE, TransportSettings.TCP_KEEP_ALIVE.get(settings));
if (TransportSettings.TCP_KEEP_ALIVE.get(settings)) {
// Netty logs a warning if it can't set the option, so try this only on supported platforms
if (IOUtils.LINUX || IOUtils.MAC_OS_X) {
if (TransportSettings.TCP_KEEP_IDLE.get(settings) >= 0) {
final SocketOption<Integer> keepIdleOption = NetUtils.getTcpKeepIdleSocketOptionOrNull();
if (keepIdleOption != null) {
bootstrap.option(NioChannelOption.of(keepIdleOption), TransportSettings.TCP_KEEP_IDLE.get(settings));
}
// Note that Netty logs a warning if it can't set the option
if (TransportSettings.TCP_KEEP_IDLE.get(settings) >= 0) {
final SocketOption<Integer> keepIdleOption = NetUtils.getTcpKeepIdleSocketOptionOrNull();
if (keepIdleOption != null) {
bootstrap.option(NioChannelOption.of(keepIdleOption), TransportSettings.TCP_KEEP_IDLE.get(settings));
}
if (TransportSettings.TCP_KEEP_INTERVAL.get(settings) >= 0) {
final SocketOption<Integer> keepIntervalOption = NetUtils.getTcpKeepIntervalSocketOptionOrNull();
if (keepIntervalOption != null) {
bootstrap.option(NioChannelOption.of(keepIntervalOption), TransportSettings.TCP_KEEP_INTERVAL.get(settings));
}
}
if (TransportSettings.TCP_KEEP_INTERVAL.get(settings) >= 0) {
final SocketOption<Integer> keepIntervalOption = NetUtils.getTcpKeepIntervalSocketOptionOrNull();
if (keepIntervalOption != null) {
bootstrap.option(NioChannelOption.of(keepIntervalOption), TransportSettings.TCP_KEEP_INTERVAL.get(settings));
}
if (TransportSettings.TCP_KEEP_COUNT.get(settings) >= 0) {
final SocketOption<Integer> keepCountOption = NetUtils.getTcpKeepCountSocketOptionOrNull();
if (keepCountOption != null) {
bootstrap.option(NioChannelOption.of(keepCountOption), TransportSettings.TCP_KEEP_COUNT.get(settings));
}
}
if (TransportSettings.TCP_KEEP_COUNT.get(settings) >= 0) {
final SocketOption<Integer> keepCountOption = NetUtils.getTcpKeepCountSocketOptionOrNull();
if (keepCountOption != null) {
bootstrap.option(NioChannelOption.of(keepCountOption), TransportSettings.TCP_KEEP_COUNT.get(settings));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@

package org.elasticsearch.common.network;

import org.elasticsearch.bootstrap.JavaVersion;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.core.internal.io.IOUtils;

import java.io.IOException;
import java.net.InetAddress;
Expand Down Expand Up @@ -50,12 +53,16 @@ public final class NetworkService {
Setting.boolSetting("network.tcp.no_delay", true, Property.NodeScope);
public static final Setting<Boolean> TCP_KEEP_ALIVE =
Setting.boolSetting("network.tcp.keep_alive", true, Property.NodeScope);
public static final boolean SET_EXTRA_KEEP_ALIVE_OPTIONS =
Booleans.parseBoolean(System.getProperty("es.network.tcp.extra_keep_alive_options", "false")) == false &&
(IOUtils.LINUX || IOUtils.MAC_OS_X) &&
JavaVersion.current().compareTo(JavaVersion.parse("11")) >= 0;
public static final Setting<Integer> TCP_KEEP_IDLE =
Setting.intSetting("network.tcp.keep_idle", -1, -1, Property.NodeScope);
Setting.intSetting("network.tcp.keep_idle", SET_EXTRA_KEEP_ALIVE_OPTIONS ? 60 : -1, -1, Property.NodeScope);
public static final Setting<Integer> TCP_KEEP_INTERVAL =
Setting.intSetting("network.tcp.keep_interval", -1, -1, Property.NodeScope);
Setting.intSetting("network.tcp.keep_interval", SET_EXTRA_KEEP_ALIVE_OPTIONS ? 10 : -1, -1, Property.NodeScope);
public static final Setting<Integer> TCP_KEEP_COUNT =
Setting.intSetting("network.tcp.keep_count", -1, -1, Property.NodeScope);
Setting.intSetting("network.tcp.keep_count", SET_EXTRA_KEEP_ALIVE_OPTIONS ? 3 : -1, -1, Property.NodeScope);
public static final Setting<Boolean> TCP_REUSE_ADDRESS =
Setting.boolSetting("network.tcp.reuse_address", NetworkUtils.defaultReuseAddress(), Property.NodeScope);
public static final Setting<ByteSizeValue> TCP_SEND_BUFFER_SIZE =
Expand Down