use of org.opensearch.threadpool.ThreadPoolInfo in project OpenSearch by opensearch-project.
the class RestThreadPoolAction method buildTable.
private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) {
final String[] threadPools = req.paramAsStringArray("thread_pool_patterns", new String[] { "*" });
final DiscoveryNodes nodes = state.getState().nodes();
final Table table = getTableWithHeader(req);
// collect all thread pool names that we see across the nodes
final Set<String> candidates = new HashSet<>();
for (final NodeStats nodeStats : nodesStats.getNodes()) {
for (final ThreadPoolStats.Stats threadPoolStats : nodeStats.getThreadPool()) {
candidates.add(threadPoolStats.getName());
}
}
// collect all thread pool names that match the specified thread pool patterns
final Set<String> included = new HashSet<>();
for (final String candidate : candidates) {
if (Regex.simpleMatch(threadPools, candidate)) {
included.add(candidate);
}
}
for (final DiscoveryNode node : nodes) {
final NodeInfo info = nodesInfo.getNodesMap().get(node.getId());
final NodeStats stats = nodesStats.getNodesMap().get(node.getId());
final Map<String, ThreadPoolStats.Stats> poolThreadStats;
final Map<String, ThreadPool.Info> poolThreadInfo;
if (stats == null) {
poolThreadStats = Collections.emptyMap();
poolThreadInfo = Collections.emptyMap();
} else {
// we use a sorted map to ensure that thread pools are sorted by name
poolThreadStats = new TreeMap<>();
poolThreadInfo = new HashMap<>();
ThreadPoolStats threadPoolStats = stats.getThreadPool();
for (ThreadPoolStats.Stats threadPoolStat : threadPoolStats) {
poolThreadStats.put(threadPoolStat.getName(), threadPoolStat);
}
if (info != null) {
for (ThreadPool.Info threadPoolInfo : info.getInfo(ThreadPoolInfo.class)) {
poolThreadInfo.put(threadPoolInfo.getName(), threadPoolInfo);
}
}
}
for (Map.Entry<String, ThreadPoolStats.Stats> entry : poolThreadStats.entrySet()) {
if (!included.contains(entry.getKey()))
continue;
table.startRow();
table.addCell(node.getName());
table.addCell(node.getId());
table.addCell(node.getEphemeralId());
table.addCell(info == null ? null : info.getInfo(ProcessInfo.class).getId());
table.addCell(node.getHostName());
table.addCell(node.getHostAddress());
table.addCell(node.getAddress().address().getPort());
final ThreadPoolStats.Stats poolStats = entry.getValue();
final ThreadPool.Info poolInfo = poolThreadInfo.get(entry.getKey());
Long maxQueueSize = null;
String keepAlive = null;
Integer core = null;
Integer max = null;
Integer size = null;
if (poolInfo != null) {
if (poolInfo.getQueueSize() != null) {
maxQueueSize = poolInfo.getQueueSize().singles();
}
if (poolInfo.getKeepAlive() != null) {
keepAlive = poolInfo.getKeepAlive().toString();
}
if (poolInfo.getThreadPoolType() == ThreadPool.ThreadPoolType.SCALING) {
assert poolInfo.getMin() >= 0;
core = poolInfo.getMin();
assert poolInfo.getMax() > 0;
max = poolInfo.getMax();
} else {
assert poolInfo.getMin() == poolInfo.getMax() && poolInfo.getMax() > 0;
size = poolInfo.getMax();
}
}
table.addCell(entry.getKey());
table.addCell(poolInfo == null ? null : poolInfo.getThreadPoolType().getType());
table.addCell(poolStats == null ? null : poolStats.getActive());
table.addCell(poolStats == null ? null : poolStats.getThreads());
table.addCell(poolStats == null ? null : poolStats.getQueue());
table.addCell(maxQueueSize == null ? -1 : maxQueueSize);
table.addCell(poolStats == null ? null : poolStats.getRejected());
table.addCell(poolStats == null ? null : poolStats.getLargest());
table.addCell(poolStats == null ? null : poolStats.getCompleted());
table.addCell(core);
table.addCell(max);
table.addCell(size);
table.addCell(keepAlive);
table.endRow();
}
}
return table;
}
use of org.opensearch.threadpool.ThreadPoolInfo in project OpenSearch by opensearch-project.
the class DeterministicTaskQueue method getThreadPool.
/**
* @return A <code>ThreadPool</code> that uses this task queue and wraps <code>Runnable</code>s in the given wrapper.
*/
public ThreadPool getThreadPool(Function<Runnable, Runnable> runnableWrapper) {
return new ThreadPool(settings) {
{
stopCachedTimeThread();
}
private final Map<String, ThreadPool.Info> infos = new HashMap<>();
private final ExecutorService forkingExecutor = new ExecutorService() {
@Override
public void shutdown() {
throw new UnsupportedOperationException();
}
@Override
public List<Runnable> shutdownNow() {
throw new UnsupportedOperationException();
}
@Override
public boolean isShutdown() {
throw new UnsupportedOperationException();
}
@Override
public boolean isTerminated() {
throw new UnsupportedOperationException();
}
@Override
public boolean awaitTermination(long timeout, TimeUnit unit) {
throw new UnsupportedOperationException();
}
@Override
public <T> Future<T> submit(Callable<T> task) {
throw new UnsupportedOperationException();
}
@Override
public <T> Future<T> submit(Runnable task, T result1) {
throw new UnsupportedOperationException();
}
@Override
public Future<?> submit(Runnable task) {
throw new UnsupportedOperationException();
}
@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) {
throw new UnsupportedOperationException();
}
@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) {
throw new UnsupportedOperationException();
}
@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) {
throw new UnsupportedOperationException();
}
@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) {
throw new UnsupportedOperationException();
}
@Override
public void execute(Runnable command) {
scheduleNow(runnableWrapper.apply(command));
}
};
@Override
public long relativeTimeInMillis() {
return currentTimeMillis;
}
@Override
public long absoluteTimeInMillis() {
return currentTimeMillis;
}
@Override
public ThreadPoolInfo info() {
throw new UnsupportedOperationException();
}
@Override
public Info info(String name) {
return infos.computeIfAbsent(name, n -> new Info(n, ThreadPoolType.FIXED, random.nextInt(10) + 1));
}
@Override
public ThreadPoolStats stats() {
throw new UnsupportedOperationException();
}
@Override
public ExecutorService generic() {
return executor(Names.GENERIC);
}
@Override
public ExecutorService executor(String name) {
return Names.SAME.equals(name) ? OpenSearchExecutors.newDirectExecutorService() : forkingExecutor;
}
@Override
public ScheduledCancellable schedule(Runnable command, TimeValue delay, String executor) {
final int NOT_STARTED = 0;
final int STARTED = 1;
final int CANCELLED = 2;
final AtomicInteger taskState = new AtomicInteger(NOT_STARTED);
scheduleAt(currentTimeMillis + delay.millis(), runnableWrapper.apply(new Runnable() {
@Override
public void run() {
if (taskState.compareAndSet(NOT_STARTED, STARTED)) {
command.run();
}
}
@Override
public String toString() {
return command.toString();
}
}));
return new ScheduledCancellable() {
@Override
public long getDelay(TimeUnit unit) {
throw new UnsupportedOperationException();
}
@Override
public int compareTo(Delayed o) {
throw new UnsupportedOperationException();
}
@Override
public boolean cancel() {
return taskState.compareAndSet(NOT_STARTED, CANCELLED);
}
@Override
public boolean isCancelled() {
return taskState.get() == CANCELLED;
}
};
}
@Override
public Cancellable scheduleWithFixedDelay(Runnable command, TimeValue interval, String executor) {
return super.scheduleWithFixedDelay(command, interval, executor);
}
@Override
public void shutdown() {
throw new UnsupportedOperationException();
}
@Override
public void shutdownNow() {
throw new UnsupportedOperationException();
}
@Override
public boolean awaitTermination(long timeout, TimeUnit unit) {
throw new UnsupportedOperationException();
}
@Override
public ScheduledExecutorService scheduler() {
return new ScheduledExecutorService() {
@Override
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
throw new UnsupportedOperationException();
}
@Override
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
throw new UnsupportedOperationException();
}
@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
throw new UnsupportedOperationException();
}
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
throw new UnsupportedOperationException();
}
@Override
public void shutdown() {
throw new UnsupportedOperationException();
}
@Override
public List<Runnable> shutdownNow() {
throw new UnsupportedOperationException();
}
@Override
public boolean isShutdown() {
throw new UnsupportedOperationException();
}
@Override
public boolean isTerminated() {
throw new UnsupportedOperationException();
}
@Override
public boolean awaitTermination(long timeout, TimeUnit unit) {
throw new UnsupportedOperationException();
}
@Override
public <T> Future<T> submit(Callable<T> task) {
throw new UnsupportedOperationException();
}
@Override
public <T> Future<T> submit(Runnable task, T result) {
throw new UnsupportedOperationException();
}
@Override
public Future<?> submit(Runnable task) {
throw new UnsupportedOperationException();
}
@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) {
throw new UnsupportedOperationException();
}
@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) {
throw new UnsupportedOperationException();
}
@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) {
throw new UnsupportedOperationException();
}
@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) {
throw new UnsupportedOperationException();
}
@Override
public void execute(Runnable command) {
throw new UnsupportedOperationException();
}
};
}
};
}
use of org.opensearch.threadpool.ThreadPoolInfo in project OpenSearch by opensearch-project.
the class NodeInfoStreamingTests method createNodeInfo.
private static NodeInfo createNodeInfo() {
Build build = Build.CURRENT;
DiscoveryNode node = new DiscoveryNode("test_node", buildNewFakeTransportAddress(), emptyMap(), emptySet(), VersionUtils.randomVersion(random()));
Settings settings = randomBoolean() ? null : Settings.builder().put("test", "setting").build();
OsInfo osInfo = null;
if (randomBoolean()) {
int availableProcessors = randomIntBetween(1, 64);
int allocatedProcessors = randomIntBetween(1, availableProcessors);
long refreshInterval = randomBoolean() ? -1 : randomNonNegativeLong();
String name = randomAlphaOfLengthBetween(3, 10);
String arch = randomAlphaOfLengthBetween(3, 10);
String version = randomAlphaOfLengthBetween(3, 10);
osInfo = new OsInfo(refreshInterval, availableProcessors, allocatedProcessors, name, name, arch, version);
}
ProcessInfo process = randomBoolean() ? null : new ProcessInfo(randomInt(), randomBoolean(), randomNonNegativeLong());
JvmInfo jvm = randomBoolean() ? null : JvmInfo.jvmInfo();
ThreadPoolInfo threadPoolInfo = null;
if (randomBoolean()) {
int numThreadPools = randomIntBetween(1, 10);
List<ThreadPool.Info> threadPoolInfos = new ArrayList<>(numThreadPools);
for (int i = 0; i < numThreadPools; i++) {
threadPoolInfos.add(new ThreadPool.Info(randomAlphaOfLengthBetween(3, 10), randomFrom(ThreadPool.ThreadPoolType.values()), randomInt()));
}
threadPoolInfo = new ThreadPoolInfo(threadPoolInfos);
}
Map<String, BoundTransportAddress> profileAddresses = new HashMap<>();
BoundTransportAddress dummyBoundTransportAddress = new BoundTransportAddress(new TransportAddress[] { buildNewFakeTransportAddress() }, buildNewFakeTransportAddress());
profileAddresses.put("test_address", dummyBoundTransportAddress);
TransportInfo transport = randomBoolean() ? null : new TransportInfo(dummyBoundTransportAddress, profileAddresses);
HttpInfo httpInfo = randomBoolean() ? null : new HttpInfo(dummyBoundTransportAddress, randomNonNegativeLong());
PluginsAndModules pluginsAndModules = null;
if (randomBoolean()) {
int numPlugins = randomIntBetween(0, 5);
List<PluginInfo> plugins = new ArrayList<>();
for (int i = 0; i < numPlugins; i++) {
String name = randomAlphaOfLengthBetween(3, 10);
plugins.add(new PluginInfo(name, randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10), VersionUtils.randomVersion(random()), "1.8", randomAlphaOfLengthBetween(3, 10), name, Collections.emptyList(), randomBoolean()));
}
int numModules = randomIntBetween(0, 5);
List<PluginInfo> modules = new ArrayList<>();
for (int i = 0; i < numModules; i++) {
String name = randomAlphaOfLengthBetween(3, 10);
modules.add(new PluginInfo(name, randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10), VersionUtils.randomVersion(random()), "1.8", randomAlphaOfLengthBetween(3, 10), name, Collections.emptyList(), randomBoolean()));
}
pluginsAndModules = new PluginsAndModules(plugins, modules);
}
IngestInfo ingestInfo = null;
if (randomBoolean()) {
int numProcessors = randomIntBetween(0, 5);
List<ProcessorInfo> processors = new ArrayList<>(numProcessors);
for (int i = 0; i < numProcessors; i++) {
processors.add(new ProcessorInfo(randomAlphaOfLengthBetween(3, 10)));
}
ingestInfo = new IngestInfo(processors);
}
AggregationInfo aggregationInfo = null;
if (randomBoolean()) {
AggregationUsageService.Builder builder = new AggregationUsageService.Builder();
int numOfAggs = randomIntBetween(0, 10);
for (int i = 0; i < numOfAggs; i++) {
String aggName = randomAlphaOfLength(10);
try {
if (randomBoolean()) {
builder.registerAggregationUsage(aggName);
} else {
int numOfTypes = randomIntBetween(1, 10);
for (int j = 0; j < numOfTypes; j++) {
builder.registerAggregationUsage(aggName, randomAlphaOfLength(10));
}
}
} catch (IllegalArgumentException ex) {
// Ignore duplicate strings
}
}
aggregationInfo = builder.build().info();
}
ByteSizeValue indexingBuffer = null;
if (randomBoolean()) {
// pick a random long that sometimes exceeds an int:
indexingBuffer = new ByteSizeValue(random().nextLong() & ((1L << 40) - 1));
}
return new NodeInfo(VersionUtils.randomVersion(random()), build, node, settings, osInfo, process, jvm, threadPoolInfo, transport, httpInfo, pluginsAndModules, ingestInfo, aggregationInfo, indexingBuffer);
}
Aggregations