use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner 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.LoadBalancerStrategyTestRunner 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.LoadBalancerStrategyTestRunner 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.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class LoadBalancerStrategyTestRunnerBuilder method buildRelativeStrategy.
private LoadBalancerStrategyTestRunner buildRelativeStrategy() {
if (_serviceProperties == null) {
setRelativeLoadBalancerStrategies(new D2RelativeStrategyProperties());
}
_strategy = new RelativeLoadBalancerStrategyFactory(_clockedExecutor, null, new ArrayList<>(), null, _clockedExecutor).newLoadBalancer(_serviceProperties);
_transportClients = _uris.stream().map(uri -> new MockTransportClient(_clockedExecutor, _latencyManager, _errorCountManager, uri, INTERVAL_IN_MILLIS, _currentErrorCountMap, _lastRequestCountMap, _callCountMap, _latencySumMap)).collect(Collectors.toList());
Map<URI, TrackerClient> trackerClientMap = _transportClients.stream().map(transportClient -> {
// If partition map is not specified, by default we only support one partition
Map<Integer, PartitionData> partitionDataMap = _partitionDataMap.getOrDefault(transportClient.getUri(), DEFAULT_PARTITION_DATA_MAP);
return new TrackerClientImpl(transportClient.getUri(), partitionDataMap, transportClient, _clockedExecutor, INTERVAL_IN_MILLIS, (status) -> status >= 500 && status <= 599);
}).collect(Collectors.toMap(TrackerClient::getUri, trackerClient -> trackerClient));
return buildInternal(trackerClientMap);
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class LoadBalancerStrategyTestRunnerBuilder method buildDegraderStrategy.
private LoadBalancerStrategyTestRunner buildDegraderStrategy() {
if (_serviceProperties == null) {
setDegraderStrategies(new HashMap<>(), new HashMap<>());
}
_strategy = new DegraderLoadBalancerStrategyFactoryV3().newLoadBalancer(_serviceProperties);
_transportClients = _uris.stream().map(uri -> new MockTransportClient(_clockedExecutor, _latencyManager, _errorCountManager, uri, INTERVAL_IN_MILLIS, _currentErrorCountMap, _lastRequestCountMap, _callCountMap, _latencySumMap)).collect(Collectors.toList());
Map<URI, TrackerClient> trackerClientMap = _transportClients.stream().map(transportClient -> {
// If partition map is not specified, by default we only support one partition
Map<Integer, PartitionData> partitionDataMap = _partitionDataMap.getOrDefault(transportClient.getUri(), DEFAULT_PARTITION_DATA_MAP);
return new DegraderTrackerClientImpl(transportClient.getUri(), partitionDataMap, transportClient, _clockedExecutor, DegraderConfigFactory.toDegraderConfig(_serviceProperties.getDegraderProperties()));
}).collect(Collectors.toMap(TrackerClient::getUri, trackerClient -> trackerClient));
return buildInternal(trackerClientMap);
}
Aggregations