Jackie-Jiang commented on code in PR #15143:
URL: https://github.com/apache/pinot/pull/15143#discussion_r1975980844
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java:
##########
@@ -248,6 +248,9 @@ public static class Instance {
public static final String
CONFIG_OF_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_THREADS =
"pinot.beta.multistage.engine.max.server.query.threads";
public static final String
DEFAULT_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_THREADS = "-1";
+ public static final String
CONFIG_OF_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_HARDLIMIT_FACTOR =
+
"pinot.beta.multistage.engine.max.server.query.threads.hardlimit.factor";
+ public static final String
DEFAULT_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_HARDLIMIT_FACTOR = "4";
Review Comment:
I feel a fixed number would be easier to understand.
With current behavior, if user somehow put `-1` as the factor because they
want to disable this, it will end up enabling the hard limit with 1 thread
##########
pinot-core/src/main/java/org/apache/pinot/core/query/executor/ServerQueryExecutorV1Impl.java:
##########
@@ -125,8 +125,8 @@ public synchronized void init(PinotConfiguration config,
InstanceDataManager ins
_planMaker.init(config);
_defaultTimeoutMs = config.getProperty(Server.TIMEOUT,
Server.DEFAULT_QUERY_EXECUTOR_TIMEOUT_MS);
_enablePrefetch =
Boolean.parseBoolean(config.getProperty(ENABLE_PREFETCH));
- LOGGER.info("Initialized query executor with defaultTimeoutMs: {},
enablePrefetch: {}", _defaultTimeoutMs,
- _enablePrefetch);
+ LOGGER.info("Initialized query executor with defaultTimeoutMs: {},
enablePrefetch: {}",
+ _defaultTimeoutMs, _enablePrefetch);
Review Comment:
(format) Per the changes in this file, I believe your IDE is not properly
setup with [Pinot
Style](https://docs.pinot.apache.org/developers/developers-and-contributors/code-setup?q=null#set-up-ide)
##########
pinot-spi/src/main/java/org/apache/pinot/spi/executor/HardLimitExecutor.java:
##########
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.spi.executor;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.utils.CommonConstants;
+
+
+/**
+ * An Executor that allows a maximum of tasks running at the same time,
rejecting immediately any excess.
+ */
+public class HardLimitExecutor extends DecoratorExecutorService {
+
+ private final AtomicInteger _running;
+ private final int _max;
+
+ public HardLimitExecutor(int max, ExecutorService executorService) {
+ super(executorService);
+ _running = new AtomicInteger(0);
+ _max = max;
+ }
+
+ /**
+ * Returns the hard limit of the number of threads that can be used by the
multi-stage executor.
+ * @param config Pinot configuration
+ * @return hard limit of the number of threads that can be used by the
multi-stage executor (no hard limit if <= 0)
+ */
+ public static int getMultiStageExecutorHardLimit(PinotConfiguration config) {
+ try {
+ return Integer.parseInt(config.getProperty(
+
CommonConstants.Helix.CONFIG_OF_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_THREADS,
+
CommonConstants.Helix.DEFAULT_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_THREADS
+ )) * Integer.parseInt(config.getProperty(
+
CommonConstants.Helix.CONFIG_OF_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_HARDLIMIT_FACTOR,
+
CommonConstants.Helix.DEFAULT_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_HARDLIMIT_FACTOR
+ ));
+ } catch (NumberFormatException e) {
+ return
Integer.parseInt(CommonConstants.Helix.DEFAULT_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_THREADS);
+ }
+ }
+
+ protected void checkTaskAllowed() {
+ if (_running.get() >= _max) {
+ throw new IllegalStateException("Tasks limit exceeded.");
+ }
+ }
+
+ @Override
+ protected <T> Callable<T> decorate(Callable<T> task) {
+ checkTaskAllowed();
+ return () -> {
+ checkTaskAllowed();
+ try {
+ _running.getAndIncrement();
Review Comment:
(minor) Usually we put this outside of `try`
##########
pinot-spi/src/main/java/org/apache/pinot/spi/executor/HardLimitExecutor.java:
##########
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.spi.executor;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.utils.CommonConstants;
+
+
+/**
+ * An Executor that allows a maximum of tasks running at the same time,
rejecting immediately any excess.
+ */
+public class HardLimitExecutor extends DecoratorExecutorService {
+
+ private final AtomicInteger _running;
+ private final int _max;
+
+ public HardLimitExecutor(int max, ExecutorService executorService) {
+ super(executorService);
+ _running = new AtomicInteger(0);
+ _max = max;
+ }
+
+ /**
+ * Returns the hard limit of the number of threads that can be used by the
multi-stage executor.
+ * @param config Pinot configuration
+ * @return hard limit of the number of threads that can be used by the
multi-stage executor (no hard limit if <= 0)
+ */
+ public static int getMultiStageExecutorHardLimit(PinotConfiguration config) {
+ try {
+ return Integer.parseInt(config.getProperty(
+
CommonConstants.Helix.CONFIG_OF_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_THREADS,
+
CommonConstants.Helix.DEFAULT_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_THREADS
+ )) * Integer.parseInt(config.getProperty(
+
CommonConstants.Helix.CONFIG_OF_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_HARDLIMIT_FACTOR,
+
CommonConstants.Helix.DEFAULT_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_HARDLIMIT_FACTOR
+ ));
+ } catch (NumberFormatException e) {
+ return
Integer.parseInt(CommonConstants.Helix.DEFAULT_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_THREADS);
+ }
+ }
+
+ protected void checkTaskAllowed() {
+ if (_running.get() >= _max) {
+ throw new IllegalStateException("Tasks limit exceeded.");
+ }
+ }
+
+ @Override
+ protected <T> Callable<T> decorate(Callable<T> task) {
+ checkTaskAllowed();
Review Comment:
Do we need to check twice?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]