From 14a042fbe523791dbc8ded73136abfa8d851e532 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Thu, 14 May 2020 21:33:46 +0200 Subject: [PATCH] Make No. of Transport Threads == Available CPUs (#56488) (#56780) We never do any file IO or other blocking work on the transport threads so no tangible benefit can be derived from using more threads than CPUs for IO. There are however significant downsides to using more threads than necessary with Netty in particular. Since we use the default setting for `io.netty.allocator.useCacheForAllThreads` which is `true` we end up using up to `16MB` of thread local buffer cache for each transport thread. Meaning we potentially waste CPUs * 16MB of heap for unnecessary IO threads in addition to obvious inefficiencies of artificially adding extra context switches. --- .../org/elasticsearch/transport/netty4/Netty4Transport.java | 2 +- .../org/elasticsearch/transport/nio/NioTransportPlugin.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java index 6e1b2a5eb9b..4fb4bfdd25c 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java @@ -78,7 +78,7 @@ public class Netty4Transport extends TcpTransport { public static final Setting WORKER_COUNT = new Setting<>("transport.netty.worker_count", - (s) -> Integer.toString(EsExecutors.allocatedProcessors(s) * 2), + (s) -> Integer.toString(EsExecutors.allocatedProcessors(s)), (s) -> Setting.parseInt(s, 1, "transport.netty.worker_count"), Property.NodeScope); public static final Setting NETTY_RECEIVE_PREDICTOR_SIZE = Setting.byteSizeSetting( diff --git a/plugins/transport-nio/src/main/java/org/elasticsearch/transport/nio/NioTransportPlugin.java b/plugins/transport-nio/src/main/java/org/elasticsearch/transport/nio/NioTransportPlugin.java index 84097e3a079..1da90e35ba7 100644 --- a/plugins/transport-nio/src/main/java/org/elasticsearch/transport/nio/NioTransportPlugin.java +++ b/plugins/transport-nio/src/main/java/org/elasticsearch/transport/nio/NioTransportPlugin.java @@ -57,7 +57,7 @@ public class NioTransportPlugin extends Plugin implements NetworkPlugin { public static final Setting NIO_WORKER_COUNT = new Setting<>("transport.nio.worker_count", - (s) -> Integer.toString(EsExecutors.allocatedProcessors(s) * 2), + (s) -> Integer.toString(EsExecutors.allocatedProcessors(s)), (s) -> Setting.parseInt(s, 1, "transport.nio.worker_count"), Setting.Property.NodeScope); public static final Setting NIO_HTTP_WORKER_COUNT = intSetting("http.nio.worker_count", 0, 0, Setting.Property.NodeScope);