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.
This commit is contained in:
Jason Tedor 2018-03-16 22:47:06 -04:00 committed by GitHub
parent 22ad52a288
commit 2e93a9158f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 27 deletions

View File

@ -58,6 +58,7 @@ import java.util.concurrent.ScheduledFuture;
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 class ThreadPool extends AbstractComponent implements Scheduler, Closeabl
THREAD_POOL_TYPES = Collections.unmodifiableMap(map);
}
private Map<String, ExecutorHolder> executors = new HashMap<>();
private final Map<String, ExecutorHolder> executors;
private final ThreadPoolInfo threadPoolInfo;
private final CachedTimeThread cachedTimeThread;
@ -207,6 +210,15 @@ public class ThreadPool extends AbstractComponent implements Scheduler, Closeabl
executors.put(Names.SAME, new ExecutorHolder(DIRECT_EXECUTOR, new Info(Names.SAME, ThreadPoolType.DIRECT)));
this.executors = unmodifiableMap(executors);
final List<Info> 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 class ThreadPool extends AbstractComponent implements Scheduler, Closeabl
}
public ThreadPoolInfo info() {
List<Info> 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 class ThreadPool extends AbstractComponent implements Scheduler, Closeabl
@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";
}
}
/**