Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align thread pool info to thread pool configuration #29123

Merged
merged 1 commit into from
Mar 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -138,7 +139,9 @@ public static ThreadPoolType fromType(String type) {
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;

Expand Down Expand Up @@ -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<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());
Expand Down Expand Up @@ -239,16 +251,7 @@ public Counter estimatedTimeInMillisCounter() {
}

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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to recreate this info (garbage!) on every invocation, it is immutable.

return threadPoolInfo;
}

public Info info(String name) {
Expand Down Expand Up @@ -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";
}
}

/**
Expand Down