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)
gaozhangmin authored and Jason918 committed Jul 29, 2022
1 parent caf3fac commit ac85bbd
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -237,7 +237,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(s -> {
// Nic speed is in Mbits/s, return kbits/s
try {
@@ -246,7 +246,7 @@ private double getTotalNicLimitKbps(List<String> nics) {
log.error("Failed to read speed for nic " + s, e);
return 0d;
}
}).sum() * 1024);
}).sum() * 1000);
}

private Path getNicTxPath(String nic) {
@@ -265,7 +265,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) {
@@ -276,7 +276,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 {
Original file line number Diff line number Diff line change
@@ -49,8 +49,8 @@ public void checkLoadReportNicSpeed() throws Exception {
LoadManagerReport report = admin.brokerStats().getLoadReport();

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

0 comments on commit ac85bbd

Please sign in to comment.