merlimat commented on a change in pull request #7475:
URL: https://github.com/apache/pulsar/pull/7475#discussion_r451611511
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LinuxBrokerHostUsageImpl.java
##########
@@ -87,45 +100,36 @@ public void calculateBrokerHostUsage() {
double totalNicUsageTx = getTotalNicUsageTxKb(nics);
double totalNicUsageRx = getTotalNicUsageRxKb(nics);
double totalCpuLimit = getTotalCpuLimit();
- CpuStat cpuStat = getTotalCpuUsage();
SystemResourceUsage usage = new SystemResourceUsage();
long now = System.currentTimeMillis();
+ double elapsedSeconds = (now - lastCollection) / 1000d;
+ double cpuUsage = getTotalCpuUsage(elapsedSeconds);
if (lastCollection == 0L) {
usage.setMemory(getMemUsage());
usage.setBandwidthIn(new ResourceUsage(0d, totalNicLimit));
usage.setBandwidthOut(new ResourceUsage(0d, totalNicLimit));
- usage.setCpu(new ResourceUsage(0d, totalCpuLimit));
} else {
- double elapsedSeconds = (now - lastCollection) / 1000d;
double nicUsageTx = (totalNicUsageTx - lastTotalNicUsageTx) /
elapsedSeconds;
double nicUsageRx = (totalNicUsageRx - lastTotalNicUsageRx) /
elapsedSeconds;
-
- if (cpuStat != null && lastCpuStat != null) {
- // we need two non null stats to get a usage report
- long cpuTimeDiff = cpuStat.getTotalTime() -
lastCpuStat.getTotalTime();
- long cpuUsageDiff = cpuStat.getUsage() -
lastCpuStat.getUsage();
- double cpuUsage = ((double) cpuUsageDiff / (double)
cpuTimeDiff) * totalCpuLimit;
- usage.setCpu(new ResourceUsage(cpuUsage, totalCpuLimit));
- }
-
- usage.setMemory(getMemUsage());
- usage.setBandwidthIn(new ResourceUsage(nicUsageRx, totalNicLimit));
- usage.setBandwidthOut(new ResourceUsage(nicUsageTx,
totalNicLimit));
}
- lastTotalNicUsageTx = totalNicUsageTx;
- lastTotalNicUsageRx = totalNicUsageRx;
- lastCpuStat = cpuStat;
- lastCollection = System.currentTimeMillis();
- this.usage = usage;
+ usage.setCpu(new ResourceUsage(cpuUsage, totalCpuLimit));
}
private double getTotalCpuLimit() {
return 100 * Runtime.getRuntime().availableProcessors();
Review comment:
@ivankelly Yes, actually, the availableProcessor is capped to discrete
CPU units, so we could read fractional CPU quotas from cgoup.
Updated here, PTAL again.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]