You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/06/14 21:23:07 UTC

[GitHub] [pulsar] heesung-sn commented on a diff in pull request #14971: [feature][broker] Add new load manager strategy for load manager to select broker having load below average.

heesung-sn commented on code in PR #14971:
URL: https://github.com/apache/pulsar/pull/14971#discussion_r897334149


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ThresholdLoadManagerStrategy.java:
##########
@@ -0,0 +1,131 @@
+/**
+ * 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.pulsar.broker.loadbalance.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ThreadLocalRandom;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.loadbalance.LoadData;
+import org.apache.pulsar.broker.loadbalance.ModularLoadManagerStrategy;
+import org.apache.pulsar.policies.data.loadbalancer.BrokerData;
+import org.apache.pulsar.policies.data.loadbalancer.BundleData;
+import org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData;
+
+/**
+ * Placement strategy which randomly selects a broker from those having resource usage below average load.
+ */
+@Slf4j
+public class ThresholdLoadManagerStrategy implements ModularLoadManagerStrategy {
+    // Maintain this list to reduce object creation.
+    private final ArrayList<String> bestBrokers;
+
+    // candidate broker -> broker usage.
+    private final Map<String, Double> brokerUsages;
+
+    public ThresholdLoadManagerStrategy() {
+        bestBrokers = new ArrayList<>();
+        brokerUsages = new HashMap<>();
+    }
+
+    private static double getScore(final BrokerData brokerData, final ServiceConfiguration conf) {
+        final double overloadThreshold = conf.getLoadBalancerBrokerOverloadedThresholdPercentage() / 100.0;
+        final double maxUsage = brokerData.getLocalData().getMaxResourceUsage();
+        if (maxUsage > overloadThreshold) {
+            log.warn("Broker {} is overloaded: max usage={}", brokerData.getLocalData().getWebServiceUrl(), maxUsage);
+            return Double.POSITIVE_INFINITY;
+        }
+
+        double brokerResourceUsage = brokerData.getLocalData().getMaxResourceUsageWithWeight(

Review Comment:
   Afaik, this `brokerResourceUsage` is relatively short-term data(every 5 sec).  Can you share why we are using this short-term usage data in this `getScore()` function?
   
   For example, I am wondering how we are going to handle the following scenarios. 
   - In one sample, one broker was temporally idle, but afterward, it became mostly busy.
   - In one sample, conversely, one broker was temporally very busy, but afterward, it became mostly idle.
   
   I don't think there is a definitive answer here, but could you share why we only use the short-term usage data here?



-- 
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-unsubscribe@pulsar.apache.org

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