use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner 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.balancer.strategies.framework.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class TestLoadBalancerPerformanceSimulation method testOneConstantHigherLatencyHost.
/**
* Based on this simulation, a healthy host can be classified as unhealthy when factor = 1.2
*/
@Test(dataProvider = "relativeLatencyHighThresholdFactor")
public void testOneConstantHigherLatencyHost(double relativeLatencyHighThresholdFactor, int numHosts) {
LoadBalancerStrategyTestRunner testRunner = buildDefaultRunnerWithConstantBadHost(numHosts, HEALTHY_HIGHER_LATENCY, relativeLatencyHighThresholdFactor);
testRunner.runWait();
Map<URI, Integer> pointsMap = testRunner.getPoints();
if (relativeLatencyHighThresholdFactor <= 1.2 && numHosts >= SMALL_CLUSTER_HOST_NUM) {
assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), UNHEALTHY_POINTS);
} else {
assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), HEALTHY_POINTS);
}
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class TestLoadBalancerPerformanceSimulation method testLowQpsWithBigLatencyRange.
@Test
public void testLowQpsWithBigLatencyRange() {
long baseLatency = 100L;
LoadBalancerStrategyTestRunner testRunnerWithFastRecovery = buildRelativeRunnerWithRandomLatencyInRange(true, baseLatency, baseLatency);
testRunnerWithFastRecovery.runWait();
LoadBalancerStrategyTestRunner testRunnerWithoutFastRecovery = buildRelativeRunnerWithRandomLatencyInRange(false, baseLatency, baseLatency);
testRunnerWithoutFastRecovery.runWait();
long fullyDroppedWithFastRecovery = testRunnerWithFastRecovery.getPoints().values().stream().filter(point -> point <= UNHEALTHY_POINTS).count();
long fullyDroppedWithoutFastRecovery = testRunnerWithoutFastRecovery.getPoints().values().stream().filter(point -> point <= UNHEALTHY_POINTS).count();
assertTrue(fullyDroppedWithoutFastRecovery > 0, "Without fast recovery, when qps is low, some hosts can be fully dropped");
assertTrue(fullyDroppedWithoutFastRecovery > fullyDroppedWithFastRecovery);
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner 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.balancer.strategies.framework.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testOneHost.
@Test(dataProvider = "strategy")
public void testOneHost(loadBalancerStrategyType type) {
LoadBalancerStrategyTestRunner testRunner = new LoadBalancerStrategyTestRunnerBuilder(type, // Set to corner case - only 1 host
DEFAULT_SERVICE_NAME, 1).setConstantRequestCount(100).setNumIntervals(3).setConstantLatency(Arrays.asList(HEALTHY_HOST_CONSTANT_LATENCY)).build();
testRunner.runWait();
List<Integer> pointHistory = testRunner.getPointHistory().get(testRunner.getUri(0));
assertEquals(pointHistory.get(2).intValue(), HEALTHY_POINTS);
}
Aggregations