aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerThreadpool.java
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2020-09-16 17:52:04 +0200
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2020-09-16 17:52:04 +0200
commit951e558ed5cbfa4ae98fc0962f8ebe5ea1fddeb0 (patch)
tree1fe2df4ac0697c013b243a8c267a2a81522ba7ba /config-model/src/main/java/com/yahoo/vespa/model/container/ContainerThreadpool.java
parentbc28d842042912b7161f5cc0d4bce44ef5e157de (diff)
Rename class to 'ContainerThreadpool'
Diffstat (limited to 'config-model/src/main/java/com/yahoo/vespa/model/container/ContainerThreadpool.java')
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/ContainerThreadpool.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerThreadpool.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerThreadpool.java
new file mode 100644
index 00000000000..6e4514c31b4
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerThreadpool.java
@@ -0,0 +1,43 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.model.container;
+
+import com.yahoo.container.bundle.BundleInstantiationSpecification;
+import com.yahoo.container.handler.threadpool.ContainerThreadPool;
+import com.yahoo.container.handler.threadpool.ContainerThreadpoolConfig;
+import com.yahoo.osgi.provider.model.ComponentModel;
+import com.yahoo.vespa.model.container.component.SimpleComponent;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Component definition for a {@link java.util.concurrent.Executor} using {@link ContainerThreadPool}.
+ *
+ * @author bjorncs
+ */
+public class ContainerThreadpool extends SimpleComponent implements ContainerThreadpoolConfig.Producer {
+
+ private final String name;
+
+ public ContainerThreadpool(String name) {
+ super(new ComponentModel(
+ BundleInstantiationSpecification.getFromStrings(
+ "threadpool@" + name,
+ ContainerThreadPool.class.getName(),
+ null)));
+ this.name = name;
+ }
+
+ @Override public void getConfig(ContainerThreadpoolConfig.Builder builder) { builder.name(this.name); }
+
+ protected static double vcpu(ContainerCluster<?> cluster) {
+ List<Double> vcpus = cluster.getContainers().stream()
+ .filter(c -> c.getHostResource() != null && c.getHostResource().realResources() != null)
+ .map(c -> c.getHostResource().realResources().vcpu())
+ .distinct()
+ .collect(Collectors.toList());
+ // We can only use host resource for calculation if all container nodes in the cluster are homogeneous (in terms of vcpu)
+ if (vcpus.size() != 1 || vcpus.get(0) == 0) return 0;
+ return vcpus.get(0);
+ }
+}