Skip to content

Commit

Permalink
[fix][branch-2.9] Fix wrong unit of NIC speed on linux (#15770)
Browse files Browse the repository at this point in the history
(cherry picked from commit 48d6086)
  • Loading branch information
gaozhangmin authored and BewareMyPower committed Jul 28, 2022
1 parent a5692a6 commit bdd65f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private Path getNicSpeedPath(String nic) {
private double getTotalNicLimitKbps(List<String> nics) {
// Use the override value as configured. Return the total max speed across all available NICs, converted
// from Gbps into Kbps
return overrideBrokerNicSpeedGbps.map(aDouble -> aDouble * nics.size() * 1024 * 1024)
return overrideBrokerNicSpeedGbps.map(aDouble -> aDouble * nics.size() * 1000 * 1000)
.orElseGet(() -> nics.stream().mapToDouble(nicPath -> {
// Nic speed is in Mbits/s, return kbits/s
try {
Expand All @@ -258,7 +258,7 @@ private double getTotalNicLimitKbps(List<String> nics) {
+ " config [loadBalancerOverrideBrokerNicSpeedGbps] to override it.", nicPath), e);
return 0d;
}
}).sum() * 1024);
}).sum() * 1000);
}

private Path getNicTxPath(String nic) {
Expand All @@ -277,7 +277,7 @@ private double getTotalNicUsageRxKb(List<String> nics) {
log.error("Failed to read rx_bytes for NIC " + s, e);
return 0d;
}
}).sum() * 8 / 1024;
}).sum() * 8d / 1000;
}

private double getTotalNicUsageTxKb(List<String> nics) {
Expand All @@ -288,7 +288,7 @@ private double getTotalNicUsageTxKb(List<String> nics) {
log.error("Failed to read tx_bytes for NIC " + s, e);
return 0d;
}
}).sum() * 8 / 1024;
}).sum() * 8d / 1000;
}

private static long readLongFromFile(String path) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public void checkLoadReportNicSpeed() throws Exception {
LoadManagerReport report = admin.brokerStats().getLoadReport();

if (SystemUtils.IS_OS_LINUX) {
assertEquals(report.getBandwidthIn().limit, nicCount * 5.4 * 1024 * 1024);
assertEquals(report.getBandwidthOut().limit, nicCount * 5.4 * 1024 * 1024);
assertEquals(report.getBandwidthIn().limit, nicCount * 5.4 * 1000 * 1000);
assertEquals(report.getBandwidthOut().limit, nicCount * 5.4 * 1000 * 1000);
} else {
// On non-Linux system we don't report the network usage
assertEquals(report.getBandwidthIn().limit, -1.0);
Expand Down

0 comments on commit bdd65f5

Please sign in to comment.