You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by pe...@apache.org on 2022/04/19 09:51:04 UTC
[pulsar] 02/26: [LoadBalance] Optimize find nics process. (#14340)
This is an automated email from the ASF dual-hosted git repository.
penghui pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit eb6bde2577219819581949e5f89789f54ecc8b40
Author: Qiang Zhao <74...@users.noreply.github.com>
AuthorDate: Fri Feb 18 08:26:16 2022 +0800
[LoadBalance] Optimize find nics process. (#14340)
(cherry picked from commit 77d60b36422738498b7578132090f560c382e89a)
---
.../loadbalance/impl/LinuxBrokerHostUsageImpl.java | 34 ++++++++++------------
1 file changed, 15 insertions(+), 19 deletions(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LinuxBrokerHostUsageImpl.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LinuxBrokerHostUsageImpl.java
index fa187950003..53d8d3e379d 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LinuxBrokerHostUsageImpl.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LinuxBrokerHostUsageImpl.java
@@ -227,23 +227,18 @@ public class LinuxBrokerHostUsageImpl implements BrokerHostUsage {
}
private boolean isPhysicalNic(Path path) {
- if (!path.toString().contains("/virtual/")) {
- try {
- Files.readAllBytes(path.resolve("speed"));
- return true;
- } catch (Exception e) {
- // In some cases, VMs in EC2 won't have the speed reported on the NIC and will give a read-error.
- // Check the type to make sure it's ethernet (type "1")
- try {
- String type = new String(Files.readAllBytes(path.resolve("type")), StandardCharsets.UTF_8).trim();
- return Integer.parseInt(type) == 1;
- } catch (IOException ioe) {
- // wireless nics don't report speed, ignore them.
- return false;
- }
- }
+ if (path.toString().contains("/virtual/")) {
+ return false;
+ }
+ try {
+ // Check the type to make sure it's ethernet (type "1")
+ String type = new String(Files.readAllBytes(path.resolve("type")), StandardCharsets.UTF_8).trim();
+ // wireless NICs don't report speed, ignore them.
+ return Integer.parseInt(type) == 1;
+ } catch (Exception e) {
+ // Read type got error.
+ return false;
}
- return false;
}
private Path getNicSpeedPath(String nic) {
@@ -254,12 +249,13 @@ public class LinuxBrokerHostUsageImpl implements BrokerHostUsage {
// 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)
- .orElseGet(() -> nics.stream().mapToDouble(s -> {
+ .orElseGet(() -> nics.stream().mapToDouble(nicPath -> {
// Nic speed is in Mbits/s, return kbits/s
try {
- return Double.parseDouble(new String(Files.readAllBytes(getNicSpeedPath(s))));
+ return Double.parseDouble(new String(Files.readAllBytes(getNicSpeedPath(nicPath))));
} catch (IOException e) {
- log.error("Failed to read speed for nic " + s, e);
+ log.error(String.format("Failed to read speed for nic %s, maybe you can set broker"
+ + " config [loadBalancerOverrideBrokerNicSpeedGbps] to override it.", nicPath), e);
return 0d;
}
}).sum() * 1024);