use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class StateUpdaterTest method testInitializePartitionWithSlowStartInitialHealthScore.
@Test(dataProvider = "trueFalse")
public void testInitializePartitionWithSlowStartInitialHealthScore(boolean doNotSlowStart) {
double initialHealthScore = 0.01;
D2RelativeStrategyProperties relativeStrategyProperties = new D2RelativeStrategyProperties().setInitialHealthScore(initialHealthScore);
setup(relativeStrategyProperties, new ConcurrentHashMap<>());
List<TrackerClient> trackerClients = TrackerClientMockHelper.mockTrackerClients(2, Arrays.asList(20, 20), Arrays.asList(10, 10), Arrays.asList(200L, 500L), Arrays.asList(100L, 200L), Arrays.asList(0, 0), doNotSlowStart, Arrays.asList(false, false));
assertTrue(_stateUpdater.getPointsMap(DEFAULT_PARTITION_ID).isEmpty(), "There should be no state before initialization");
_stateUpdater.updateState(new HashSet<>(trackerClients), DEFAULT_PARTITION_ID, DEFAULT_CLUSTER_GENERATION_ID, false);
if (!doNotSlowStart) {
assertEquals(_stateUpdater.getPointsMap(DEFAULT_PARTITION_ID).get(trackerClients.get(0).getUri()).intValue(), (int) (initialHealthScore * RelativeLoadBalancerStrategyFactory.DEFAULT_POINTS_PER_WEIGHT));
assertEquals(_stateUpdater.getPointsMap(DEFAULT_PARTITION_ID).get(trackerClients.get(1).getUri()).intValue(), (int) (initialHealthScore * RelativeLoadBalancerStrategyFactory.DEFAULT_POINTS_PER_WEIGHT));
} else {
assertEquals(_stateUpdater.getPointsMap(DEFAULT_PARTITION_ID).get(trackerClients.get(0).getUri()).intValue(), HEALTHY_POINTS);
assertEquals(_stateUpdater.getPointsMap(DEFAULT_PARTITION_ID).get(trackerClients.get(1).getUri()).intValue(), HEALTHY_POINTS);
}
}
use of com.linkedin.d2.D2RelativeStrategyProperties 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();
}
use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testDifferentHighLatencyFactors.
@Test(dataProvider = "highFactor", retryAnalyzer = SingleRetry.class)
public void testDifferentHighLatencyFactors(double highFactor) {
long unhealthyLatency = 800L;
long healthyLatency = 400L;
long avgLatency = (unhealthyLatency + 4 * healthyLatency) / 5;
D2RelativeStrategyProperties relativeStrategyProperties = new D2RelativeStrategyProperties().setRelativeLatencyHighThresholdFactor(highFactor);
LoadBalancerStrategyTestRunner testRunner = new LoadBalancerStrategyTestRunnerBuilder(loadBalancerStrategyType.RELATIVE, DEFAULT_SERVICE_NAME, DEFAULT_NUM_HOSTS).setConstantRequestCount(DEFAULT_REQUESTS_PER_INTERVAL).setNumIntervals(3).setConstantLatency(Arrays.asList(unhealthyLatency, healthyLatency, healthyLatency, healthyLatency, healthyLatency)).setRelativeLoadBalancerStrategies(relativeStrategyProperties).build();
testRunner.runWait();
Map<URI, Integer> pointsMap = testRunner.getPoints();
if (highFactor < (double) unhealthyLatency / avgLatency) {
assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), (int) (HEALTHY_POINTS - RelativeLoadBalancerStrategyFactory.DEFAULT_DOWN_STEP * HEALTHY_POINTS * 2));
} else {
assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), HEALTHY_POINTS);
}
}
use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testGrowingQps.
@Test(dataProvider = "strategy")
public void testGrowingQps(loadBalancerStrategyType type) {
Map<String, String> degraderPropertiesWithMinCallCount = new HashMap<>();
D2RelativeStrategyProperties relativePropertiesWithMinCallCount = new D2RelativeStrategyProperties();
// Set minCallCount to be 100
degraderPropertiesWithMinCallCount.put(PropertyKeys.DEGRADER_MIN_CALL_COUNT, "100");
relativePropertiesWithMinCallCount.setMinCallCount(100);
LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setDynamicRequestCount((intervalIndex) -> 10 + 50 * intervalIndex).setNumIntervals(50).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<>(), degraderPropertiesWithMinCallCount).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithMinCallCount).build();
testRunner.runWait();
List<Integer> pointHistory = testRunner.getPointHistory().get(testRunner.getUri(0));
int lowestPoints = getLowestPoints(pointHistory);
assertEquals(pointHistory.get(3).intValue(), HEALTHY_POINTS, "The unhealthy host still has 100 points on 4th iteration because QPS was small");
assertTrue(lowestPoints <= FULLY_DROPPED_POINTS, "The points will eventually drop");
}
use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testQuarantineRecovery.
@Test(dataProvider = "strategy")
public void testQuarantineRecovery(loadBalancerStrategyType type) {
Map<String, Object> strategyPropertiesWithQuarantineEnabled = new HashMap<>();
D2RelativeStrategyProperties relativePropertiesWithQuarantineEnabled = new D2RelativeStrategyProperties();
D2QuarantineProperties quarantineProperties = new D2QuarantineProperties().setQuarantineMaxPercent(DEFAULT_QUARANTINE_PERCENTAGE);
strategyPropertiesWithQuarantineEnabled.put(PropertyKeys.HTTP_LB_QUARANTINE_MAX_PERCENT, String.valueOf(DEFAULT_QUARANTINE_PERCENTAGE));
relativePropertiesWithQuarantineEnabled.setQuarantineProperties(quarantineProperties);
LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(1000).setNumIntervals(40).setDynamicLatency(Arrays.asList(HOST_RECOVERING_TO_HEALTHY_LATENCY, HEALTHY_HOST_LATENCY_CORRELATION, HEALTHY_HOST_LATENCY_CORRELATION, HEALTHY_HOST_LATENCY_CORRELATION, HEALTHY_HOST_LATENCY_CORRELATION));
LoadBalancerStrategyTestRunner testRunner = type == loadBalancerStrategyType.DEGRADER ? builder.setDegraderStrategies(strategyPropertiesWithQuarantineEnabled, new HashMap<>()).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithQuarantineEnabled).build();
testRunner.runWait();
List<Integer> pointHistory = testRunner.getPointHistory().get(testRunner.getUri(0));
assertEquals(getLowestPoints(pointHistory), QUARANTINED_POINTS);
assertEquals(pointHistory.get(39).intValue(), HEALTHY_POINTS);
}
Aggregations