You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "thetumbled (via GitHub)" <gi...@apache.org> on 2023/08/29 11:40:52 UTC

[GitHub] [pulsar] thetumbled opened a new pull request, #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

thetumbled opened a new pull request, #21085:
URL: https://github.com/apache/pulsar/pull/21085

   
   ### Motivation
   
   As the discussion of https://github.com/apache/pulsar/pull/21011 , we can reuse the configuration `loadBalancerMaxNumberOfBundlesInBundleLoadReport` in `ExtensibleLoadManager`, apply the topK mechanism to `ModularLoadManagerImpl`.
   
   ### Modifications
   Apply the topK mechanism to `ModularLoadManagerImpl`.
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Does this pull request potentially affect one of the following parts:
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   *If the box was checked, please highlight the changes*
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [ ] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The threading model
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [ ] The metrics
   - [ ] Anything that affects deployment
   
   ### Documentation
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc` <!-- Your PR contains doc changes. -->
   - [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
   - [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
   - [ ] `doc-complete` <!-- Docs have been already added -->
   
   ### Matching PR in forked repository
   
   PR in forked repository: <!-- ENTER URL 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


Re: [PR] [improve] [broker] apply topK machanism to ModularLoadManagerImpl. [pulsar]

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#issuecomment-2122307213

   PTAL, thanks. @Demogorgon314 @heesung-sn @codelipenghui @BewareMyPower @lhotari


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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1314519436


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,29 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {

Review Comment:
   The original logic is that each follower only uploads its own broker data, the leader reads and extracts BundleData, aggregates and uploads BundleData.
   
   If the follower broker only uploads topK from the source, it can make the brokerData smaller. But I feel that such optimization may not be very significant? The pressure should mainly be caused by the reading and writing of a large number of Znodes, with a large number of Bundles corresponding to a large number of Znodes.
   
   Moreover, I feel that the current approach also has a benefit, which is to let the leader broker select the **global** topK * brokerCount, without the need for each follower to select a **local** top K.
   
   PS: If we adopt the idea that follower broker select topK bundleData, we still need to select topK * brokerCount bundleData in leader broker, because each follower uploads only topK does not mean that the BundleData in the leader broker's memory only stores topK * brokerCount.



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309554504


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java:
##########
@@ -103,4 +97,13 @@ public int getTopics() {
     public void setTopics(int topics) {
         this.topics = topics;
     }
+
+    @Override
+    public int compareTo(BundleData o) {
+        int result = this.longTermData.compareTo(o.longTermData);
+        if (result == 0) {
+            result = this.shortTermData.compareTo(o.shortTermData);
+        }

Review Comment:
   May be we should prefer to update short-term data than long-term data?
   There are other approach to sort out the BundleData. We can add a field `lastestSample` to save the lastest `NamespaceBundleStats` in `BundleData` when we call
   https://github.com/apache/pulsar/blob/d099ac4fa2f217b9c5f0a5e660c83048e829c5d7/pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java#L77-L81
   Then we can sort the BundleData based on `lastestSample` as ExtensibleLoadManager does.
   As `NamespaceBundleStats` is unchangeable, we can avoid the concurrent problem too.
   WDYT, @hangc0276 @codelipenghui 



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309554504


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java:
##########
@@ -103,4 +97,13 @@ public int getTopics() {
     public void setTopics(int topics) {
         this.topics = topics;
     }
+
+    @Override
+    public int compareTo(BundleData o) {
+        int result = this.longTermData.compareTo(o.longTermData);
+        if (result == 0) {
+            result = this.shortTermData.compareTo(o.shortTermData);
+        }

Review Comment:
   There is another approach to sort out the BundleData. We can add a field `lastestSample` to save the lastest `NamespaceBundleStats` in `BundleData` when we call
   https://github.com/apache/pulsar/blob/d099ac4fa2f217b9c5f0a5e660c83048e829c5d7/pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java#L77-L81
   Then we can sort the BundleData based on `lastestSample` as ExtensibleLoadManager does.
   As `NamespaceBundleStats` is unchangeable, we can avoid the concurrent problem too.
   WDYT, @hangc0276 @codelipenghui 



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1314519436


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,29 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {

Review Comment:
   The original logic is that each follower only uploads its own broker data, the leader reads and extracts BundleData, aggregates and uploads BundleData.
   
   If the follower broker only uploads the topK bundleData contained in it's brokerData, it can make the brokerData smaller. But I feel that such optimization may not be very significant? The pressure should mainly be caused by the reading and writing of a large number of Znodes, with a large number of Bundles corresponding to a large number of Znodes.
   
   Moreover, I feel that the current approach(that is only leader broker filter bundleData) has a benefit, which is to let the leader broker select the **global** topK * brokerCount, instead of each follower select a **local** top K.
   
   PS: If we adopt the idea that follower broker select topK bundleData, we still need to select topK * brokerCount bundleData in leader broker, because each follower uploads only topK does not mean that the BundleData in the leader broker's memory only stores topK * brokerCount.
   WDYT, @Demogorgon314 @heesung-sn 



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


Re: [PR] [improve] [broker] apply topK machanism to ModularLoadManagerImpl. [pulsar]

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled closed pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.
URL: https://github.com/apache/pulsar/pull/21085


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


[GitHub] [pulsar] heesung-sn commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309136466


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,23 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private int selectTopKBundle() {
+        bundleArr.clear();
+
+        bundleArr.addAll(loadData.getBundleData().entrySet());

Review Comment:
   Are these thread-safe?



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,23 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private int selectTopKBundle() {
+        bundleArr.clear();
+
+        bundleArr.addAll(loadData.getBundleData().entrySet());
+        // select topK bundle for each broker, so select topK * brokerCount bundle in total
+        int brokerCount = loadData.getBrokerData().size();

Review Comment:
   can brokerCount be 0? are we handling this case?



##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/TimeAverageMessageData.java:
##########
@@ -177,4 +175,40 @@ public double totalMsgRate() {
     public double totalMsgThroughput() {
         return msgThroughputIn + msgThroughputOut;
     }
+
+    @Override
+    public int compareTo(TimeAverageMessageData other) {
+        int result = this.compareByBandwidthIn(other);
+
+        if (result == 0) {
+            result = this.compareByBandwidthOut(other);
+        }

Review Comment:
   Why do we have separate bandwithIn and Out checks here? What if some bundles' bandwithOut is way greater than bandwithIn?



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309531265


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,23 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private int selectTopKBundle() {
+        bundleArr.clear();
+
+        bundleArr.addAll(loadData.getBundleData().entrySet());

Review Comment:
   `org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl#writeBundleDataOnZooKeeper` is executed in single thread.
   https://github.com/apache/pulsar/blob/d099ac4fa2f217b9c5f0a5e660c83048e829c5d7/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java#L318-L319
   But, the bundle-data may be updated in another thread, which may fail the sorting process. I will fix this problem.



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1311043357


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/models/TopKBundles.java:
##########
@@ -132,6 +133,42 @@ static void partitionSort(List<Map.Entry<String, ? extends Comparable>> arr, int
         Collections.sort(arr.subList(0, end), (a, b) -> b.getValue().compareTo(a.getValue()));
     }
 
+    public static <T> void partitionSort(List<Map.Entry<String, T>> arr, int k, Comparator<T> comparator) {
+        int start = 0;
+        int end = arr.size() - 1;
+        int target = k - 1;
+        while (start < end) {
+            int lo = start;
+            int hi = end;
+            int mid = lo;
+            var pivot = arr.get(hi).getValue();
+            while (mid <= hi) {
+                int cmp = comparator.compare(pivot, arr.get(mid).getValue());
+                if (cmp < 0) {
+                    var tmp = arr.get(lo);
+                    arr.set(lo++, arr.get(mid));
+                    arr.set(mid++, tmp);
+                } else if (cmp > 0) {
+                    var tmp = arr.get(mid);
+                    arr.set(mid, arr.get(hi));
+                    arr.set(hi--, tmp);
+                } else {
+                    mid++;
+                }
+            }
+            if (lo <= target && target < mid) {
+                end = lo;
+                break;
+            }
+            if (target < lo) {
+                end = lo - 1;
+            } else {
+                start = mid;
+            }
+        }
+        Collections.sort(arr.subList(0, end), (a, b) -> comparator.compare(b.getValue(), a.getValue()));

Review Comment:
   removed.



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1311403237


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java:
##########
@@ -103,4 +97,13 @@ public int getTopics() {
     public void setTopics(int topics) {
         this.topics = topics;
     }
+
+    @Override
+    public int compareTo(BundleData o) {
+        int result = this.longTermData.compareTo(o.longTermData);
+        if (result == 0) {
+            result = this.shortTermData.compareTo(o.shortTermData);
+        }

Review Comment:
   May be we can compare the `shortTermData` first?
   WDYT.  @heesung-sn 



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309539694


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,23 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private int selectTopKBundle() {
+        bundleArr.clear();
+
+        bundleArr.addAll(loadData.getBundleData().entrySet());
+        // select topK bundle for each broker, so select topK * brokerCount bundle in total
+        int brokerCount = loadData.getBrokerData().size();

Review Comment:
   fixed.



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


Re: [PR] [improve] [broker] apply topK machanism to ModularLoadManagerImpl. [pulsar]

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1506916208


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,29 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {

Review Comment:
   I still support that it is leader's responsibility to filter topK, bacause the main pressure is caused by large number of znodes corresponding to large number of bundles stats **uploaded by leader**. 
   Filtering bundles in follower only minimize the single size of one znode, which do not reduce too much pressure on zk. If neccessary, we can raise another pr to implement 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: commits-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] codelipenghui commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "codelipenghui (via GitHub)" <gi...@apache.org>.
codelipenghui commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1314485905


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,29 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {

Review Comment:
   Maybe the reason is we can't get topK bundles based on topK bundles of each broker?
   From this point, it looks like makes sense to introduce a new minimum throughput limitation for the bundle stats that are reported by each broker?



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


[GitHub] [pulsar] Demogorgon314 commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "Demogorgon314 (via GitHub)" <gi...@apache.org>.
Demogorgon314 commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1310027075


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/models/TopKBundles.java:
##########
@@ -132,6 +133,42 @@ static void partitionSort(List<Map.Entry<String, ? extends Comparable>> arr, int
         Collections.sort(arr.subList(0, end), (a, b) -> b.getValue().compareTo(a.getValue()));
     }
 
+    public static <T> void partitionSort(List<Map.Entry<String, T>> arr, int k, Comparator<T> comparator) {
+        int start = 0;
+        int end = arr.size() - 1;
+        int target = k - 1;
+        while (start < end) {
+            int lo = start;
+            int hi = end;
+            int mid = lo;
+            var pivot = arr.get(hi).getValue();
+            while (mid <= hi) {
+                int cmp = comparator.compare(pivot, arr.get(mid).getValue());
+                if (cmp < 0) {
+                    var tmp = arr.get(lo);
+                    arr.set(lo++, arr.get(mid));
+                    arr.set(mid++, tmp);
+                } else if (cmp > 0) {
+                    var tmp = arr.get(mid);
+                    arr.set(mid, arr.get(hi));
+                    arr.set(hi--, tmp);
+                } else {
+                    mid++;
+                }
+            }
+            if (lo <= target && target < mid) {
+                end = lo;
+                break;
+            }
+            if (target < lo) {
+                end = lo - 1;
+            } else {
+                start = mid;
+            }
+        }
+        Collections.sort(arr.subList(0, end), (a, b) -> comparator.compare(b.getValue(), a.getValue()));

Review Comment:
   ```suggestion
           arr.subList(0, end).sort((a, b) -> comparator.compare(b.getValue(), a.getValue()));
   ```



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1145,30 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {
+        CompletableFuture completableFuture = new CompletableFuture();

Review Comment:
   ```suggestion
           CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
   ```



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1145,30 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {
+        CompletableFuture completableFuture = new CompletableFuture();
+
+        executors.execute(() -> {
+            // make the bundle-data update and sorting executed in single thread
+            bundleArr.clear();
+            bundleArr.addAll(loadData.getBundleData().entrySet());
+
+            // select topK bundle for each broker, so select topK * brokerCount bundle in total
+            int brokerCount = Math.max(1, loadData.getBrokerData().size());
+            int updateBundleCount = Math.min(pulsar.getConfiguration()
+                    .getLoadBalancerMaxNumberOfBundlesInBundleLoadReport() * brokerCount, bundleArr.size());
+
+            TopKBundles.partitionSort(bundleArr, updateBundleCount, bundleDataComparator);

Review Comment:
   Should we select the topK bundles for each broker?



##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/BundleDataComparator.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.util;
+
+import java.io.Serializable;
+import java.util.Comparator;
+import org.apache.pulsar.policies.data.loadbalancer.BundleData;
+
+public class BundleDataComparator implements Comparator<BundleData>, Serializable {

Review Comment:
   Can we implement the `Comparable<BundleData>` interface for `BundleData` class?



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1310155909


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1145,30 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {
+        CompletableFuture completableFuture = new CompletableFuture();
+
+        executors.execute(() -> {
+            // make the bundle-data update and sorting executed in single thread
+            bundleArr.clear();
+            bundleArr.addAll(loadData.getBundleData().entrySet());
+
+            // select topK bundle for each broker, so select topK * brokerCount bundle in total
+            int brokerCount = Math.max(1, loadData.getBrokerData().size());
+            int updateBundleCount = Math.min(pulsar.getConfiguration()
+                    .getLoadBalancerMaxNumberOfBundlesInBundleLoadReport() * brokerCount, bundleArr.size());
+
+            TopKBundles.partitionSort(bundleArr, updateBundleCount, bundleDataComparator);

Review Comment:
   In `ExtensibleLoadManager`, each broker will update topK bundle-data, so the total bundle-data count is `brokerCount*topK`.
   While in `ModularLoadManagerImpl`, only leader broker will update the bundle-data. 
   I think that we should make their behavior consistent.



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309536646


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/TimeAverageMessageData.java:
##########
@@ -177,4 +175,40 @@ public double totalMsgRate() {
     public double totalMsgThroughput() {
         return msgThroughputIn + msgThroughputOut;
     }
+
+    @Override
+    public int compareTo(TimeAverageMessageData other) {
+        int result = this.compareByBandwidthIn(other);
+
+        if (result == 0) {
+            result = this.compareByBandwidthOut(other);
+        }

Review Comment:
   I imitate the logic implemented by 
   https://github.com/apache/pulsar/blob/d099ac4fa2f217b9c5f0a5e660c83048e829c5d7/pulsar-client-admin-api/src/main/java/org/apache/pulsar/policies/data/loadbalancer/NamespaceBundleStats.java#L70-L87



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


[GitHub] [pulsar] heesung-sn commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309112337


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,23 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private int selectTopKBundle() {
+        bundleArr.clear();
+
+        bundleArr.addAll(loadData.getBundleData().entrySet());
+        // select topK bundle for each broker, so select topK * brokerCount bundle in total
+        int brokerCount = loadData.getBrokerData().size();
+        int updateBundleCount = pulsar.getConfiguration()
+                .getLoadBalancerMaxNumberOfBundlesInBundleLoadReport() * brokerCount;
+        updateBundleCount = Math.min(updateBundleCount, bundleArr.size());

Review Comment:
   Maybe, 
   
   Math.max(1, Math.min(updateBundleCount, bundleArr.size())); to be safe?



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309554504


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java:
##########
@@ -103,4 +97,13 @@ public int getTopics() {
     public void setTopics(int topics) {
         this.topics = topics;
     }
+
+    @Override
+    public int compareTo(BundleData o) {
+        int result = this.longTermData.compareTo(o.longTermData);
+        if (result == 0) {
+            result = this.shortTermData.compareTo(o.shortTermData);
+        }

Review Comment:
   There is another approach to sort out the BundleData. We can add a field `lastSample` to save the lastest `NamespaceBundleStats` in `BundleData` when we call
   https://github.com/apache/pulsar/blob/d099ac4fa2f217b9c5f0a5e660c83048e829c5d7/pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java#L77-L81
   Then we can sort the BundleData based on `lastSample` as ExtensibleLoadManager does.
   As `NamespaceBundleStats` is unchangeable, we can avoid the concurrent problem too.
   WDYT, @hangc0276 @codelipenghui 



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309536646


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/TimeAverageMessageData.java:
##########
@@ -177,4 +175,40 @@ public double totalMsgRate() {
     public double totalMsgThroughput() {
         return msgThroughputIn + msgThroughputOut;
     }
+
+    @Override
+    public int compareTo(TimeAverageMessageData other) {
+        int result = this.compareByBandwidthIn(other);
+
+        if (result == 0) {
+            result = this.compareByBandwidthOut(other);
+        }

Review Comment:
   I imitate the logic implemented by 
   https://github.com/apache/pulsar/blob/master/pulsar-client-admin-api/src/main/java/org/apache/pulsar/policies/data/loadbalancer/NamespaceBundleStats.java#L40-L47



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1314519436


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,29 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {

Review Comment:
   The original logic is that each follower only uploads its own broker data, the leader reads and extracts BundleData, aggregates and uploads BundleData.
   If the follower broker only uploads topK from the source, it can make the brokerData smaller. But I feel that such optimization may not be very significant? The pressure should mainly be caused by the reading and writing of a large number of Znodes, with a large number of Bundles corresponding to a large number of Znodes.
   Moreover, I feel that the current approach also has a benefit, which is to let the leader broker select the **global** topK * brokerCount, without the need for each follower to select a **local** top K.



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


[GitHub] [pulsar] thetumbled commented on pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#issuecomment-1697373367

   PTAL, thanks. @codelipenghui @hangc0276 @heesung-sn @Demogorgon314 


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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1310047764


##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/BundleDataComparator.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.util;
+
+import java.io.Serializable;
+import java.util.Comparator;
+import org.apache.pulsar.policies.data.loadbalancer.BundleData;
+
+public class BundleDataComparator implements Comparator<BundleData>, Serializable {

Review Comment:
   If we implement the Comparable<BundleData> interface for BundleData class, we have to override the `equals` and `hashcode` method for BundleData, or bug spot tools will report errors like:
   ```
   [ERROR] Medium: org.apache.pulsar.policies.data.loadbalancer.BundleData defines compareTo(BundleData) and uses Object.equals() [org.apache.pulsar.policies.data.loadbalancer.BundleData] At BundleData.java:[lines 103-107] EQ_COMPARETO_USE_OBJECT_EQUALS
   ```
   But i am afraid that it will influence logic in the other places. 



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


[GitHub] [pulsar] heesung-sn commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1311835447


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/TimeAverageMessageData.java:
##########
@@ -177,4 +175,40 @@ public double totalMsgRate() {
     public double totalMsgThroughput() {
         return msgThroughputIn + msgThroughputOut;
     }
+
+    @Override
+    public int compareTo(TimeAverageMessageData other) {
+        int result = this.compareByBandwidthIn(other);
+
+        if (result == 0) {
+            result = this.compareByBandwidthOut(other);
+        }

Review Comment:
   To me, this seems like another bug. but I agree that we are not fixing this issue in this PR>



##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/TimeAverageMessageData.java:
##########
@@ -177,4 +175,40 @@ public double totalMsgRate() {
     public double totalMsgThroughput() {
         return msgThroughputIn + msgThroughputOut;
     }
+
+    @Override
+    public int compareTo(TimeAverageMessageData other) {
+        int result = this.compareByBandwidthIn(other);
+
+        if (result == 0) {
+            result = this.compareByBandwidthOut(other);
+        }

Review Comment:
   To me, this seems like another bug. but I agree that we are not fixing this issue in this PR.



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1314519436


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,29 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {

Review Comment:
   The original logic is that each follower only uploads its own broker data, the leader reads and extracts BundleData, aggregates and uploads BundleData.
   
   If the follower broker only uploads the topK bundleData contained in it's brokerData, it can make the brokerData smaller. But I feel that such optimization may not be very significant? The pressure should mainly be caused by the reading and writing of a large number of Znodes, with a large number of Bundles corresponding to a large number of Znodes.
   
   Moreover, I feel that the current approach(that is only leader broker filter bundleData) has a benefit, which is to let the leader broker select the **global** topK * brokerCount, instead of each follower select a **local** top K.
   
   PS: If we adopt the idea that follower broker select topK bundleData, we still need to select topK * brokerCount bundleData in leader broker, because each follower uploads only topK does not mean that the BundleData in the leader broker's memory only stores topK * brokerCount.



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1314519436


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,29 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {

Review Comment:
   The original logic is that each follower only uploads its own broker data, the leader reads and extracts BundleData, aggregates and uploads BundleData.
   If the follower broker only uploads topK from the source, it can make the brokerData smaller. But I feel that such optimization may not be very significant? The pressure should mainly be caused by the reading and writing of a large number of Znodes, with a large number of Bundles corresponding to a large number of Znodes.
   
   Moreover, I feel that the current approach also has a benefit, which is to let the leader broker select the **global** topK * brokerCount, without the need for each follower to select a **local** top K.



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309554504


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java:
##########
@@ -103,4 +97,13 @@ public int getTopics() {
     public void setTopics(int topics) {
         this.topics = topics;
     }
+
+    @Override
+    public int compareTo(BundleData o) {
+        int result = this.longTermData.compareTo(o.longTermData);
+        if (result == 0) {
+            result = this.shortTermData.compareTo(o.shortTermData);
+        }

Review Comment:
   There is another approach to sort out the BundleData. We can add a field `lastSample` to save the lastest `NamespaceBundleStats` in `BundleData` when we call
   https://github.com/apache/pulsar/blob/d099ac4fa2f217b9c5f0a5e660c83048e829c5d7/pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java#L77-L81
   Then we can sort the BundleData based on `lastSample` as ExtensibleLoadManager does.
   WDYT, @hangc0276 @codelipenghui 



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


[GitHub] [pulsar] Demogorgon314 commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "Demogorgon314 (via GitHub)" <gi...@apache.org>.
Demogorgon314 commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1310063331


##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/BundleDataComparator.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.util;
+
+import java.io.Serializable;
+import java.util.Comparator;
+import org.apache.pulsar.policies.data.loadbalancer.BundleData;
+
+public class BundleDataComparator implements Comparator<BundleData>, Serializable {

Review Comment:
   I don't think overriding the `equals` and `hashcode` methods will influence other places. Can you confirm 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: commits-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309540812


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,23 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private int selectTopKBundle() {
+        bundleArr.clear();
+
+        bundleArr.addAll(loadData.getBundleData().entrySet());
+        // select topK bundle for each broker, so select topK * brokerCount bundle in total
+        int brokerCount = loadData.getBrokerData().size();
+        int updateBundleCount = pulsar.getConfiguration()
+                .getLoadBalancerMaxNumberOfBundlesInBundleLoadReport() * brokerCount;
+        updateBundleCount = Math.min(updateBundleCount, bundleArr.size());

Review Comment:
   fixed.



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


[GitHub] [pulsar] hangc0276 commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "hangc0276 (via GitHub)" <gi...@apache.org>.
hangc0276 commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1314396562


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,29 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {

Review Comment:
   Do we need to apply the `topK` selection on each broker's bundle stats report stage?



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


Re: [PR] [improve] [broker] apply topK machanism to ModularLoadManagerImpl. [pulsar]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#issuecomment-1747913086

   The pr had no activity for 30 days, mark with Stale label.


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


Re: [PR] [improve] [broker] apply topK machanism to ModularLoadManagerImpl. [pulsar]

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1506916208


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,29 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {

Review Comment:
   I still support that it is leader's responsibility to filter topK, bacause the main pressure is caused by large number of znodes corresponding to large bundles stats **uploaded by leader**. 
   Filtering bundles in follower only minimize the single size of one znode, which do not reduce too much pressure on zk. If neccessary, we can raise another pr to implement 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: commits-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] heesung-sn commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309134566


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java:
##########
@@ -103,4 +97,13 @@ public int getTopics() {
     public void setTopics(int topics) {
         this.topics = topics;
     }
+
+    @Override
+    public int compareTo(BundleData o) {
+        int result = this.longTermData.compareTo(o.longTermData);
+        if (result == 0) {
+            result = this.shortTermData.compareTo(o.shortTermData);
+        }

Review Comment:
   What if short-term data is significantly higher than long-term's?



##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/TimeAverageMessageData.java:
##########
@@ -41,15 +41,20 @@ public class TimeAverageMessageData {
     // The average message rate out per second.
     private double msgRateOut;
 
+    // Consider the throughput equal if difference is less than 100 KB/s
+    private static final double throughputDifferenceThreshold = 1e5;
+    // Consider the msgRate equal if the difference is less than 100
+    private static final double msgRateDifferenceThreshold = 100;

Review Comment:
   What's the justification for these vals?



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


[GitHub] [pulsar] heesung-sn commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1311834292


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java:
##########
@@ -103,4 +97,13 @@ public int getTopics() {
     public void setTopics(int topics) {
         this.topics = topics;
     }
+
+    @Override
+    public int compareTo(BundleData o) {
+        int result = this.longTermData.compareTo(o.longTermData);
+        if (result == 0) {
+            result = this.shortTermData.compareTo(o.shortTermData);
+        }

Review Comment:
   I think this may require some community agreement, but +1 for short-term IMO.



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1310141718


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/models/TopKBundles.java:
##########
@@ -132,6 +133,42 @@ static void partitionSort(List<Map.Entry<String, ? extends Comparable>> arr, int
         Collections.sort(arr.subList(0, end), (a, b) -> b.getValue().compareTo(a.getValue()));
     }
 
+    public static <T> void partitionSort(List<Map.Entry<String, T>> arr, int k, Comparator<T> comparator) {
+        int start = 0;
+        int end = arr.size() - 1;
+        int target = k - 1;
+        while (start < end) {
+            int lo = start;
+            int hi = end;
+            int mid = lo;
+            var pivot = arr.get(hi).getValue();
+            while (mid <= hi) {
+                int cmp = comparator.compare(pivot, arr.get(mid).getValue());
+                if (cmp < 0) {
+                    var tmp = arr.get(lo);
+                    arr.set(lo++, arr.get(mid));
+                    arr.set(mid++, tmp);
+                } else if (cmp > 0) {
+                    var tmp = arr.get(mid);
+                    arr.set(mid, arr.get(hi));
+                    arr.set(hi--, tmp);
+                } else {
+                    mid++;
+                }
+            }
+            if (lo <= target && target < mid) {
+                end = lo;
+                break;
+            }
+            if (target < lo) {
+                end = lo - 1;
+            } else {
+                start = mid;
+            }
+        }
+        Collections.sort(arr.subList(0, end), (a, b) -> comparator.compare(b.getValue(), a.getValue()));

Review Comment:
   I imitate the logic implemented by 
   https://github.com/apache/pulsar/blob/ee5ac8607ebd7f90843789d4eead48de8600c1f0/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/models/TopKBundles.java#L132-L132
   I think we should make them consistent.



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309554504


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java:
##########
@@ -103,4 +97,13 @@ public int getTopics() {
     public void setTopics(int topics) {
         this.topics = topics;
     }
+
+    @Override
+    public int compareTo(BundleData o) {
+        int result = this.longTermData.compareTo(o.longTermData);
+        if (result == 0) {
+            result = this.shortTermData.compareTo(o.shortTermData);
+        }

Review Comment:
   May be we should prefer to update short-term data than long-term data?
   WDYT, @hangc0276 @codelipenghui 



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


Re: [PR] [improve] [broker] apply topK machanism to ModularLoadManagerImpl. [pulsar]

Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1506894322


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,29 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {

Review Comment:
   I think we can scope out the brokerData optimization in this PR. Then, we can raise another PR to put only topk bundles in brokerData if further optimization is required. 
   
   
   
   



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


Re: [PR] [improve] [broker] apply topK machanism to ModularLoadManagerImpl. [pulsar]

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1506916208


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,29 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {

Review Comment:
   I still support that it is leader's responsibility to filter topK, bacause the main pressure is caused by large number of znodes corresponding to large number of bundles stats **uploaded by leader**. 
   Filtering bundles in follower only minimize the size of single znode, which do not reduce too much pressure on zk. If neccessary, we can raise another pr to implement 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: commits-unsubscribe@pulsar.apache.org

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


Re: [PR] [improve] [broker] apply topK machanism to ModularLoadManagerImpl. [pulsar]

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#issuecomment-2122305937

   List some experimetal data to show the improvement.
   I deploy a cluster with 5 nodes, and there are 1k+ bundles in the cluster. Set topK=20, so that there will be 20*5=100 bundles to be uploaded to zk, which means we filter out 90% bundles. It is ok that we filter so many bundles as most of the them are small bundles.
   Following graph show the effects:
   ![image](https://github.com/apache/pulsar/assets/52550727/2db39be4-2e4e-4c88-8a72-e46147c22116)
   ![image](https://github.com/apache/pulsar/assets/52550727/b1cf7063-dd92-4018-8ef3-67038d899c9b)
   Write latency has decreased from 200ms to single digits!
   
   Not only do write latency and throughput decrease, but read latency and throughput also decrease significantly! Because as long as there is less writing, there is also less reading.
   ![image](https://github.com/apache/pulsar/assets/52550727/d166f7e9-ae47-4361-8e14-8076ef206ccb)
   ![image](https://github.com/apache/pulsar/assets/52550727/42c2076c-d475-4656-ac23-0a04e3dbda55)
   
   


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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309572714


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,23 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private int selectTopKBundle() {
+        bundleArr.clear();
+
+        bundleArr.addAll(loadData.getBundleData().entrySet());

Review Comment:
   fixed.



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1310051180


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1145,30 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {
+        CompletableFuture completableFuture = new CompletableFuture();

Review Comment:
   fixed.



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309531265


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,23 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private int selectTopKBundle() {
+        bundleArr.clear();
+
+        bundleArr.addAll(loadData.getBundleData().entrySet());

Review Comment:
   `org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl#writeBundleDataOnZooKeeper` is executed in single thread.
   https://github.com/apache/pulsar/blob/master/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java#L318-L319
   But, the bundle-data may be updated in another thread, which may fail the sorting process. I will fix this problem.



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309538255


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/TimeAverageMessageData.java:
##########
@@ -41,15 +41,20 @@ public class TimeAverageMessageData {
     // The average message rate out per second.
     private double msgRateOut;
 
+    // Consider the throughput equal if difference is less than 100 KB/s
+    private static final double throughputDifferenceThreshold = 1e5;
+    // Consider the msgRate equal if the difference is less than 100
+    private static final double msgRateDifferenceThreshold = 100;

Review Comment:
   I imitate the logic implemented by 
   https://github.com/apache/pulsar/blob/d099ac4fa2f217b9c5f0a5e660c83048e829c5d7/pulsar-client-admin-api/src/main/java/org/apache/pulsar/policies/data/loadbalancer/NamespaceBundleStats.java#L40-L47



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


[GitHub] [pulsar] heesung-sn commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309137447


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,23 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private int selectTopKBundle() {
+        bundleArr.clear();
+
+        bundleArr.addAll(loadData.getBundleData().entrySet());
+        // select topK bundle for each broker, so select topK * brokerCount bundle in total
+        int brokerCount = loadData.getBrokerData().size();
+        int updateBundleCount = pulsar.getConfiguration()
+                .getLoadBalancerMaxNumberOfBundlesInBundleLoadReport() * brokerCount;

Review Comment:
   can brokerCount be 0?



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1309554504


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java:
##########
@@ -103,4 +97,13 @@ public int getTopics() {
     public void setTopics(int topics) {
         this.topics = topics;
     }
+
+    @Override
+    public int compareTo(BundleData o) {
+        int result = this.longTermData.compareTo(o.longTermData);
+        if (result == 0) {
+            result = this.shortTermData.compareTo(o.shortTermData);
+        }

Review Comment:
   There is another approach to sort out the BundleData. We can add a field `lastSample` to save the lastest `NamespaceBundleStats` in `BundleData` when we call
   https://github.com/apache/pulsar/blob/d099ac4fa2f217b9c5f0a5e660c83048e829c5d7/pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java#L77-L81
   Then we can sort the BundleData based on `lastSample` as ExtensibleLoadManager does.
   Or we prefer to use the `TimeAverageMessageData`?
   WDYT, @hangc0276 @codelipenghui 



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


[GitHub] [pulsar] Demogorgon314 commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "Demogorgon314 (via GitHub)" <gi...@apache.org>.
Demogorgon314 commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1311350024


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java:
##########
@@ -103,4 +97,13 @@ public int getTopics() {
     public void setTopics(int topics) {
         this.topics = topics;
     }
+
+    @Override
+    public int compareTo(BundleData o) {
+        int result = this.longTermData.compareTo(o.longTermData);
+        if (result == 0) {
+            result = this.shortTermData.compareTo(o.shortTermData);
+        }

Review Comment:
   I prefer to compare the `shortTermData` first.



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


[GitHub] [pulsar] thetumbled commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1311043234


##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/BundleDataComparator.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.util;
+
+import java.io.Serializable;
+import java.util.Comparator;
+import org.apache.pulsar.policies.data.loadbalancer.BundleData;
+
+public class BundleDataComparator implements Comparator<BundleData>, Serializable {

Review Comment:
   revert to implement the `Comparable` interface.



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


[GitHub] [pulsar] codelipenghui commented on a diff in pull request #21085: [improve] [broker] apply topK machanism to ModularLoadManagerImpl.

Posted by "codelipenghui (via GitHub)" <gi...@apache.org>.
codelipenghui commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1314491224


##########
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/BundleData.java:
##########
@@ -103,4 +97,13 @@ public int getTopics() {
     public void setTopics(int topics) {
         this.topics = topics;
     }
+
+    @Override
+    public int compareTo(BundleData o) {
+        int result = this.longTermData.compareTo(o.longTermData);
+        if (result == 0) {
+            result = this.shortTermData.compareTo(o.shortTermData);
+        }

Review Comment:
   +1 for short-term data



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


Re: [PR] [improve] [broker] apply topK machanism to ModularLoadManagerImpl. [pulsar]

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on code in PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#discussion_r1506912336


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -1139,6 +1143,29 @@ public void writeBrokerDataOnZooKeeper(boolean force) {
         }
     }
 
+    /**
+     * sort bundles by load and select topK bundles for each broker.
+     * @return the number of bundles selected
+     */
+    private CompletableFuture<Integer> selectTopKBundle() {

Review Comment:
   Sorry, i don't get your point. Do you agree with that leader filter topK, or follower filter topK?



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


Re: [PR] [improve] [broker] apply topK machanism to ModularLoadManagerImpl. [pulsar]

Posted by "thetumbled (via GitHub)" <gi...@apache.org>.
thetumbled commented on PR #21085:
URL: https://github.com/apache/pulsar/pull/21085#issuecomment-2122455991

   close it as it stay for too long, create a new pr: https://github.com/apache/pulsar/pull/22753, thanks.


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