Skip to content

Commit

Permalink
Fix bug :Infinity value for CPU or Bandwidth usage (#13609)
Browse files Browse the repository at this point in the history
* fix bug :Infinity value for CPU or Bandwidth usage

* use executorService.schedule replace to executorService.schedule

* 1.use  scheduleAtFixedDelay instead of  scheduleAtFixedRate;
2.returns when elapsedSeconds <= 0 is true, skip this round of calculateBrokerHostUsage;

* 1.move the early return conditional block to before getTotalCpuUsage;

* 1.use scheduleWithFixedDelay instead of scheduleAtFixedRate in the class GenericBrokerHostUsageImpl;

* update log content: add a space in log
  • Loading branch information
lordcheng10 authored Jan 12, 2022
1 parent 9032a9a commit 2a7515f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public GenericBrokerHostUsageImpl(int hostUsageCheckIntervalMin,
this.totalCpuLimit = getTotalCpuLimit();
// Call now to initialize values before the constructor returns
calculateBrokerHostUsage();
executorService.scheduleAtFixedRate(catchingAndLoggingThrowables(this::checkCpuLoad), CPU_CHECK_MILLIS,
executorService.scheduleWithFixedDelay(catchingAndLoggingThrowables(this::checkCpuLoad), CPU_CHECK_MILLIS,
CPU_CHECK_MILLIS, TimeUnit.MILLISECONDS);
executorService.scheduleAtFixedRate(catchingAndLoggingThrowables(this::doCalculateBrokerHostUsage),
executorService.scheduleWithFixedDelay(catchingAndLoggingThrowables(this::doCalculateBrokerHostUsage),
hostUsageCheckIntervalMin,
hostUsageCheckIntervalMin, TimeUnit.MINUTES);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public LinuxBrokerHostUsageImpl(int hostUsageCheckIntervalMin,

// Call now to initialize values before the constructor returns
calculateBrokerHostUsage();
executorService.scheduleAtFixedRate(catchingAndLoggingThrowables(this::calculateBrokerHostUsage),
executorService.scheduleWithFixedDelay(catchingAndLoggingThrowables(this::calculateBrokerHostUsage),
hostUsageCheckIntervalMin,
hostUsageCheckIntervalMin, TimeUnit.MINUTES);
}
Expand All @@ -105,9 +105,14 @@ public void calculateBrokerHostUsage() {
double totalNicUsageRx = getTotalNicUsageRxKb(nics);
double totalCpuLimit = getTotalCpuLimit();

SystemResourceUsage usage = new SystemResourceUsage();
long now = System.currentTimeMillis();
double elapsedSeconds = (now - lastCollection) / 1000d;
if (elapsedSeconds <= 0) {
log.warn("elapsedSeconds {} is not expected, skip this round of calculateBrokerHostUsage", elapsedSeconds);
return;
}

SystemResourceUsage usage = new SystemResourceUsage();
double cpuUsage = getTotalCpuUsage(elapsedSeconds);

if (lastCollection == 0L) {
Expand Down

0 comments on commit 2a7515f

Please sign in to comment.