From 1798c9f0d16cac32563fc766c6a27e9275d65bfb Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 16 Mar 2018 22:47:06 -0400 Subject: [PATCH] Align thread pool info to thread pool configuration (#29123) Today we report thread pool info using a common object. This means that we use a shared set of terminology that is not consistent with the terminology used to the configure thread pools. This holds in particular for the minimum and maximum number of threads in the thread pool where we use the following terminology: thread pool info | fixed | scaling min core size max max size This commit changes the display of thread pool info to be dependent on the type of the thread pool so that we can align the terminology in the output of thread pool info with the terminology used to configure a thread pool. --- .../elasticsearch/threadpool/ThreadPool.java | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java b/server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java index 6abdc309e21b0..c7d16d1979b20 100644 --- a/server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java +++ b/server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java @@ -58,6 +58,7 @@ import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import static java.util.Collections.unmodifiableMap; @@ -138,7 +139,9 @@ public static ThreadPoolType fromType(String type) { THREAD_POOL_TYPES = Collections.unmodifiableMap(map); } - private Map executors = new HashMap<>(); + private final Map executors; + + private final ThreadPoolInfo threadPoolInfo; private final CachedTimeThread cachedTimeThread; @@ -207,6 +210,15 @@ public ThreadPool(final Settings settings, final ExecutorBuilder... customBui executors.put(Names.SAME, new ExecutorHolder(DIRECT_EXECUTOR, new Info(Names.SAME, ThreadPoolType.DIRECT))); this.executors = unmodifiableMap(executors); + + final List infos = + executors + .values() + .stream() + .filter(holder -> holder.info.getName().equals("same") == false) + .map(holder -> holder.info) + .collect(Collectors.toList()); + this.threadPoolInfo = new ThreadPoolInfo(infos); this.scheduler = Scheduler.initScheduler(settings); TimeValue estimatedTimeInterval = ESTIMATED_TIME_INTERVAL_SETTING.get(settings); this.cachedTimeThread = new CachedTimeThread(EsExecutors.threadName(settings, "[timer]"), estimatedTimeInterval.millis()); @@ -239,16 +251,7 @@ public Counter estimatedTimeInMillisCounter() { } public ThreadPoolInfo info() { - List infos = new ArrayList<>(); - for (ExecutorHolder holder : executors.values()) { - String name = holder.info.getName(); - // no need to have info on "same" thread pool - if ("same".equals(name)) { - continue; - } - infos.add(holder.info); - } - return new ThreadPoolInfo(infos); + return threadPoolInfo; } public Info info(String name) { @@ -655,32 +658,29 @@ public SizeValue getQueueSize() { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(name); - builder.field(Fields.TYPE, type.getType()); - if (min != -1) { - builder.field(Fields.MIN, min); - } - if (max != -1) { - builder.field(Fields.MAX, max); + builder.field("type", type.getType()); + + if (type == ThreadPoolType.SCALING) { + assert min != -1; + builder.field("core", min); + assert max != -1; + builder.field("max", max); + } else { + assert max != -1; + builder.field("size", max); } if (keepAlive != null) { - builder.field(Fields.KEEP_ALIVE, keepAlive.toString()); + builder.field("keep_alive", keepAlive.toString()); } if (queueSize == null) { - builder.field(Fields.QUEUE_SIZE, -1); + builder.field("queue_size", -1); } else { - builder.field(Fields.QUEUE_SIZE, queueSize.singles()); + builder.field("queue_size", queueSize.singles()); } builder.endObject(); return builder; } - static final class Fields { - static final String TYPE = "type"; - static final String MIN = "min"; - static final String MAX = "max"; - static final String KEEP_ALIVE = "keep_alive"; - static final String QUEUE_SIZE = "queue_size"; - } } /**