Skip to content

Commit 723e47a

Browse files
committed
Consolidate network settings, common tcp settings, and generalized port settings, closes #174.
1 parent c59945e commit 723e47a

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpServerTransport.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.util.concurrent.atomic.AtomicReference;
5252

5353
import static org.elasticsearch.util.concurrent.DynamicExecutors.*;
54+
import static org.elasticsearch.util.network.NetworkService.TcpSettings.*;
5455

5556
/**
5657
* @author kimchy (shay.banon)
@@ -102,14 +103,14 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
102103
this.networkService = networkService;
103104
SizeValue maxContentLength = componentSettings.getAsSize("max_content_length", new SizeValue(100, SizeUnit.MB));
104105
this.workerCount = componentSettings.getAsInt("worker_count", Runtime.getRuntime().availableProcessors());
105-
this.port = componentSettings.get("port", "9200-9300");
106+
this.port = componentSettings.get("port", settings.get("http.port", "9200-9300"));
106107
this.bindHost = componentSettings.get("bind_host");
107108
this.publishHost = componentSettings.get("publish_host");
108-
this.tcpNoDelay = componentSettings.getAsBoolean("tcp_no_delay", true);
109-
this.tcpKeepAlive = componentSettings.getAsBoolean("tcp_keep_alive", null);
110-
this.reuseAddress = componentSettings.getAsBoolean("reuse_address", NetworkUtils.defaultReuseAddress());
111-
this.tcpSendBufferSize = componentSettings.getAsSize("tcp_send_buffer_size", null);
112-
this.tcpReceiveBufferSize = componentSettings.getAsSize("tcp_receive_buffer_size", null);
109+
this.tcpNoDelay = componentSettings.getAsBoolean("tcp_no_delay", settings.getAsBoolean(TCP_NO_DELAY, true));
110+
this.tcpKeepAlive = componentSettings.getAsBoolean("tcp_keep_alive", settings.getAsBoolean(TCP_KEEP_ALIVE, null));
111+
this.reuseAddress = componentSettings.getAsBoolean("reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress()));
112+
this.tcpSendBufferSize = componentSettings.getAsSize("tcp_send_buffer_size", settings.getAsSize(TCP_SEND_BUFFER_SIZE, null));
113+
this.tcpReceiveBufferSize = componentSettings.getAsSize("tcp_receive_buffer_size", settings.getAsSize(TCP_RECEIVE_BUFFER_SIZE, null));
113114

114115
// validate max content length
115116
if (maxContentLength.bytes() > Integer.MAX_VALUE) {

modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import static org.elasticsearch.util.collect.Lists.*;
7070
import static org.elasticsearch.util.concurrent.ConcurrentCollections.*;
7171
import static org.elasticsearch.util.concurrent.DynamicExecutors.*;
72+
import static org.elasticsearch.util.network.NetworkService.TcpSettings.*;
7273
import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*;
7374
import static org.elasticsearch.util.transport.NetworkExceptionHelper.*;
7475

@@ -141,16 +142,16 @@ public NettyTransport(Settings settings, ThreadPool threadPool) {
141142
this.networkService = networkService;
142143

143144
this.workerCount = componentSettings.getAsInt("worker_count", Runtime.getRuntime().availableProcessors());
144-
this.port = componentSettings.get("port", "9300-9400");
145+
this.port = componentSettings.get("port", settings.get("transport.tcp.port", "9300-9400"));
145146
this.bindHost = componentSettings.get("bind_host");
146147
this.connectionsPerNode = componentSettings.getAsInt("connections_per_node", 5);
147148
this.publishHost = componentSettings.get("publish_host");
148149
this.connectTimeout = componentSettings.getAsTime("connect_timeout", timeValueSeconds(1));
149-
this.tcpNoDelay = componentSettings.getAsBoolean("tcp_no_delay", true);
150-
this.tcpKeepAlive = componentSettings.getAsBoolean("tcp_keep_alive", null);
151-
this.reuseAddress = componentSettings.getAsBoolean("reuse_address", NetworkUtils.defaultReuseAddress());
152-
this.tcpSendBufferSize = componentSettings.getAsSize("tcp_send_buffer_size", null);
153-
this.tcpReceiveBufferSize = componentSettings.getAsSize("tcp_receive_buffer_size", null);
150+
this.tcpNoDelay = componentSettings.getAsBoolean("tcp_no_delay", settings.getAsBoolean(TCP_NO_DELAY, true));
151+
this.tcpKeepAlive = componentSettings.getAsBoolean("tcp_keep_alive", settings.getAsBoolean(TCP_KEEP_ALIVE, null));
152+
this.reuseAddress = componentSettings.getAsBoolean("reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress()));
153+
this.tcpSendBufferSize = componentSettings.getAsSize("tcp_send_buffer_size", settings.getAsSize(TCP_SEND_BUFFER_SIZE, null));
154+
this.tcpReceiveBufferSize = componentSettings.getAsSize("tcp_receive_buffer_size", settings.getAsSize(TCP_RECEIVE_BUFFER_SIZE, null));
154155
}
155156

156157
public Settings settings() {

modules/elasticsearch/src/main/java/org/elasticsearch/util/network/NetworkService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ public class NetworkService extends AbstractComponent {
4242
private static final String GLOBAL_NETWORK_BINDHOST_SETTING = "network.bind_host";
4343
private static final String GLOBAL_NETWORK_PUBLISHHOST_SETTING = "network.publish_host";
4444

45+
public static final class TcpSettings {
46+
public static final String TCP_NO_DELAY = "network.tcp.no_delay";
47+
public static final String TCP_KEEP_ALIVE = "network.tcp.keep_alive";
48+
public static final String TCP_REUSE_ADDRESS = "network.tcp.reuse_address";
49+
public static final String TCP_SEND_BUFFER_SIZE = "network.tcp.send_buffer_size";
50+
public static final String TCP_RECEIVE_BUFFER_SIZE = "network.tcp.receive_buffer_size";
51+
}
52+
4553
public static interface CustomNameResolver {
4654
InetAddress resolve();
4755
}

plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransport.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.concurrent.atomic.AtomicReference;
4848

4949
import static org.elasticsearch.util.concurrent.DynamicExecutors.*;
50+
import static org.elasticsearch.util.network.NetworkService.TcpSettings.*;
5051

5152
/**
5253
* @author kimchy (shay.banon)
@@ -89,14 +90,14 @@ public class NettyMemcachedServerTransport extends AbstractLifecycleComponent<Me
8990
this.networkService = networkService;
9091

9192
this.workerCount = componentSettings.getAsInt("worker_count", Runtime.getRuntime().availableProcessors());
92-
this.port = componentSettings.get("port", "11211-11311");
93+
this.port = componentSettings.get("port", settings.get("memcached.port", "11211-11311"));
9394
this.bindHost = componentSettings.get("bind_host");
9495
this.publishHost = componentSettings.get("publish_host");
95-
this.tcpNoDelay = componentSettings.getAsBoolean("tcp_no_delay", true);
96-
this.tcpKeepAlive = componentSettings.getAsBoolean("tcp_keep_alive", null);
97-
this.reuseAddress = componentSettings.getAsBoolean("reuse_address", NetworkUtils.defaultReuseAddress());
98-
this.tcpSendBufferSize = componentSettings.getAsSize("tcp_send_buffer_size", null);
99-
this.tcpReceiveBufferSize = componentSettings.getAsSize("tcp_receive_buffer_size", null);
96+
this.tcpNoDelay = componentSettings.getAsBoolean("tcp_no_delay", settings.getAsBoolean(TCP_NO_DELAY, true));
97+
this.tcpKeepAlive = componentSettings.getAsBoolean("tcp_keep_alive", settings.getAsBoolean(TCP_KEEP_ALIVE, null));
98+
this.reuseAddress = componentSettings.getAsBoolean("reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress()));
99+
this.tcpSendBufferSize = componentSettings.getAsSize("tcp_send_buffer_size", settings.getAsSize(TCP_SEND_BUFFER_SIZE, null));
100+
this.tcpReceiveBufferSize = componentSettings.getAsSize("tcp_receive_buffer_size", settings.getAsSize(TCP_RECEIVE_BUFFER_SIZE, null));
100101
}
101102

102103
@Override public BoundTransportAddress boundAddress() {

0 commit comments

Comments
 (0)