Watcher: Reduce threads on non-data nodes (elastic/x-pack-elasticsearch#3932)

The watcher thread pool is scaled by the number of CPUs and has by
default up to 5x the number of cores. This is needed because we assumme
I/O based waiting workloads for watcher. However if the node is not a
data node, there will not be any execution of watches with the exception
of a user calling the execute watch API on that node.

This means, we can get away with just one thread, so that there is no
need for the JVM to manage more threads on master/client or ingest only
nodes.

Original commit: elastic/x-pack-elasticsearch@b5899401d3
This commit is contained in:
Alexander Reelsen 2018-02-23 09:16:32 +01:00 committed by GitHub
parent 45fb3db062
commit 2ebb21f108
2 changed files with 19 additions and 3 deletions

View File

@ -34,6 +34,7 @@ import org.elasticsearch.env.Environment;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.node.Node;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.ScriptPlugin;
@ -464,13 +465,22 @@ public class Watcher extends Plugin implements ActionPlugin, ScriptPlugin {
* Use five times the number of processors up until 50, then stick with the
* number of processors.
*
* If the node is not a data node, we will never need so much threads, so we
* just return 1 here, which still allows to execute a watch locally, but
* there is no need of managing any more threads here
*
* @param settings The current settings
* @return A number between 5 and the number of processors
*/
static int getWatcherThreadPoolSize(Settings settings) {
int numberOfProcessors = EsExecutors.numberOfProcessors(settings);
long size = Math.max(Math.min(5 * numberOfProcessors, 50), numberOfProcessors);
return Math.toIntExact(size);
boolean isDataNode = Node.NODE_DATA_SETTING.get(settings);
if (isDataNode) {
int numberOfProcessors = EsExecutors.numberOfProcessors(settings);
long size = Math.max(Math.min(5 * numberOfProcessors, 50), numberOfProcessors);
return Math.toIntExact(size);
} else {
return 1;
}
}
@Override

View File

@ -89,5 +89,11 @@ public class WatcherPluginTests extends ESTestCase {
assertThat(Watcher.getWatcherThreadPoolSize(Settings.builder().put("processors", 50).build()), is(50));
assertThat(Watcher.getWatcherThreadPoolSize(Settings.builder().put("processors", 51).build()), is(51));
assertThat(Watcher.getWatcherThreadPoolSize(Settings.builder().put("processors", 96).build()), is(96));
Settings noDataNodeSettings = Settings.builder()
.put("processors", scaledRandomIntBetween(1, 100))
.put("node.data", false)
.build();
assertThat(Watcher.getWatcherThreadPoolSize(noDataNodeSettings), is(1));
}
}