Skip to content

Commit

Permalink
Use double to configure loadBalancerOverrideBrokerNicSpeedGbps (#1180)
Browse files Browse the repository at this point in the history
* Use double to configure loadBalancerOverrideBrokerNicSpeedGbps

* Fixed tests
  • Loading branch information
merlimat committed Feb 6, 2018
1 parent 03ade5c commit 0ba6ae9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion conf/broker.conf
Expand Up @@ -360,7 +360,8 @@ loadBalancerNamespaceMaximumBundles=128
# reported by Linux is not reflecting the real bandwidth available to the broker. # 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 # 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 # 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= loadBalancerOverrideBrokerNicSpeedGbps=


# Name of load manager to use # Name of load manager to use
Expand Down
Expand Up @@ -353,7 +353,7 @@ public class ServiceConfiguration implements PulsarConfiguration {
private String loadManagerClassName = "org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl"; private String loadManagerClassName = "org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl";


// Option to override the auto-detected network interfaces max speed // Option to override the auto-detected network interfaces max speed
private Integer loadBalancerOverrideBrokerNicSpeedGbps; private Double loadBalancerOverrideBrokerNicSpeedGbps;


/**** --- Replication --- ****/ /**** --- Replication --- ****/
// Enable replication metrics // Enable replication metrics
Expand Down Expand Up @@ -1232,11 +1232,11 @@ public int getLoadBalancerNamespaceMaximumBundles() {
return this.loadBalancerNamespaceMaximumBundles; return this.loadBalancerNamespaceMaximumBundles;
} }


public Optional<Integer> getLoadBalancerOverrideBrokerNicSpeedGbps() { public Optional<Double> getLoadBalancerOverrideBrokerNicSpeedGbps() {
return Optional.ofNullable(loadBalancerOverrideBrokerNicSpeedGbps); return Optional.ofNullable(loadBalancerOverrideBrokerNicSpeedGbps);
} }


public void setLoadBalancerOverrideBrokerNicSpeedGbps(int loadBalancerOverrideBrokerNicSpeedGbps) { public void setLoadBalancerOverrideBrokerNicSpeedGbps(double loadBalancerOverrideBrokerNicSpeedGbps) {
this.loadBalancerOverrideBrokerNicSpeedGbps = loadBalancerOverrideBrokerNicSpeedGbps; this.loadBalancerOverrideBrokerNicSpeedGbps = loadBalancerOverrideBrokerNicSpeedGbps;
} }


Expand Down
Expand Up @@ -55,7 +55,7 @@ public class LinuxBrokerHostUsageImpl implements BrokerHostUsage {
private OperatingSystemMXBean systemBean; private OperatingSystemMXBean systemBean;
private SystemResourceUsage usage; private SystemResourceUsage usage;


private final Optional<Integer> overrideBrokerNicSpeedGbps; private final Optional<Double> overrideBrokerNicSpeedGbps;


private static final Logger LOG = LoggerFactory.getLogger(LinuxBrokerHostUsageImpl.class); private static final Logger LOG = LoggerFactory.getLogger(LinuxBrokerHostUsageImpl.class);


Expand Down
Expand Up @@ -32,7 +32,7 @@ public class LoadReportNetworkLimit extends MockedPulsarServiceBaseTest {
@Override @Override
public void setup() throws Exception { public void setup() throws Exception {
conf.setLoadBalancerEnabled(true); conf.setLoadBalancerEnabled(true);
conf.setLoadBalancerOverrideBrokerNicSpeedGbps(5); conf.setLoadBalancerOverrideBrokerNicSpeedGbps(5.4);
super.internalSetup(); super.internalSetup();
} }


Expand All @@ -49,8 +49,8 @@ public void checkLoadReportNicSpeed() throws Exception {
LoadManagerReport report = admin.brokerStats().getLoadReport(); LoadManagerReport report = admin.brokerStats().getLoadReport();


if (SystemUtils.IS_OS_LINUX) { if (SystemUtils.IS_OS_LINUX) {
assertEquals(report.getBandwidthIn().limit, 5.0 * 1024 * 1024); assertEquals(report.getBandwidthIn().limit, 5.4 * 1024 * 1024);
assertEquals(report.getBandwidthOut().limit, 5.0 * 1024 * 1024); assertEquals(report.getBandwidthOut().limit, 5.4 * 1024 * 1024);
} else { } else {
// On non-Linux system we don't report the network usage // On non-Linux system we don't report the network usage
assertEquals(report.getBandwidthIn().limit, -1.0); assertEquals(report.getBandwidthIn().limit, -1.0);
Expand Down
Expand Up @@ -73,7 +73,7 @@ public void testOptionalSettingPresent() throws Exception {
String confFile = "loadBalancerOverrideBrokerNicSpeedGbps=5\n"; String confFile = "loadBalancerOverrideBrokerNicSpeedGbps=5\n";
InputStream stream = new ByteArrayInputStream(confFile.getBytes()); InputStream stream = new ByteArrayInputStream(confFile.getBytes());
final ServiceConfiguration config = PulsarConfigurationLoader.create(stream, ServiceConfiguration.class); final ServiceConfiguration config = PulsarConfigurationLoader.create(stream, ServiceConfiguration.class);
assertEquals(config.getLoadBalancerOverrideBrokerNicSpeedGbps(), Optional.of(5)); assertEquals(config.getLoadBalancerOverrideBrokerNicSpeedGbps(), Optional.of(5.0));
} }


/** /**
Expand Down
Expand Up @@ -219,7 +219,12 @@ public static Long stringToLong(String val) {
* @return The converted Double value. * @return The converted Double value.
*/ */
public static Double stringToDouble(String val) { 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);
}
} }


/** /**
Expand Down

0 comments on commit 0ba6ae9

Please sign in to comment.