github-actions[bot] commented on code in PR #60855:
URL: https://github.com/apache/doris/pull/60855#discussion_r3321823356
##########
fe/fe-core/src/main/java/org/apache/doris/cloud/rpc/MetaServiceProxy.java:
##########
@@ -194,19 +206,23 @@ public MetaServiceClientWrapper(MetaServiceProxy proxy) {
this.proxy = proxy;
}
- public <Response> Response executeRequest(String methodName,
Function<MetaServiceClient, Response> function)
- throws RpcException {
+ public <Response> Response executeRequest(String methodName,
Function<MetaServiceClient, Response> function,
+ int cost, Function<Response, Cloud.MetaServiceResponseStatus>
statusExtractor) throws RpcException {
long maxRetries = Config.meta_service_rpc_retry_cnt;
for (long tried = 1; tried <= maxRetries; tried++) {
MetaServiceClient client = null;
Review Comment:
`RpcRateLimitException` from `MetaServiceRpcLimiterManager.acquire()` falls
into this generic catch and is retried up to `meta_service_rpc_retry_cnt`. That
makes a local admission-control decision behave like a remote RPC failure: a
cost-limit timeout can block for `retry_cnt *
meta_service_rpc_rate_limit_wait_timeout_ms` (default 10 * 5s) before failing,
and immediate `too many waiting requests` rejections still loop and
sleep/retry. Under overload this keeps FE RPC threads queued longer and adds
more limiter attempts instead of failing fast. Please catch
`RpcRateLimitException` separately and propagate it without retrying (or
otherwise make the retry policy explicit for local limiter failures).
##########
fe/fe-core/src/main/java/org/apache/doris/cloud/rpc/MetaServiceRpcLimiterManager.java:
##########
@@ -0,0 +1,432 @@
+// 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.doris.cloud.rpc;
+
+import org.apache.doris.cloud.rpc.RpcRateLimiter.CostLimiter;
+import org.apache.doris.cloud.rpc.RpcRateLimiter.OverloadQpsLimiter;
+import org.apache.doris.cloud.rpc.RpcRateLimiter.QpsLimiter;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.profile.SummaryProfile;
+import org.apache.doris.metric.CloudMetrics;
+import org.apache.doris.metric.MetricRepo;
+import org.apache.doris.qe.ConnectContext;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+
+public class MetaServiceRpcLimiterManager {
+ private static final Logger LOG =
LogManager.getLogger(MetaServiceRpcLimiterManager.class);
+ private static final String GET_VERSION_METHOD = "getVersion";
+ public static final String GET_TABLE_VERSION_METHOD = "getTableVersion";
+ public static final String GET_PARTITION_VERSION_METHOD =
"getPartitionVersion";
+
+ private final int processorCount;
+ private static volatile MetaServiceRpcLimiterManager instance;
+
+ private volatile boolean lastEnabled = false;
+ private volatile int lastMaxWaitRequestNum = 0;
+ private volatile int lastDefaultQps = 0;
+ private volatile String lastQpsConfig = "";
+ private volatile String lastCostConfig = "";
+ private volatile boolean lastOverloadThrottleEnabled = false;
+ private volatile String lastOverloadThrottleMethodAllowlist = "";
+
+ private Map<String, Integer> methodQpsConfig = new ConcurrentHashMap<>();
+ private Map<String, Integer> methodCostConfig = new ConcurrentHashMap<>();
+ private Set<String> overloadThrottleMethods =
ConcurrentHashMap.newKeySet();
+
+ private final Map<String, QpsLimiter> qpsLimiters = new
ConcurrentHashMap<>();
+ private final Map<String, CostLimiter> costLimiters = new
ConcurrentHashMap<>();
+ private final Map<String, OverloadQpsLimiter> overloadQpsLimiters = new
ConcurrentHashMap<>();
+
+ public static MetaServiceRpcLimiterManager getInstance() {
+ if (instance == null) {
+ synchronized (MetaServiceRpcLimiterManager.class) {
+ if (instance == null) {
+ instance = new
MetaServiceRpcLimiterManager(Runtime.getRuntime().availableProcessors());
+ }
+ }
+ }
+ return instance;
+ }
+
+ @VisibleForTesting
+ MetaServiceRpcLimiterManager(int processorCount) {
+ this.processorCount = processorCount;
+ reloadConfig();
+
MetaServiceOverloadThrottle.getInstance().setFactorChangeListener(this::setOverloadFactor);
+ }
+
+ @VisibleForTesting
+ boolean isConfigChanged() {
+ return Config.meta_service_rpc_rate_limit_enabled != lastEnabled
+ || Config.meta_service_rpc_rate_limit_default_qps_per_core !=
lastDefaultQps
+ || Config.meta_service_rpc_rate_limit_max_waiting_request_num
!= lastMaxWaitRequestNum
+ ||
!Objects.equals(Config.meta_service_rpc_rate_limit_qps_per_core_config,
lastQpsConfig)
+ ||
!Objects.equals(Config.meta_service_rpc_cost_limit_per_core_config,
lastCostConfig)
+ || Config.meta_service_rpc_overload_throttle_enabled !=
lastOverloadThrottleEnabled
+ ||
!Objects.equals(Config.meta_service_rpc_overload_throttle_methods,
+ lastOverloadThrottleMethodAllowlist);
+ }
+
+ @VisibleForTesting
+ boolean reloadConfig() {
+ if (!isConfigChanged()) {
+ return false;
+ }
+ synchronized (this) {
+ if (!isConfigChanged()) {
+ return false;
+ }
+ reloadRateLimiterConfig();
+ reloadOverloadThrottleConfig();
+ }
+ return true;
+ }
+
+ private void reloadRateLimiterConfig() {
+ boolean enabled = Config.meta_service_rpc_rate_limit_enabled;
+ int maxWaitRequestNum =
Config.meta_service_rpc_rate_limit_max_waiting_request_num;
+ int defaultQpsPerCore =
Config.meta_service_rpc_rate_limit_default_qps_per_core;
+ String qpsConfig =
Config.meta_service_rpc_rate_limit_qps_per_core_config;
+ String costConfig = Config.meta_service_rpc_cost_limit_per_core_config;
+ // Parse the qps and cost config
+ parseConfig(qpsConfig, "QPS", methodQpsConfig);
+ parseConfig(costConfig, "cost limit", methodCostConfig);
+ updateQpsLimiters(defaultQpsPerCore, maxWaitRequestNum);
+
+ // If disabled, clear all limiters
+ if (!enabled) {
+ methodCostConfig.clear();
+ qpsLimiters.clear();
+ costLimiters.clear();
+ } else {
+ updateCostLimiters();
+ }
+ // Update last config
+ lastEnabled = enabled;
+ lastMaxWaitRequestNum = maxWaitRequestNum;
+ lastDefaultQps = defaultQpsPerCore;
+ lastQpsConfig = qpsConfig;
+ lastCostConfig = costConfig;
+ LOG.info("Reload meta service rpc rate limit config. enabled: {},
maxWaitRequestNum: {}, defaultQps: {}, "
+ + "qpsConfig: [{}], costConfig: [{}]", lastEnabled,
lastMaxWaitRequestNum, lastDefaultQps,
+ lastQpsConfig, lastCostConfig);
+ }
+
+ private void reloadOverloadThrottleConfig() {
+ boolean overloadThrottleEnabled =
Config.meta_service_rpc_overload_throttle_enabled;
+ String overloadThrottleMethods =
Config.meta_service_rpc_overload_throttle_methods;
+ if (!overloadThrottleEnabled) {
+ this.overloadThrottleMethods.clear();
+ this.overloadQpsLimiters.clear();
+ } else {
+ Set<String> newOverloadThrottleMethods = new HashSet<>();
+ if (overloadThrottleMethods != null &&
!overloadThrottleMethods.isEmpty()) {
+ for (String method : overloadThrottleMethods.split(",")) {
+ String trimmed = method.trim();
+ if (!trimmed.isEmpty()) {
+ if (trimmed.equalsIgnoreCase(GET_VERSION_METHOD)) {
+
newOverloadThrottleMethods.add(GET_TABLE_VERSION_METHOD);
+
newOverloadThrottleMethods.add(GET_PARTITION_VERSION_METHOD);
+ } else {
+ newOverloadThrottleMethods.add(trimmed);
+ }
+ }
+ }
+ }
+ Set<String> toRemove = new HashSet<>();
+ for (String method : this.overloadThrottleMethods) {
+ if (!newOverloadThrottleMethods.contains(method)) {
+ toRemove.add(method);
+ }
+ }
+ this.overloadThrottleMethods.removeAll(toRemove);
+ this.overloadThrottleMethods.addAll(newOverloadThrottleMethods);
+ this.overloadQpsLimiters.keySet()
Review Comment:
On config reload this only removes overload limiters whose methods left the
allowlist; it never updates the existing overload limiters' `baseQps`,
effective rate, or `maxWaitRequestNum`. Normal `qpsLimiters` are updated in
`updateQpsLimiters()`, but if overload throttling is already active (`factor <
1.0`) and an operator changes
`meta_service_rpc_rate_limit_default_qps_per_core` or the per-method QPS
config, the overload limiter keeps enforcing the old base QPS until the factor
returns to 1 and the map is cleared. Since these configs are mutable, reload
should update or recreate `overloadQpsLimiters` with the new base QPS/max-wait
settings as well.
--
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]