yashmayya commented on code in PR #14574:
URL: https://github.com/apache/pinot/pull/14574#discussion_r1886880302
##########
pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/MultiStageBrokerRequestHandler.java:
##########
@@ -224,67 +227,89 @@ protected BrokerResponse handleRequest(long requestId,
String query, SqlNodeAndO
return new
BrokerResponseNative(QueryException.getException(QueryException.QUOTA_EXCEEDED_ERROR,
errorMessage));
}
- Tracing.ThreadAccountantOps.setupRunner(String.valueOf(requestId),
ThreadExecutionContext.TaskType.MSE);
-
- long executionStartTimeNs = System.nanoTime();
- QueryDispatcher.QueryResult queryResults;
+ Timer queryTimer = new Timer(queryTimeoutMs);
try {
- queryResults =
- _queryDispatcher.submitAndReduce(requestContext,
dispatchableSubPlan, queryTimeoutMs, queryOptions);
- } catch (TimeoutException e) {
- for (String table : tableNames) {
- _brokerMetrics.addMeteredTableValue(table,
BrokerMeter.BROKER_RESPONSES_WITH_TIMEOUTS, 1);
+ // It's fine to block in this thread because we use a separate thread
pool from the main Jersey server to process
+ // these requests.
+ if (!_querySemaphore.tryAcquire(queryTimeoutMs, TimeUnit.MILLISECONDS)) {
+ LOGGER.warn("Timed out waiting to execute request {}: {}", requestId,
query);
+
requestContext.setErrorCode(QueryException.EXECUTION_TIMEOUT_ERROR_CODE);
+ return new
BrokerResponseNative(QueryException.EXECUTION_TIMEOUT_ERROR);
}
- LOGGER.warn("Timed out executing request {}: {}", requestId, query);
+ } catch (InterruptedException e) {
+ LOGGER.warn("Interrupt received while waiting to execute request {}:
{}", requestId, query);
requestContext.setErrorCode(QueryException.EXECUTION_TIMEOUT_ERROR_CODE);
return new BrokerResponseNative(QueryException.EXECUTION_TIMEOUT_ERROR);
Review Comment:
We could either add a debug / info log showing this queueing / throttling
mechanism based wait time per query or add a new metric to show the number of
queries that timed out while waiting to be dispatched (or both). WDYT?
##########
pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/MultiStageQuerySemaphore.java:
##########
@@ -0,0 +1,174 @@
+/**
+ * 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.broker.requesthandler;
+
+import com.google.common.base.Preconditions;
+import java.util.Collections;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import org.apache.helix.HelixAdmin;
+import org.apache.helix.HelixConstants;
+import org.apache.helix.HelixManager;
+import org.apache.helix.model.HelixConfigScope;
+import org.apache.helix.model.builder.HelixConfigScopeBuilder;
+import org.apache.pinot.broker.broker.helix.ClusterChangeHandler;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class helps limit the number of multi-stage queries being executed
concurrently. Currently, this limit is
+ * applied at the broker level, but could be moved to the server level in the
future.
+ */
+public class MultiStageQuerySemaphore extends Semaphore implements
ClusterChangeHandler {
Review Comment:
Good point, I've split up this class into two new ones -
`MultiStageQueryThrottler` which implements the `ClusterChangeHandler`
interface and `AdjustableSemaphore` which is now a generic util class. I've
preferred to keep the minimal interfaces because I don't feel like the amount
of mocking required for testing here is too high, but I'd be happy to
reconsider if you feel strongly about it.
--
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]