use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class TestLoadBalancerPerformanceSimulation method buildDefaultRelativeRunnerWithLinearLatency.
private LoadBalancerStrategyTestRunner buildDefaultRelativeRunnerWithLinearLatency(int numHosts, double badHostLinearFactor, double normalHostLinearFactor, double relativeLatencyHighThresholdFactor, double relativeLatencyLowThresholdFactor, int requestCountPerInterval) {
List<LatencyCorrelation> latencyCorrelationList = new ArrayList<>();
latencyCorrelationList.add((requestsPerInterval, intervalIndex) -> HEALTHY_LATENCY + (long) (badHostLinearFactor * requestsPerInterval));
for (int i = 0; i < numHosts - 1; i++) {
latencyCorrelationList.add((requestsPerInterval, intervalIndex) -> HEALTHY_LATENCY + (long) (normalHostLinearFactor * requestsPerInterval));
}
D2RelativeStrategyProperties relativeStrategyProperties = new D2RelativeStrategyProperties().setRelativeLatencyHighThresholdFactor(relativeLatencyHighThresholdFactor).setRelativeLatencyLowThresholdFactor(relativeLatencyLowThresholdFactor);
return new LoadBalancerStrategyTestRunnerBuilder(loadBalancerStrategyType.RELATIVE, DEFAULT_SERVICE_NAME, numHosts).setConstantRequestCount(requestCountPerInterval).setNumIntervals(100).setDynamicLatency(latencyCorrelationList).setRelativeLoadBalancerStrategies(relativeStrategyProperties).build();
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class TestLoadBalancerPerformanceSimulation method testOneConstantSevereBadHost.
@Test(dataProvider = "relativeLatencyHighThresholdFactor")
public void testOneConstantSevereBadHost(double relativeLatencyHighThresholdFactor, int numHosts) {
LoadBalancerStrategyTestRunner testRunner = buildDefaultRunnerWithConstantBadHost(numHosts, SEVERE_BAD_LATENCY, relativeLatencyHighThresholdFactor);
testRunner.runWait();
Map<URI, Integer> pointsMap = testRunner.getPoints();
assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), UNHEALTHY_POINTS);
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class TestLoadBalancerPerformanceSimulation method testLowQpsWithOneBadHost.
@Test(dataProvider = "isFastRecovery")
public void testLowQpsWithOneBadHost(boolean isFastRecovery) {
long badHostBaseLatency = 400L;
long regularBaseLatency = 100L;
LoadBalancerStrategyTestRunner testRunner = buildRelativeRunnerWithRandomLatencyInRange(isFastRecovery, badHostBaseLatency, regularBaseLatency);
testRunner.runWait();
double badHostPointAverage = testRunner.getPointHistory().get(testRunner.getUri(0)).stream().mapToDouble(point -> point).average().getAsDouble();
double regularHostPointAverage = testRunner.getPointHistory().get(testRunner.getUri(1)).stream().mapToDouble(point -> point).average().getAsDouble();
assertTrue(badHostPointAverage <= regularHostPointAverage);
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class TestLoadBalancerPerformanceSimulation method testDifferentLatency.
/**
* Test a list of hosts that have very different latency by nature
*/
@Test
public void testDifferentLatency() {
LoadBalancerStrategyTestRunner testRelativeRunner1 = buildRelativeRunnerWithDifferentLatency(1.2);
testRelativeRunner1.runWait();
double relativeStrategyAverageLatency1 = testRelativeRunner1.getAvgLatency();
LOG.info("relativeStrategyAverageLatency: " + relativeStrategyAverageLatency1 + ", final points: " + testRelativeRunner1.getPoints());
LoadBalancerStrategyTestRunner testRelativeRunner2 = buildRelativeRunnerWithDifferentLatency(1.3);
testRelativeRunner2.runWait();
double relativeStrategyAverageLatency2 = testRelativeRunner2.getAvgLatency();
LOG.info("relativeStrategyAverageLatency: " + relativeStrategyAverageLatency2 + ", final points: " + testRelativeRunner2.getPoints());
LoadBalancerStrategyTestRunner testRelativeRunner3 = buildRelativeRunnerWithDifferentLatency(1.4);
testRelativeRunner3.runWait();
double relativeStrategyAverageLatency3 = testRelativeRunner3.getAvgLatency();
LOG.info("relativeStrategyAverageLatency: " + relativeStrategyAverageLatency3 + ", final points: " + testRelativeRunner3.getPoints());
/**
* With lowest latency factor, half of the hosts are marked as unhealthy, cluster has lower average latency
* With the highest latency factor, only 1 host is marked as unhealthy
*/
assertTrue(relativeStrategyAverageLatency1 < relativeStrategyAverageLatency2);
assertTrue(relativeStrategyAverageLatency2 < relativeStrategyAverageLatency3);
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class TestLoadBalancerPerformanceSimulation method testHostRecoveringToModerateUnhealthy.
@Test(dataProvider = "relativeLatencyLowThresholdFactor")
public void testHostRecoveringToModerateUnhealthy(double relativeLatencyLowThresholdFactor, int numHosts) {
LoadBalancerStrategyTestRunner testRunner = buildDefaultRunnerWithRecoveringBadHost(numHosts, HOST_BECOMING_MODERATE_BAD_LATENCY, relativeLatencyLowThresholdFactor);
testRunner.runWait();
Map<URI, Integer> pointsMap = testRunner.getPoints();
assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), UNHEALTHY_POINTS);
}
Aggregations