merlimat closed pull request #1180: Use double to configure
loadBalancerOverrideBrokerNicSpeedGbps
URL: https://github.com/apache/incubator-pulsar/pull/1180
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/conf/broker.conf b/conf/broker.conf
index 979f4e2d9..780b192d0 100644
--- a/conf/broker.conf
+++ b/conf/broker.conf
@@ -360,7 +360,8 @@ loadBalancerNamespaceMaximumBundles=128
# reported by Linux is not reflecting the real bandwidth available to the
broker.
# Since the network usage is employed by the load manager to decide when a
broker
# is overloaded, it is important to make sure the info is correct or override
it
-# with the right value here.
+# with the right value here. The configured value can be a double (eg: 0.8)
and that
+# can be used to trigger load-shedding even before hitting on NIC limits.
loadBalancerOverrideBrokerNicSpeedGbps=
# Name of load manager to use
diff --git
a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
index 0cc40011b..3fb8f7b4f 100644
---
a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
+++
b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
@@ -349,7 +349,7 @@
private String loadManagerClassName =
"org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl";
// Option to override the auto-detected network interfaces max speed
- private Integer loadBalancerOverrideBrokerNicSpeedGbps;
+ private Double loadBalancerOverrideBrokerNicSpeedGbps;
/**** --- Replication --- ****/
// Enable replication metrics
@@ -1220,11 +1220,11 @@ public int getLoadBalancerNamespaceMaximumBundles() {
return this.loadBalancerNamespaceMaximumBundles;
}
- public Optional<Integer> getLoadBalancerOverrideBrokerNicSpeedGbps() {
+ public Optional<Double> getLoadBalancerOverrideBrokerNicSpeedGbps() {
return Optional.ofNullable(loadBalancerOverrideBrokerNicSpeedGbps);
}
- public void setLoadBalancerOverrideBrokerNicSpeedGbps(int
loadBalancerOverrideBrokerNicSpeedGbps) {
+ public void setLoadBalancerOverrideBrokerNicSpeedGbps(double
loadBalancerOverrideBrokerNicSpeedGbps) {
this.loadBalancerOverrideBrokerNicSpeedGbps =
loadBalancerOverrideBrokerNicSpeedGbps;
}
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 7cdf84c30..7f75d3c68 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
@@ -55,7 +55,7 @@
private OperatingSystemMXBean systemBean;
private SystemResourceUsage usage;
- private final Optional<Integer> overrideBrokerNicSpeedGbps;
+ private final Optional<Double> overrideBrokerNicSpeedGbps;
private static final Logger LOG =
LoggerFactory.getLogger(LinuxBrokerHostUsageImpl.class);
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LoadReportNetworkLimit.java
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LoadReportNetworkLimit.java
index 7f8324731..c9e7510a2 100644
---
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LoadReportNetworkLimit.java
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/LoadReportNetworkLimit.java
@@ -32,7 +32,7 @@
@Override
public void setup() throws Exception {
conf.setLoadBalancerEnabled(true);
- conf.setLoadBalancerOverrideBrokerNicSpeedGbps(5);
+ conf.setLoadBalancerOverrideBrokerNicSpeedGbps(5.4);
super.internalSetup();
}
@@ -49,8 +49,8 @@ public void checkLoadReportNicSpeed() throws Exception {
LoadManagerReport report = admin.brokerStats().getLoadReport();
if (SystemUtils.IS_OS_LINUX) {
- assertEquals(report.getBandwidthIn().limit, 5.0 * 1024 * 1024);
- assertEquals(report.getBandwidthOut().limit, 5.0 * 1024 * 1024);
+ assertEquals(report.getBandwidthIn().limit, 5.4 * 1024 * 1024);
+ assertEquals(report.getBandwidthOut().limit, 5.4 * 1024 * 1024);
} else {
// On non-Linux system we don't report the network usage
assertEquals(report.getBandwidthIn().limit, -1.0);
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/common/naming/ServiceConfigurationTest.java
b/pulsar-broker/src/test/java/org/apache/pulsar/common/naming/ServiceConfigurationTest.java
index bad061c81..4bb4fb994 100644
---
a/pulsar-broker/src/test/java/org/apache/pulsar/common/naming/ServiceConfigurationTest.java
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/common/naming/ServiceConfigurationTest.java
@@ -73,7 +73,7 @@ public void testOptionalSettingPresent() throws Exception {
String confFile = "loadBalancerOverrideBrokerNicSpeedGbps=5\n";
InputStream stream = new ByteArrayInputStream(confFile.getBytes());
final ServiceConfiguration config =
PulsarConfigurationLoader.create(stream, ServiceConfiguration.class);
- assertEquals(config.getLoadBalancerOverrideBrokerNicSpeedGbps(),
Optional.of(5));
+ assertEquals(config.getLoadBalancerOverrideBrokerNicSpeedGbps(),
Optional.of(5.0));
}
/**
diff --git
a/pulsar-common/src/main/java/org/apache/pulsar/common/util/FieldParser.java
b/pulsar-common/src/main/java/org/apache/pulsar/common/util/FieldParser.java
index ebac11186..f6f4fc1b0 100644
--- a/pulsar-common/src/main/java/org/apache/pulsar/common/util/FieldParser.java
+++ b/pulsar-common/src/main/java/org/apache/pulsar/common/util/FieldParser.java
@@ -219,7 +219,12 @@ public static Long stringToLong(String val) {
* @return The converted Double value.
*/
public static Double stringToDouble(String val) {
- return Double.valueOf(trim(val));
+ String v = trim(val);
+ if (StringUtil.isNullOrEmpty(v)) {
+ return null;
+ } else {
+ return Double.valueOf(v);
+ }
}
/**
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services