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/09/05 11:59:44 UTC

[GitHub] [pulsar] codelipenghui commented on a diff in pull request #16557: [PIP-169] Support split bundle by flow or qps

codelipenghui commented on code in PR #16557:
URL: https://github.com/apache/pulsar/pull/16557#discussion_r962823480


##########
pulsar-broker/src/main/java/org/apache/pulsar/common/naming/FlowOrQpsEquallyDivideBundleSplitAlgorithm.java:
##########
@@ -0,0 +1,129 @@
+/**
+ * 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.common.naming;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import org.apache.pulsar.broker.namespace.NamespaceService;
+import org.apache.pulsar.common.policies.data.stats.TopicStatsImpl;
+
+
+/**
+ * Split algorithm based on flow or qps.
+ */
+public class FlowOrQpsEquallyDivideBundleSplitAlgorithm implements NamespaceBundleSplitAlgorithm {
+    private static final long MBytes = 1024 * 1024;
+
+    class TopicInfo {
+        String topicName;
+        double msgRate;
+        double throughput;
+
+        public TopicInfo(String topicName, double msgRate, double throughput) {
+            this.topicName = topicName;
+            this.msgRate = msgRate;
+            this.throughput = throughput;
+        }
+    }
+
+    @Override
+    public CompletableFuture<List<Long>> getSplitBoundary(BundleSplitOption bundleSplitOptionTmp) {
+        FlowOrQpsEquallyDivideBundleSplitOption bundleSplitOption =
+                (FlowOrQpsEquallyDivideBundleSplitOption) bundleSplitOptionTmp;
+        NamespaceService service = bundleSplitOption.getService();
+        NamespaceBundle bundle = bundleSplitOption.getBundle();
+        Map<String, TopicStatsImpl> topicStatsMap = bundleSplitOption.getTopicStatsMap();
+        int loadBalancerNamespaceBundleMaxMsgRate = bundleSplitOption.getLoadBalancerNamespaceBundleMaxMsgRate();
+        double diffThreshold = bundleSplitOption.getFlowOrQpsDifferenceThresholdPercentage() / 100.0;
+        long loadBalancerNamespaceBundleMaxBandwidthBytes = bundleSplitOption
+                .getLoadBalancerNamespaceBundleMaxBandwidthMbytes() * MBytes;
+
+
+        return service.getOwnedTopicListForNamespaceBundle(bundle).thenCompose(topics -> {
+            if (topics == null || topics.size() <= 1) {
+                return CompletableFuture.completedFuture(null);
+            }
+
+            double bundleThroughput = 0;
+            double bundleMsgRate = 0;
+            Map<Long, TopicInfo> topicInfoMap = new HashMap<>();
+            List<Long> topicHashList = new ArrayList<>(topics.size());
+            for (String topic : topics) {
+                TopicStatsImpl topicStats = topicStatsMap.get(topic);
+                if (topicStats == null) {
+                    continue;
+                }
+                double msgRateIn = topicStats.getMsgRateIn();
+                double msgRateOut = topicStats.getMsgRateOut();

Review Comment:
   I think this one is based on the message, not the entry right?



-- 
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