Skip to content

Commit 2e93a91

Browse files
authored
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.
1 parent 22ad52a commit 2e93a91

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java

+27-27
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import java.util.concurrent.ScheduledThreadPoolExecutor;
5959
import java.util.concurrent.ThreadPoolExecutor;
6060
import java.util.concurrent.TimeUnit;
61+
import java.util.stream.Collectors;
6162

6263
import static java.util.Collections.unmodifiableMap;
6364

@@ -138,7 +139,9 @@ public static ThreadPoolType fromType(String type) {
138139
THREAD_POOL_TYPES = Collections.unmodifiableMap(map);
139140
}
140141

141-
private Map<String, ExecutorHolder> executors = new HashMap<>();
142+
private final Map<String, ExecutorHolder> executors;
143+
144+
private final ThreadPoolInfo threadPoolInfo;
142145

143146
private final CachedTimeThread cachedTimeThread;
144147

@@ -207,6 +210,15 @@ public ThreadPool(final Settings settings, final ExecutorBuilder<?>... customBui
207210

208211
executors.put(Names.SAME, new ExecutorHolder(DIRECT_EXECUTOR, new Info(Names.SAME, ThreadPoolType.DIRECT)));
209212
this.executors = unmodifiableMap(executors);
213+
214+
final List<Info> infos =
215+
executors
216+
.values()
217+
.stream()
218+
.filter(holder -> holder.info.getName().equals("same") == false)
219+
.map(holder -> holder.info)
220+
.collect(Collectors.toList());
221+
this.threadPoolInfo = new ThreadPoolInfo(infos);
210222
this.scheduler = Scheduler.initScheduler(settings);
211223
TimeValue estimatedTimeInterval = ESTIMATED_TIME_INTERVAL_SETTING.get(settings);
212224
this.cachedTimeThread = new CachedTimeThread(EsExecutors.threadName(settings, "[timer]"), estimatedTimeInterval.millis());
@@ -239,16 +251,7 @@ public Counter estimatedTimeInMillisCounter() {
239251
}
240252

241253
public ThreadPoolInfo info() {
242-
List<Info> infos = new ArrayList<>();
243-
for (ExecutorHolder holder : executors.values()) {
244-
String name = holder.info.getName();
245-
// no need to have info on "same" thread pool
246-
if ("same".equals(name)) {
247-
continue;
248-
}
249-
infos.add(holder.info);
250-
}
251-
return new ThreadPoolInfo(infos);
254+
return threadPoolInfo;
252255
}
253256

254257
public Info info(String name) {
@@ -655,32 +658,29 @@ public SizeValue getQueueSize() {
655658
@Override
656659
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
657660
builder.startObject(name);
658-
builder.field(Fields.TYPE, type.getType());
659-
if (min != -1) {
660-
builder.field(Fields.MIN, min);
661-
}
662-
if (max != -1) {
663-
builder.field(Fields.MAX, max);
661+
builder.field("type", type.getType());
662+
663+
if (type == ThreadPoolType.SCALING) {
664+
assert min != -1;
665+
builder.field("core", min);
666+
assert max != -1;
667+
builder.field("max", max);
668+
} else {
669+
assert max != -1;
670+
builder.field("size", max);
664671
}
665672
if (keepAlive != null) {
666-
builder.field(Fields.KEEP_ALIVE, keepAlive.toString());
673+
builder.field("keep_alive", keepAlive.toString());
667674
}
668675
if (queueSize == null) {
669-
builder.field(Fields.QUEUE_SIZE, -1);
676+
builder.field("queue_size", -1);
670677
} else {
671-
builder.field(Fields.QUEUE_SIZE, queueSize.singles());
678+
builder.field("queue_size", queueSize.singles());
672679
}
673680
builder.endObject();
674681
return builder;
675682
}
676683

677-
static final class Fields {
678-
static final String TYPE = "type";
679-
static final String MIN = "min";
680-
static final String MAX = "max";
681-
static final String KEEP_ALIVE = "keep_alive";
682-
static final String QUEUE_SIZE = "queue_size";
683-
}
684684
}
685685

686686
/**

0 commit comments

Comments
 (0)