Search in sources :

Example 16 with LoadBalancerStrategyTestRunner

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

Example 17 with LoadBalancerStrategyTestRunner

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

Example 18 with LoadBalancerStrategyTestRunner

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);
}
Also used : com.linkedin.d2.loadBalancerStrategyType(com.linkedin.d2.loadBalancerStrategyType) Logger(org.slf4j.Logger) DataProvider(org.testng.annotations.DataProvider) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties) LoggerFactory(org.slf4j.LoggerFactory) LoadBalancerStrategyTestRunnerBuilder(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) LatencyCorrelation(com.linkedin.d2.balancer.strategies.framework.LatencyCorrelation) ArrayList(java.util.ArrayList) List(java.util.List) Assert(org.testng.Assert) Map(java.util.Map) Assert.assertTrue(org.testng.Assert.assertTrue) URI(java.net.URI) LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) Test(org.testng.annotations.Test)

Example 19 with LoadBalancerStrategyTestRunner

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

Example 20 with LoadBalancerStrategyTestRunner

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