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/07/18 02:38:06 UTC

[GitHub] [pulsar] Jason918 commented on a diff in pull request #16408: [fix][broker] Support loadBalancerSheddingIntervalMinutes dynamic configuration

Jason918 commented on code in PR #16408:
URL: https://github.com/apache/pulsar/pull/16408#discussion_r922939459


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java:
##########
@@ -1032,9 +1030,10 @@ protected void startLeaderElectionService() {
                             if (loadResourceQuotaTask != null) {
                                 loadResourceQuotaTask.cancel(false);
                             }
-                            loadSheddingTask = loadManagerExecutor.scheduleAtFixedRate(
-                                    new LoadSheddingTask(loadManager),
-                                    loadSheddingInterval, loadSheddingInterval, TimeUnit.MILLISECONDS);
+                            loadSheddingTask = loadManagerExecutor.schedule(

Review Comment:
   It seems not right to cancel `loadSheddingTask` like this.



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/LoadSheddingTask.java:
##########
@@ -28,15 +31,25 @@
 public class LoadSheddingTask implements Runnable {
     private static final Logger LOG = LoggerFactory.getLogger(LoadSheddingTask.class);
     private final AtomicReference<LoadManager> loadManager;
+    private final ScheduledExecutorService loadManagerExecutor;
 
-    public LoadSheddingTask(AtomicReference<LoadManager> loadManager) {
+    private final ServiceConfiguration config;
+
+    public LoadSheddingTask(AtomicReference<LoadManager> loadManager,
+                            ScheduledExecutorService loadManagerExecutor,
+                            ServiceConfiguration config) {
         this.loadManager = loadManager;
+        this.loadManagerExecutor = loadManagerExecutor;
+        this.config = config;
     }
 
     @Override
     public void run() {
         try {
             loadManager.get().doLoadShedding();
+            loadManagerExecutor.schedule(new LoadSheddingTask(loadManager, loadManagerExecutor, config),

Review Comment:
   This re-schedule better in finally?



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java:
##########
@@ -1032,9 +1030,10 @@ protected void startLeaderElectionService() {
                             if (loadResourceQuotaTask != null) {
                                 loadResourceQuotaTask.cancel(false);
                             }
-                            loadSheddingTask = loadManagerExecutor.scheduleAtFixedRate(
-                                    new LoadSheddingTask(loadManager),
-                                    loadSheddingInterval, loadSheddingInterval, TimeUnit.MILLISECONDS);
+                            loadSheddingTask = loadManagerExecutor.schedule(
+                                    new LoadSheddingTask(loadManager, loadManagerExecutor, config),
+                                    TimeUnit.MINUTES.toMillis(config.getLoadBalancerSheddingIntervalMinutes()),
+                                    TimeUnit.MILLISECONDS);

Review Comment:
   Why not just use `TimeUnit.MINUTES`?



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