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/01/04 22:12:20 UTC

[GitHub] [pulsar] michaeljmarshall commented on a change in pull request #13609: Fix bug :Infinity value for CPU or Bandwidth usage

michaeljmarshall commented on a change in pull request #13609:
URL: https://github.com/apache/pulsar/pull/13609#discussion_r778420958



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LinuxBrokerHostUsageImpl.java
##########
@@ -108,9 +112,9 @@ public void calculateBrokerHostUsage() {
         SystemResourceUsage usage = new SystemResourceUsage();
         long now = System.currentTimeMillis();
         double elapsedSeconds = (now - lastCollection) / 1000d;
-        double cpuUsage = getTotalCpuUsage(elapsedSeconds);
+        double cpuUsage = (elapsedSeconds <= 0) ? 0 : getTotalCpuUsage(elapsedSeconds);
 
-        if (lastCollection == 0L) {
+        if (lastCollection == 0L || elapsedSeconds <= 0) {

Review comment:
       We could also just add another `if` block here that returns when `elapsedSeconds <= 0` is true. That wouldn't require changing any of the other parts of this method.

##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LinuxBrokerHostUsageImpl.java
##########
@@ -128,6 +132,9 @@ public void calculateBrokerHostUsage() {
         lastCollection = System.currentTimeMillis();
         this.usage = usage;
         usage.setCpu(new ResourceUsage(cpuUsage, totalCpuLimit));
+
+        executorService.schedule(catchingAndLoggingThrowables(this::calculateBrokerHostUsage),

Review comment:
       If there is an exception in the above method, we'll miss calling this `schedule`, which would stop broker host usage calculations.




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