use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testQuarantineHittingMaxPercentage.
@Test(dataProvider = "strategy")
public void testQuarantineHittingMaxPercentage(loadBalancerStrategyType type) {
Map<String, Object> strategyPropertiesWithQuarantineEnabled = new HashMap<>();
D2RelativeStrategyProperties relativePropertiesWithQuarantineEnabled = new D2RelativeStrategyProperties();
// Only 1/5 of the hosts can be quarantined
double quarantinePercentage = 0.2;
strategyPropertiesWithQuarantineEnabled.put(PropertyKeys.HTTP_LB_QUARANTINE_MAX_PERCENT, String.valueOf(quarantinePercentage));
D2QuarantineProperties quarantineProperties = new D2QuarantineProperties().setQuarantineMaxPercent(quarantinePercentage);
relativePropertiesWithQuarantineEnabled.setQuarantineProperties(quarantineProperties);
LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(1000).setNumIntervals(10).setConstantLatency(Arrays.asList(UNHEALTHY_HOST_CONSTANT_LATENCY, UNHEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY));
LoadBalancerStrategyTestRunner testRunner = type == loadBalancerStrategyType.DEGRADER ? builder.setDegraderStrategies(strategyPropertiesWithQuarantineEnabled, new HashMap<>()).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithQuarantineEnabled).build();
testRunner.runWait();
Map<URI, Integer> pointsMap = testRunner.getPoints();
Assert.assertTrue(pointsMap.values().contains(QUARANTINED_POINTS));
Assert.assertTrue(pointsMap.values().contains(INITIAL_RECOVERY_POINTS), "There should be host that is not quarantined but fully dropped");
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testDifferentUpDownStep.
@Test(dataProvider = "strategy")
public void testDifferentUpDownStep(loadBalancerStrategyType type) {
Map<String, String> degraderPropertiesWithUpDownStep = new HashMap<>();
D2RelativeStrategyProperties relativePropertiesWithUpDownStep = new D2RelativeStrategyProperties();
// Set up/downStep to be 0.3
double step = 0.3;
degraderPropertiesWithUpDownStep.put(PropertyKeys.DEGRADER_UP_STEP, String.valueOf(step));
degraderPropertiesWithUpDownStep.put(PropertyKeys.DEGRADER_DOWN_STEP, String.valueOf(step));
relativePropertiesWithUpDownStep.setUpStep(step);
relativePropertiesWithUpDownStep.setDownStep(step);
LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(1000).setNumIntervals(3).setConstantLatency(Arrays.asList(UNHEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY));
LoadBalancerStrategyTestRunner testRunner = type == loadBalancerStrategyType.DEGRADER ? builder.setDegraderStrategies(new HashMap<>(), degraderPropertiesWithUpDownStep).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithUpDownStep).build();
testRunner.runWait();
Map<URI, Integer> pointsMap = testRunner.getPoints();
assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), (int) (HEALTHY_POINTS - 2 * step * HEALTHY_POINTS));
assertEquals(pointsMap.get(testRunner.getUri(1)).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(testRunner.getUri(2)).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(testRunner.getUri(3)).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(testRunner.getUri(4)).intValue(), HEALTHY_POINTS);
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testSlowStartWithInitialHealthScore.
@Test(dataProvider = "strategy")
public void testSlowStartWithInitialHealthScore(loadBalancerStrategyType type) {
Map<String, String> degraderPropertiesWithSlowStart = new HashMap<>();
D2RelativeStrategyProperties relativePropertiesWithSlowStart = new D2RelativeStrategyProperties();
degraderPropertiesWithSlowStart.put(PropertyKeys.DEGRADER_INITIAL_DROP_RATE, "0.99");
degraderPropertiesWithSlowStart.put(PropertyKeys.DEGRADER_SLOW_START_THRESHOLD, "0.5");
relativePropertiesWithSlowStart.setInitialHealthScore(0.01);
relativePropertiesWithSlowStart.setSlowStartThreshold(0.5);
LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(60).setNumIntervals(30).setDegraderStrategies(new HashMap<>(), degraderPropertiesWithSlowStart).setConstantLatency(Arrays.asList(HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY));
LoadBalancerStrategyTestRunner testRunner = type == loadBalancerStrategyType.DEGRADER ? builder.setDegraderStrategies(new HashMap<>(), degraderPropertiesWithSlowStart).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithSlowStart).build();
testRunner.runWait();
List<Integer> pointHistory = testRunner.getPointHistory().get(testRunner.getUri(0));
assertTrue(hasPointsInHistory(pointHistory, Arrays.asList(1, 4, 16)));
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.
the class LoadBalancerStrategyTestRunnerBuilder method setDegraderStrategies.
public LoadBalancerStrategyTestRunnerBuilder setDegraderStrategies(Map<String, Object> strategyProperties, Map<String, String> degraderProperties) {
// Copy a new map in case the original map is immutable
Map<String, Object> strategyPropertiesCopy = new HashMap<>();
if (strategyProperties != null) {
strategyPropertiesCopy.putAll(strategyProperties);
}
strategyPropertiesCopy.put(PropertyKeys.CLOCK, _clockedExecutor);
strategyPropertiesCopy.put(PropertyKeys.HTTP_LB_QUARANTINE_EXECUTOR_SERVICE, _clockedExecutor);
Map<String, String> degraderPropertiesCopy = new HashMap<>();
if (degraderPropertiesCopy != null) {
degraderPropertiesCopy.putAll(degraderProperties);
}
_serviceProperties = new ServiceProperties(_serviceName, DEFAULT_CLUSTER_NAME, DEFAULT_PATH, DEFAULT_STRATEGY_LIST, strategyPropertiesCopy, null, degraderPropertiesCopy, null, null);
return this;
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.
the class TestLoadBalancerPerformanceSimulation method buildDefaultRunnerWithConstantBadHost.
private LoadBalancerStrategyTestRunner buildDefaultRunnerWithConstantBadHost(int numHosts, long badHostLatency, double relativeLatencyHighThresholdFactor) {
List<Long> constantLatencyList = new ArrayList<>();
constantLatencyList.add(badHostLatency);
for (int i = 0; i < numHosts - 1; i++) {
constantLatencyList.add(HEALTHY_LATENCY);
}
D2RelativeStrategyProperties relativeStrategyProperties = new D2RelativeStrategyProperties().setRelativeLatencyHighThresholdFactor(relativeLatencyHighThresholdFactor);
return new LoadBalancerStrategyTestRunnerBuilder(loadBalancerStrategyType.RELATIVE, DEFAULT_SERVICE_NAME, numHosts).setConstantRequestCount(DEFAULT_REQUESTS_PER_INTERVAL).setNumIntervals(30).setConstantLatency(constantLatencyList).setRelativeLoadBalancerStrategies(relativeStrategyProperties).build();
}
Aggregations