Search in sources :

Example 1 with LoadBalancerStrategyTestRunner

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();
}
Also used : LatencyCorrelation(com.linkedin.d2.balancer.strategies.framework.LatencyCorrelation) LoadBalancerStrategyTestRunnerBuilder(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder) ArrayList(java.util.ArrayList) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties)

Example 2 with LoadBalancerStrategyTestRunner

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);
}
Also used : LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 3 with LoadBalancerStrategyTestRunner

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);
}
Also used : LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) Test(org.testng.annotations.Test)

Example 4 with LoadBalancerStrategyTestRunner

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);
}
Also used : LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) Test(org.testng.annotations.Test)

Example 5 with LoadBalancerStrategyTestRunner

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);
}
Also used : LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

LoadBalancerStrategyTestRunner (com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner)27 Test (org.testng.annotations.Test)27 LoadBalancerStrategyTestRunnerBuilder (com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder)23 D2RelativeStrategyProperties (com.linkedin.d2.D2RelativeStrategyProperties)20 URI (java.net.URI)18 HashMap (java.util.HashMap)16 ArrayList (java.util.ArrayList)8 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)5 LatencyCorrelation (com.linkedin.d2.balancer.strategies.framework.LatencyCorrelation)5 D2QuarantineProperties (com.linkedin.d2.D2QuarantineProperties)4 com.linkedin.d2.loadBalancerStrategyType (com.linkedin.d2.loadBalancerStrategyType)3 List (java.util.List)3 Map (java.util.Map)3 Callback (com.linkedin.common.callback.Callback)2 None (com.linkedin.common.util.None)2 DegraderTrackerClientImpl (com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl)2 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)2 TrackerClientImpl (com.linkedin.d2.balancer.clients.TrackerClientImpl)2 RelativeStrategyPropertiesConverter (com.linkedin.d2.balancer.config.RelativeStrategyPropertiesConverter)2 PropertyKeys (com.linkedin.d2.balancer.properties.PropertyKeys)2