gortiz commented on code in PR #15143:
URL: https://github.com/apache/pinot/pull/15143#discussion_r1975452181


##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/plan/server/ServerPlanRequestUtils.java:
##########
@@ -106,7 +106,7 @@ public static OpChain 
compileLeafStage(OpChainExecutionContext executionContext,
       BiConsumer<PlanNode, MultiStageOperator> relationConsumer,
       boolean explain) {
     long queryArrivalTimeMs = System.currentTimeMillis();
-    MdcExecutor mdcExecutor = new MdcExecutor(executorService) {
+    ExecutorService decoratedExecutor = new MdcExecutor(executorService) {

Review Comment:
   Is there any reason to apply this change? Maybe you needed that before but 
now that you are creating the executor in another place it is not needed?



##########
pinot-spi/src/main/java/org/apache/pinot/spi/executor/ExecutorServiceUtils.java:
##########
@@ -132,4 +133,14 @@ public static void close(ExecutorService executorService, 
long terminationMillis
       throw new RuntimeException(e);
     }
   }
+
+  /**
+   * 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) {
+    return 
config.getProperty(CommonConstants.Helix.CONFIG_OF_MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_THREADS,
 0)
+        * 
CommonConstants.Helix.MULTI_STAGE_ENGINE_MAX_SERVER_QUERY_THREADS_HARDLIMIT_FACTOR;
+  }

Review Comment:
   It looks like this static method is bound to the hard limit executor. I 
don't think ExecutorServiceUtils is the correct place to have it. It would be 
more natural to be declared in the HardLimitExecutor class



##########
pinot-common/src/main/java/org/apache/pinot/common/utils/HardLimitExecutorServicePlugin.java:
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.common.utils;
+
+import com.google.auto.service.AutoService;
+import java.util.concurrent.ExecutorService;
+import org.apache.pinot.spi.executor.ExecutorServicePlugin;
+import org.apache.pinot.spi.executor.ExecutorServiceProvider;
+import org.apache.pinot.spi.executor.ExecutorServiceUtils;
+import org.apache.pinot.spi.executor.HardLimitExecutor;
+import org.apache.pinot.spi.utils.CommonConstants;
+
+
+/**
+ * This is the plugin for the cached executor service with a hard limit for 
the amount of created threads.
+ *
+ * The provider included in this plugin creates cached thread pools, which are 
the recommended executor service for
+ * cases where the tasks are short-lived and not CPU bound.
+ *
+ * If that is not the case, this executor may create a large number of threads 
that will be competing for CPU resources,
+ * which may lead to performance degradation and even system instability.
+ * In that case {@link FixedExecutorServicePlugin} could be used, but it may 
need changes to the code to avoid
+ * deadlocks. Deployments using Java 21 or above could consider using a 
virtual thread executor service plugin.
+ *
+ * @see org.apache.pinot.spi.executor.ExecutorServiceUtils
+ */
+@AutoService(ExecutorServicePlugin.class)
+public class HardLimitExecutorServicePlugin implements ExecutorServicePlugin {
+  @Override
+  public String id() {
+    return "hardlimit";
+  }
+
+  @Override
+  public ExecutorServiceProvider provider() {
+    return (conf, confPrefix, baseName) -> {
+      int limit = ExecutorServiceUtils.getMultiStageExecutorHardLimit(conf);
+      ExecutorService executorService = ExecutorServiceUtils.create(
+          conf, CommonConstants.Server.MULTISTAGE_EXECUTOR_CONFIG_PREFIX, 
baseName,
+          CommonConstants.Server.DEFAULT_MULTISTAGE_EXECUTOR_TYPE);
+      if (limit > 0) {
+        executorService = new HardLimitExecutor(limit, executorService);
+      }
+      return executorService;
+    };
+  }

Review Comment:
   I'm not sure if we need this class, but if we do, this executor should not 
be configured with an MSE property. These plugins provide a standard way to 
configure each type of executor service. These providers can be used more than 
once to create different executors, so we probably need to give them different 
configurations.
   
     If you read FixedExecutorServicePlugin you can see that it reads a 
different part of the config depending on the `configPrefix`. Could you do the 
same thing? As a corollary, 
`ExecutorServiceUtils.getMultiStageExecutorHardLimit` won't be needed given 
that different allocations will use different properties.



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/QueryRunner.java:
##########
@@ -174,9 +174,14 @@ public void init(PinotConfiguration config, 
InstanceDataManager instanceDataMana
     String joinOverflowModeStr = 
config.getProperty(CommonConstants.MultiStageQueryRunner.KEY_OF_JOIN_OVERFLOW_MODE);
     _joinOverflowMode = joinOverflowModeStr != null ? 
JoinOverFlowMode.valueOf(joinOverflowModeStr) : null;
 
-    _executorService =
-        ExecutorServiceUtils.create(config, 
Server.MULTISTAGE_EXECUTOR_CONFIG_PREFIX, "query-runner-on-" + port,
-            Server.DEFAULT_MULTISTAGE_EXECUTOR_TYPE);
+    int hardLimit = 
ExecutorServiceUtils.getMultiStageExecutorHardLimit(config);
+    String executorType = Server.DEFAULT_MULTISTAGE_EXECUTOR_TYPE;
+    if (hardLimit > 0) {
+      executorType = "hardlimit";
+    }
+    _executorService = ExecutorServiceUtils.create(config, 
Server.MULTISTAGE_EXECUTOR_CONFIG_PREFIX,
+          "query-runner-on-" + port, executorType);

Review Comment:
   I don't think you need to use the ExecutorServiceUtils.create here. You 
always want to use a specific executor service, so use it directly.



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/QueryRunner.java:
##########
@@ -177,6 +178,12 @@ public void init(PinotConfiguration config, 
InstanceDataManager instanceDataMana
     _executorService =
         ExecutorServiceUtils.create(config, 
Server.MULTISTAGE_EXECUTOR_CONFIG_PREFIX, "query-runner-on-" + port,
             Server.DEFAULT_MULTISTAGE_EXECUTOR_TYPE);
+
+    int maxThreads = 
config.getProperty(Server.CONFIG_OF_MSE_THREADS_HARD_LIMIT, 
Server.DEFAULT_MSE_THREADS_HARD_LIMIT);
+    if (maxThreads > 0) {
+      _executorService = new MaxTasksExecutor(maxThreads, _executorService);
+    }

Review Comment:
   I don't think we should use the provider api here



##########
pinot-core/src/main/java/org/apache/pinot/core/query/executor/ServerQueryExecutorV1Impl.java:
##########
@@ -142,25 +140,8 @@ public synchronized void shutDown() {
   @Override
   public InstanceResponseBlock execute(ServerQueryRequest queryRequest, 
ExecutorService executorService,
       @Nullable ResultsBlockStreamer streamer) {
-    MdcExecutor mdcExecutor = new MdcExecutor(executorService) {
-      @Override
-      protected boolean alreadyRegistered() {
-        return LoggerConstants.QUERY_ID_KEY.isRegistered();
-      }
-
-      @Override
-      protected void registerInMdc() {
-        queryRequest.registerInMdc();
-      }
-
-      @Override
-      protected void unregisterFromMdc() {
-        queryRequest.unregisterFromMdc();
-      }
-    };

Review Comment:
   I don't understand this change here. Who is modifying the MDC now?



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to