aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@yahooinc.com>2023-09-28 16:09:29 +0200
committerBjørn Christian Seime <bjorncs@yahooinc.com>2023-09-28 16:11:22 +0200
commitebdbbc59f35b69f3502cfcaa56dd3dd5349bc28c (patch)
tree2e5faa47a113e58632ecd05c9ca5c027aa49c7e3 /config-model/src/main/java/com
parent168f8847334518c8efe73478805a580b5f5e23a6 (diff)
Introduce new threadpool syntax
Diffstat (limited to 'config-model/src/main/java/com')
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/clients/ContainerDocumentApi.java19
-rwxr-xr-xconfig-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java3
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/ContainerThreadpool.java82
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/component/Handler.java6
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java7
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/xml/DocumentApiOptionsBuilder.java9
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/xml/SearchHandler.java13
7 files changed, 78 insertions, 61 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/clients/ContainerDocumentApi.java b/config-model/src/main/java/com/yahoo/vespa/model/clients/ContainerDocumentApi.java
index 0795fdf41d6..762c670039c 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/clients/ContainerDocumentApi.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/clients/ContainerDocumentApi.java
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.clients;
+import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.container.handler.threadpool.ContainerThreadpoolConfig;
import com.yahoo.osgi.provider.model.ComponentModel;
import com.yahoo.vespa.model.container.ContainerCluster;
@@ -10,6 +11,7 @@ import com.yahoo.vespa.model.container.component.BindingPattern;
import com.yahoo.vespa.model.container.component.Handler;
import com.yahoo.vespa.model.container.component.SystemBindingPattern;
import com.yahoo.vespa.model.container.component.UserBindingPattern;
+import org.w3c.dom.Element;
import java.nio.file.Path;
import java.util.Collection;
@@ -29,10 +31,11 @@ public class ContainerDocumentApi {
private final boolean ignoreUndefinedFields;
- public ContainerDocumentApi(ContainerCluster<?> cluster, HandlerOptions handlerOptions, boolean ignoreUndefinedFields, Set<Integer> portOverride) {
+ public ContainerDocumentApi(DeployState ds, ContainerCluster<?> cluster, HandlerOptions handlerOptions,
+ boolean ignoreUndefinedFields, Set<Integer> portOverride) {
this.ignoreUndefinedFields = ignoreUndefinedFields;
addRestApiHandler(cluster, handlerOptions, portOverride);
- addFeedHandler(cluster, handlerOptions, portOverride);
+ addFeedHandler(ds, cluster, handlerOptions, portOverride);
addVespaClientContainerBundle(cluster);
}
@@ -40,9 +43,9 @@ public class ContainerDocumentApi {
c.addPlatformBundle(VESPACLIENT_CONTAINER_BUNDLE);
}
- private static void addFeedHandler(ContainerCluster<?> cluster, HandlerOptions handlerOptions, Set<Integer> portOverride) {
+ private static void addFeedHandler(DeployState ds, ContainerCluster<?> cluster, HandlerOptions handlerOptions, Set<Integer> portOverride) {
String bindingSuffix = ContainerCluster.RESERVED_URI_PREFIX + "/feedapi";
- var executor = new Threadpool("feedapi-handler", handlerOptions.feedApiThreadpoolOptions);
+ var executor = new Threadpool(ds, "feedapi-handler", handlerOptions.feedApiThreadpoolOptions);
var handler = newVespaClientHandler("com.yahoo.vespa.http.server.FeedHandler",
bindingSuffix, handlerOptions, executor, portOverride);
cluster.addComponent(handler);
@@ -104,9 +107,9 @@ public class ContainerDocumentApi {
public static final class HandlerOptions {
private final Collection<String> bindings;
- private final ContainerThreadpool.UserOptions feedApiThreadpoolOptions;
+ private final Element feedApiThreadpoolOptions;
- public HandlerOptions(Collection<String> bindings, ContainerThreadpool.UserOptions feedApiThreadpoolOptions) {
+ public HandlerOptions(Collection<String> bindings, Element feedApiThreadpoolOptions) {
this.bindings = Collections.unmodifiableCollection(bindings);
this.feedApiThreadpoolOptions = feedApiThreadpoolOptions;
}
@@ -114,9 +117,7 @@ public class ContainerDocumentApi {
private static class Threadpool extends ContainerThreadpool {
- Threadpool(String name, ContainerThreadpool.UserOptions threadpoolOptions) {
- super(name, threadpoolOptions);
- }
+ Threadpool(DeployState ds, String name, Element xml) { super(ds, name, xml); }
@Override
protected void setDefaultConfigValues(ContainerThreadpoolConfig.Builder builder) {
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java
index fa13e7ec9d6..3d4ec51c8d2 100755
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java
@@ -144,7 +144,7 @@ public abstract class ContainerCluster<CONTAINER extends Container>
private ContainerDocproc containerDocproc;
private ContainerDocumentApi containerDocumentApi;
private SecretStore secretStore;
- private final ContainerThreadpool defaultHandlerThreadpool = new Handler.DefaultHandlerThreadpool();
+ private final ContainerThreadpool defaultHandlerThreadpool;
private boolean rpcServerEnabled = true;
private boolean httpServerEnabled = true;
@@ -187,6 +187,7 @@ public abstract class ContainerCluster<CONTAINER extends Container>
addCommonVespaBundles();
addSimpleComponent(VoidRequestLog.class);
addComponent(new DefaultThreadpoolProvider(this, defaultPoolNumThreads));
+ defaultHandlerThreadpool = new Handler.DefaultHandlerThreadpool(deployState, null);
addComponent(defaultHandlerThreadpool);
addSimpleComponent(com.yahoo.concurrent.classlock.ClassLocking.class);
addSimpleComponent("com.yahoo.container.jdisc.metric.MetricConsumerProviderProvider");
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
index fb4e62f5cd1..7e4bf41a8b0 100644
--- 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
@@ -1,16 +1,17 @@
// Copyright Yahoo. 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.config.model.builder.xml.XmlHelper;
+import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.container.handler.threadpool.ContainerThreadPool;
import com.yahoo.container.handler.threadpool.ContainerThreadpoolConfig;
import com.yahoo.container.handler.threadpool.ContainerThreadpoolImpl;
import com.yahoo.osgi.provider.model.ComponentModel;
-import com.yahoo.text.XML;
import com.yahoo.vespa.model.container.component.SimpleComponent;
import org.w3c.dom.Element;
-import java.util.Optional;
+import java.util.logging.Level;
/**
* Component definition for a {@link java.util.concurrent.Executor} using {@link ContainerThreadPool}.
@@ -20,18 +21,50 @@ import java.util.Optional;
public abstract class ContainerThreadpool extends SimpleComponent implements ContainerThreadpoolConfig.Producer {
private final String name;
- private final UserOptions userOptions;
+ private final UserOptions options;
- public ContainerThreadpool(String name, UserOptions userOptions) {
+ record UserOptions(Double max, Double min, Double queue){}
+
+ protected ContainerThreadpool(DeployState ds, String name, Element parent) {
super(new ComponentModel(
BundleInstantiationSpecification.fromStrings(
"threadpool@" + name,
ContainerThreadpoolImpl.class.getName(),
null)));
this.name = name;
- this.userOptions = userOptions;
+ var threadpoolElem = XmlHelper.getOptionalChild(parent, "threadpool").orElse(null);
+ if (threadpoolElem == null) options = new UserOptions(null, null, null);
+ else {
+ // TODO Vespa 9 Remove min-threads, max-threads and queue-size
+ Double max = null;
+ Double min = null;
+ Double queue = null;
+ var minElem = XmlHelper.getOptionalChild(threadpoolElem, "min-threads").orElse(null);
+ if (minElem != null) ds.getDeployLogger().logApplicationPackage(Level.WARNING, "For <threadpool>: <min-threads> is deprecated, use <threads> instead");
+ var maxElem = XmlHelper.getOptionalChild(threadpoolElem, "max-threads").orElse(null);
+ if (maxElem != null) ds.getDeployLogger().logApplicationPackage(Level.WARNING, "For <threadpool>: <max-threads> is deprecated, use <threads> with 'boost' instead");
+ var queueElem = XmlHelper.getOptionalChild(threadpoolElem, "queue").orElse(null);
+ var queueSizeElem = XmlHelper.getOptionalChild(threadpoolElem, "queue-size").orElse(null);
+ if (queueSizeElem != null) ds.getDeployLogger().logApplicationPackage(Level.WARNING, "For <threadpool>: <queue-size> is deprecated, use <queue> instead");
+ var threadsElem = XmlHelper.getOptionalChild(threadpoolElem, "threads").orElse(null);
+ if (threadsElem != null) {
+ min = parseMultiplier(threadsElem.getTextContent());
+ if (threadsElem.hasAttribute("boost")) max = parseMultiplier(threadsElem.getAttribute("boost"));
+ } else if (minElem != null) {
+ min = parseFixed(minElem.getTextContent());
+ }
+ if (max == null && maxElem != null) {
+ max = parseFixed(maxElem.getTextContent());
+ }
+ if (queueElem != null) queue = parseMultiplier(queueElem.getTextContent());
+ else if (queueSizeElem != null) queue = parseFixed(queueSizeElem.getTextContent());
+ options = new UserOptions(max, min, queue);
+ }
}
+ private static Double parseMultiplier(String text) { return -parseFixed(text); }
+ private static Double parseFixed(String text) { return Double.parseDouble(text); }
+
// Must be implemented by subclasses to set values that may be overridden by user options.
protected abstract void setDefaultConfigValues(ContainerThreadpoolConfig.Builder builder);
@@ -40,35 +73,20 @@ public abstract class ContainerThreadpool extends SimpleComponent implements Con
setDefaultConfigValues(builder);
builder.name(this.name);
- if (userOptions != null) {
- builder.maxThreads(userOptions.maxThreads);
- builder.minThreads(userOptions.minThreads);
- builder.queueSize(userOptions.queueSize);
+ if (options.max() != null) {
+ int max = (int) Math.round(options.max());
+ if (options.max() != 0 && max == 0) max = options.max() > 0 ? 1 : -1;
+ builder.maxThreads(max);
}
- }
-
- public static class UserOptions {
- private final int maxThreads;
- private final int minThreads;
- private final int queueSize;
-
- private UserOptions(int maxThreads, int minThreads, int queueSize) {
- this.maxThreads = maxThreads;
- this.minThreads = minThreads;
- this.queueSize = queueSize;
- }
-
- public static Optional<UserOptions> fromXml(Element xml) {
- Element element = XML.getChild(xml, "threadpool");
- if (element == null) return Optional.empty();
- return Optional.of(new UserOptions(
- intOption(element, "max-threads"),
- intOption(element, "min-threads"),
- intOption(element, "queue-size")));
+ if (options.min() != null) {
+ int min = (int) Math.round(options.min());
+ if (options.min() != 0 && min == 0) min = options.min() > 0 ? 1 : -1;
+ builder.minThreads(min);
}
-
- private static int intOption(Element element, String name) {
- return Integer.parseInt(XML.getChild(element, name).getTextContent());
+ if (options.queue() != null) {
+ int queue = (int) Math.round(options.queue());
+ if (options.queue() != 0 && queue == 0) queue = options.queue() > 0 ? 1 : -1;
+ builder.queueSize(queue);
}
}
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/component/Handler.java b/config-model/src/main/java/com/yahoo/vespa/model/container/component/Handler.java
index 31031aa5bf2..969db6553e6 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/component/Handler.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/component/Handler.java
@@ -1,9 +1,11 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.component;
+import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.container.handler.threadpool.ContainerThreadpoolConfig;
import com.yahoo.osgi.provider.model.ComponentModel;
import com.yahoo.vespa.model.container.ContainerThreadpool;
+import org.w3c.dom.Element;
import java.util.ArrayList;
import java.util.Arrays;
@@ -76,8 +78,8 @@ public class Handler extends Component<Component<?, ?>, ComponentModel> {
*/
public static class DefaultHandlerThreadpool extends ContainerThreadpool {
- public DefaultHandlerThreadpool() {
- super("default-handler-common", null);
+ public DefaultHandlerThreadpool(DeployState ds, Element options) {
+ super(ds, "default-handler-common", options);
}
@Override
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java
index 474f3f5ce6d..1874b5fa19a 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java
@@ -70,7 +70,6 @@ import com.yahoo.vespa.model.container.Container;
import com.yahoo.vespa.model.container.ContainerCluster;
import com.yahoo.vespa.model.container.ContainerModel;
import com.yahoo.vespa.model.container.ContainerModelEvaluation;
-import com.yahoo.vespa.model.container.ContainerThreadpool;
import com.yahoo.vespa.model.container.DataplaneProxy;
import com.yahoo.vespa.model.container.IdentityProvider;
import com.yahoo.vespa.model.container.PlatformBundles;
@@ -1143,9 +1142,9 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> {
if (isHostedTenantApplication(context)) {
bindingPatterns = SearchHandler.bindingPattern(getDataplanePorts(deployState));
}
- SearchHandler searchHandler = new SearchHandler(cluster,
+ SearchHandler searchHandler = new SearchHandler(deployState, cluster,
serverBindings(deployState, context, searchElement, bindingPatterns),
- ContainerThreadpool.UserOptions.fromXml(searchElement).orElse(null));
+ searchElement);
cluster.addComponent(searchHandler);
// Add as child to SearchHandler to get the correct chains config.
@@ -1186,7 +1185,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> {
ContainerDocumentApi.HandlerOptions documentApiOptions = DocumentApiOptionsBuilder.build(documentApiElement);
Element ignoreUndefinedFields = XML.getChild(documentApiElement, "ignore-undefined-fields");
- return new ContainerDocumentApi(cluster, documentApiOptions,
+ return new ContainerDocumentApi(deployState, cluster, documentApiOptions,
"true".equals(XML.getValue(ignoreUndefinedFields)), portBindingOverride(deployState, context));
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/DocumentApiOptionsBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/DocumentApiOptionsBuilder.java
index bb1d0af1db9..cdbe62720b9 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/DocumentApiOptionsBuilder.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/DocumentApiOptionsBuilder.java
@@ -3,7 +3,6 @@ package com.yahoo.vespa.model.container.xml;
import com.yahoo.text.XML;
import com.yahoo.vespa.model.clients.ContainerDocumentApi;
-import com.yahoo.vespa.model.container.ContainerThreadpool;
import org.w3c.dom.Element;
import java.util.ArrayList;
@@ -19,13 +18,7 @@ public class DocumentApiOptionsBuilder {
private static final Logger log = Logger.getLogger(DocumentApiOptionsBuilder.class.getName());
public static ContainerDocumentApi.HandlerOptions build(Element spec) {
- return new ContainerDocumentApi.HandlerOptions(getBindings(spec), threadpoolOptions(spec, "http-client-api"));
- }
-
- private static ContainerThreadpool.UserOptions threadpoolOptions(Element spec, String elementName) {
- Element element = XML.getChild(spec, elementName);
- if (element == null) return null;
- return ContainerThreadpool.UserOptions.fromXml(element).orElse(null);
+ return new ContainerDocumentApi.HandlerOptions(getBindings(spec), XML.getChild(spec, "http-client-api"));
}
private static List<String> getBindings(Element spec) {
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/SearchHandler.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/SearchHandler.java
index 6cfef153fee..3cd296c1469 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/SearchHandler.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/SearchHandler.java
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.xml;
+import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.container.handler.threadpool.ContainerThreadpoolConfig;
import com.yahoo.vespa.model.container.ApplicationContainerCluster;
@@ -9,6 +10,7 @@ import com.yahoo.vespa.model.container.component.BindingPattern;
import com.yahoo.vespa.model.container.component.SystemBindingPattern;
import com.yahoo.vespa.model.container.component.chain.ProcessingHandler;
import com.yahoo.vespa.model.container.search.searchchain.SearchChains;
+import org.w3c.dom.Element;
import java.util.Collection;
import java.util.List;
@@ -30,10 +32,11 @@ class SearchHandler extends ProcessingHandler<SearchChains> {
static final BundleInstantiationSpecification HANDLER_SPEC = fromSearchAndDocproc(HANDLER_CLASSNAME);
static final BindingPattern DEFAULT_BINDING = SystemBindingPattern.fromHttpPath("/search/*");
- SearchHandler(ApplicationContainerCluster cluster,
+ SearchHandler(DeployState ds,
+ ApplicationContainerCluster cluster,
List<BindingPattern> bindings,
- ContainerThreadpool.UserOptions threadpoolOptions) {
- super(cluster.getSearchChains(), HANDLER_SPEC, new Threadpool(threadpoolOptions));
+ Element threadpoolOptions) {
+ super(cluster.getSearchChains(), HANDLER_SPEC, new Threadpool(ds, threadpoolOptions));
bindings.forEach(this::addServerBindings);
}
@@ -46,8 +49,8 @@ class SearchHandler extends ProcessingHandler<SearchChains> {
private static class Threadpool extends ContainerThreadpool {
- Threadpool(UserOptions options) {
- super("search-handler", options);
+ Threadpool(DeployState ds, Element options) {
+ super(ds, "search-handler", options);
}
@Override