diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-08-04 13:49:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-04 13:49:05 +0200 |
commit | d0689c6277623a495b915b08f0adb4b13627b7db (patch) | |
tree | 937ab9c84acc15a3ba79847e1353f36ce6b74164 /config-model | |
parent | 6498cfa2c279ddbec10a6ddcb53ca3e4d9300fdf (diff) |
Revert "Bjorncs/container thread pool"
Diffstat (limited to 'config-model')
6 files changed, 26 insertions, 153 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 965ae365597..58f03bffb30 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 @@ -5,104 +5,46 @@ import com.yahoo.config.model.producer.AbstractConfigProducer; import com.yahoo.container.bundle.BundleInstantiationSpecification; import com.yahoo.osgi.provider.model.ComponentModel; import com.yahoo.vespa.model.container.ContainerCluster; -import com.yahoo.vespa.model.container.ThreadPoolExecutorComponent; import com.yahoo.vespa.model.container.component.Handler; import java.util.Collection; import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; /** * @author Einar M R Rosenvinge - * @author bjorncs */ public class ContainerDocumentApi { - private static final int FALLBACK_MAX_POOL_SIZE = 0; // Use fallback based on actual logical core count on host - private static final int FALLBACK_CORE_POOL_SIZE = 0; // Use fallback based on actual logical core count on host - - private final ContainerCluster<?> cluster; + private static final String vespaClientBundleSpecification = "vespaclient-container-plugin"; private final Options options; - private final Handler<AbstractConfigProducer<?>> feedHandler; - private final Handler<AbstractConfigProducer<?>> restApiHandler; - public ContainerDocumentApi(ContainerCluster<?> cluster, Options options) { - this.cluster = cluster; + public ContainerDocumentApi(ContainerCluster cluster, Options options) { this.options = options; - this.restApiHandler = addRestApiHandler(cluster, options); - this.feedHandler = addFeedHandler(cluster, options); - } - - public void addNodesDependentThreadpoolConfiguration() { - if (cluster.getContainers().isEmpty()) throw new IllegalStateException("Cluster is empty"); - ThreadPoolExecutorComponent feedHandlerExecutor = newExecutorComponent("feedapi-handler", cluster, options); - feedHandler.inject(feedHandlerExecutor); - feedHandler.addComponent(feedHandlerExecutor); - ThreadPoolExecutorComponent restApiHandlerExecutor = newExecutorComponent("restapi-handler", cluster, options); - restApiHandler.inject(restApiHandlerExecutor); - restApiHandler.addComponent(restApiHandlerExecutor); - } - - private static Handler<AbstractConfigProducer<?>> addFeedHandler(ContainerCluster<?> cluster, Options options) { - String bindingSuffix = ContainerCluster.RESERVED_URI_PREFIX + "/feedapi"; - var handler = newVespaClientHandler( - "com.yahoo.vespa.http.server.FeedHandler", bindingSuffix, options); - cluster.addComponent(handler); - return handler; + setupHandlers(cluster); } - private static Handler<AbstractConfigProducer<?>> addRestApiHandler(ContainerCluster<?> cluster, Options options) { - var handler = newVespaClientHandler( - "com.yahoo.document.restapi.resource.RestApi", "document/v1/*", options); - cluster.addComponent(handler); - return handler; + private void setupHandlers(ContainerCluster cluster) { + cluster.addComponent(newVespaClientHandler("com.yahoo.document.restapi.resource.RestApi", "document/v1/*")); + cluster.addComponent(newVespaClientHandler("com.yahoo.vespa.http.server.FeedHandler", ContainerCluster.RESERVED_URI_PREFIX + "/feedapi")); } - private static ThreadPoolExecutorComponent newExecutorComponent(String name, ContainerCluster<?> cluster, Options options) { - int maxPoolSize = maxPoolSize(cluster); - return new ThreadPoolExecutorComponent.Builder(name) - .maxPoolSize(maxPoolSize) - .corePoolSize(corePoolSize(maxPoolSize, options)) - .queueSize(500) - .build(); - } - - private static Handler<AbstractConfigProducer<?>> newVespaClientHandler( - String componentId, - String bindingSuffix, - Options options) { + private Handler<AbstractConfigProducer<?>> newVespaClientHandler(String componentId, String bindingSuffix) { Handler<AbstractConfigProducer<?>> handler = new Handler<>(new ComponentModel( - BundleInstantiationSpecification.getFromStrings(componentId, null, "vespaclient-container-plugin"), "")); + BundleInstantiationSpecification.getFromStrings(componentId, null, vespaClientBundleSpecification), "")); + for (String rootBinding : options.bindings) { - handler.addServerBindings(rootBinding + bindingSuffix, rootBinding + bindingSuffix + '/'); + handler.addServerBindings(rootBinding + bindingSuffix, + rootBinding + bindingSuffix + '/'); } return handler; } - private static int maxPoolSize(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 FALLBACK_MAX_POOL_SIZE; - return (int)Math.ceil(vcpus.get(0)); - } - - private static int corePoolSize(int maxPoolSize, Options options) { - if (maxPoolSize == FALLBACK_MAX_POOL_SIZE) return FALLBACK_CORE_POOL_SIZE; - return (int) Math.ceil(options.feedCoreThreadPoolSizeFactor * maxPoolSize); - } - public static final class Options { private final Collection<String> bindings; - private final double feedCoreThreadPoolSizeFactor; - public Options(Collection<String> bindings, double feedCoreThreadPoolSizeFactor) { + + public Options(Collection<String> bindings) { this.bindings = Collections.unmodifiableCollection(bindings); - this.feedCoreThreadPoolSizeFactor = feedCoreThreadPoolSizeFactor; } } 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 82b23aa71b5..240157fb7aa 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 @@ -17,7 +17,6 @@ import com.yahoo.container.QrSearchersConfig; import com.yahoo.container.bundle.BundleInstantiationSpecification; import com.yahoo.container.core.ApplicationMetadataConfig; import com.yahoo.container.core.document.ContainerDocumentConfig; -import com.yahoo.container.handler.ThreadPoolProvider; import com.yahoo.container.di.config.PlatformBundlesConfig; import com.yahoo.container.handler.ThreadpoolConfig; import com.yahoo.container.jdisc.JdiscBindingsConfig; @@ -174,7 +173,7 @@ public abstract class ContainerCluster<CONTAINER extends Container> addComponent(new StatisticsComponent()); addSimpleComponent(AccessLog.class); - addSimpleComponent(ThreadPoolProvider.class); + addComponent(new ThreadPoolExecutorComponent.Builder("default-pool").build()); addSimpleComponent(com.yahoo.concurrent.classlock.ClassLocking.class); addSimpleComponent(SecurityFilterInvoker.class); addSimpleComponent("com.yahoo.container.jdisc.metric.MetricConsumerProviderProvider"); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ThreadPoolExecutorComponent.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ThreadPoolExecutorComponent.java index aac73ce7636..2926cb3ee6c 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/ThreadPoolExecutorComponent.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ThreadPoolExecutorComponent.java @@ -2,15 +2,15 @@ package com.yahoo.vespa.model.container; import com.yahoo.container.bundle.BundleInstantiationSpecification; +import com.yahoo.container.handler.ThreadPoolProvider; import com.yahoo.container.handler.ThreadpoolConfig; -import com.yahoo.container.handler.threadpool.ContainerThreadPool; import com.yahoo.osgi.provider.model.ComponentModel; import com.yahoo.vespa.model.container.component.SimpleComponent; import java.time.Duration; /** - * Component definition for a {@link java.util.concurrent.Executor} using {@link ContainerThreadPool}. + * Component definition for a {@link java.util.concurrent.Executor} using {@link ThreadPoolProvider}. * * @author bjorncs */ @@ -26,8 +26,8 @@ public class ThreadPoolExecutorComponent extends SimpleComponent implements Thre private ThreadPoolExecutorComponent(Builder builder) { super(new ComponentModel( BundleInstantiationSpecification.getFromStrings( - "threadpool@" + builder.name, - ContainerThreadPool.class.getName(), + "threadpool-provider@" + builder.name, + ThreadPoolProvider.class.getName(), null))); this.name = builder.name; this.maxPoolSize = builder.maxPoolSize; 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 f24e469ea5c..41e092c7ea5 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 @@ -183,7 +183,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { addProcessing(deployState, spec, cluster); addSearch(deployState, spec, cluster); addDocproc(deployState, spec, cluster); - addDocumentApi(deployState, spec, cluster); // NOTE: Must be done after addSearch + addDocumentApi(spec, cluster); // NOTE: Must be done after addSearch cluster.addDefaultHandlersExceptStatus(); addStatusHandlers(cluster, context.getDeployState().isHosted()); @@ -198,7 +198,6 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { addClientProviders(deployState, spec, cluster); addServerProviders(deployState, spec, cluster); - addHandlerSpecificThreadpools(cluster); addAthensCopperArgos(cluster, context); // Must be added after nodes. } @@ -213,13 +212,6 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { } } - private void addHandlerSpecificThreadpools(ContainerCluster<?> cluster) { - ContainerDocumentApi documentApi = cluster.getDocumentApi(); - if (documentApi != null) { - documentApi.addNodesDependentThreadpoolConfiguration(); - } - } - private void addAthensCopperArgos(ApplicationContainerCluster cluster, ConfigModelContext context) { if ( ! context.getDeployState().isHosted()) return; app.getDeployment().map(DeploymentSpec::fromXml) @@ -408,8 +400,8 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { cluster.addServlet(new ServletBuilder().build(deployState, cluster, servletElem)); } - private void addDocumentApi(DeployState deployState, Element spec, ApplicationContainerCluster cluster) { - ContainerDocumentApi containerDocumentApi = buildDocumentApi(deployState, cluster, spec); + private void addDocumentApi(Element spec, ApplicationContainerCluster cluster) { + ContainerDocumentApi containerDocumentApi = buildDocumentApi(cluster, spec); if (containerDocumentApi == null) return; cluster.setDocumentApi(containerDocumentApi); @@ -838,11 +830,11 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { return result.toArray(new String[result.size()]); } - private ContainerDocumentApi buildDocumentApi(DeployState deployState, ApplicationContainerCluster cluster, Element spec) { + private ContainerDocumentApi buildDocumentApi(ApplicationContainerCluster cluster, Element spec) { Element documentApiElement = XML.getChild(spec, "document-api"); if (documentApiElement == null) return null; - ContainerDocumentApi.Options documentApiOptions = DocumentApiOptionsBuilder.build(deployState, documentApiElement); + ContainerDocumentApi.Options documentApiOptions = DocumentApiOptionsBuilder.build(documentApiElement); return new ContainerDocumentApi(cluster, documentApiOptions); } 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 bbeeffda612..ae74dbdb4a7 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 @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. 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.text.XML; import com.yahoo.vespa.model.clients.ContainerDocumentApi; import org.w3c.dom.Element; @@ -21,8 +20,8 @@ public class DocumentApiOptionsBuilder { private static final Logger log = Logger.getLogger(DocumentApiOptionsBuilder.class.getName()); private static final String[] DEFAULT_BINDINGS = {"http://*/"}; - public static ContainerDocumentApi.Options build(DeployState deployState, Element spec) { - return new ContainerDocumentApi.Options(getBindings(spec), deployState.getProperties().feedCoreThreadPoolSizeFactor()); + public static ContainerDocumentApi.Options build(Element spec) { + return new ContainerDocumentApi.Options(getBindings(spec)); } private static List<String> getBindings(Element spec) { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerDocumentApiBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerDocumentApiBuilderTest.java index 6897d0b7433..ac2e1b88c0b 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerDocumentApiBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerDocumentApiBuilderTest.java @@ -1,19 +1,7 @@ // Copyright 2017 Yahoo Holdings. 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.api.HostProvisioner; import com.yahoo.config.model.builder.xml.test.DomBuilderTest; -import com.yahoo.config.model.provision.Host; -import com.yahoo.config.model.test.MockApplicationPackage; -import com.yahoo.config.model.test.MockRoot; -import com.yahoo.config.provision.Capacity; -import com.yahoo.config.provision.ClusterMembership; -import com.yahoo.config.provision.ClusterSpec; -import com.yahoo.config.provision.HostSpec; -import com.yahoo.config.provision.NodeResources; -import com.yahoo.config.provision.ProvisionLogger; -import com.yahoo.container.handler.ThreadpoolConfig; -import com.yahoo.net.HostName; import com.yahoo.vespa.model.container.ContainerCluster; import com.yahoo.vespa.model.container.component.Handler; import org.junit.Test; @@ -21,27 +9,22 @@ import org.w3c.dom.Element; import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.Optional; -import java.util.Set; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.Matchers.hasItem; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; /** * @author Einar M R Rosenvinge - * @author bjorncs */ public class ContainerDocumentApiBuilderTest extends ContainerModelBuilderTestBase { private Map<String, Handler<?>> getHandlers(String clusterName) { - ContainerCluster<?> cluster = (ContainerCluster<?>) root.getChildren().get(clusterName); + ContainerCluster cluster = (ContainerCluster) root.getChildren().get(clusterName); Map<String, Handler<?>> handlerMap = new HashMap<>(); Collection<Handler<?>> handlers = cluster.getHandlers(); for (Handler<?> handler : handlers) { @@ -97,46 +80,4 @@ public class ContainerDocumentApiBuilderTest extends ContainerModelBuilderTestBa assertThat(handlerMap.get("com.yahoo.vespa.http.server.FeedHandler").getServerBindings().contains("http://*/" + ContainerCluster.RESERVED_URI_PREFIX + "/feedapi/"), is(true)); assertThat(handlerMap.get("com.yahoo.vespa.http.server.FeedHandler").getServerBindings().size(), equalTo(2)); } - - @Test - public void feeding_api_have_separate_threadpools() { - Element elem = DomBuilderTest.parse( - "<container id='cluster1' version='1.0'>", - " <document-api />", - nodesXml, - "</container>"); - root = new MockRoot("root", new MockApplicationPackage.Builder().build(), new HostProvisionerWithCustomRealResource()); - createModel(root, elem); - Map<String, Handler<?>> handlers = getHandlers("cluster1"); - Handler<?> feedApiHandler = handlers.get("com.yahoo.vespa.http.server.FeedHandler"); - Set<String> injectedComponentIds = feedApiHandler.getInjectedComponentIds(); - assertThat(injectedComponentIds, hasItem("threadpool@feedapi-handler")); - - ThreadpoolConfig config = root.getConfig(ThreadpoolConfig.class, "cluster1/component/com.yahoo.vespa.http.server.FeedHandler/threadpool@feedapi-handler"); - assertEquals(4, config.maxthreads()); - assertEquals(4, config.corePoolSize()); - } - - private static class HostProvisionerWithCustomRealResource implements HostProvisioner { - - @Override - public HostSpec allocateHost(String alias) { - Host host = new Host(HostName.getLocalhost()); - ClusterMembership membership = ClusterMembership.from( - ClusterSpec - .specification( - ClusterSpec.Type.container, - ClusterSpec.Id.from("id")) - .vespaVersion("") - .group(ClusterSpec.Group.from(0)) - .build(), - 0); - return new HostSpec( - host.hostname(), new NodeResources(4, 0, 0, 0), NodeResources.unspecified(), NodeResources.unspecified(), - membership, Optional.empty(), Optional.empty(), Optional.empty()); - } - - @Override public List<HostSpec> prepare(ClusterSpec cluster, Capacity capacity, ProvisionLogger logger) { return List.of(); } - } - } |