Search in sources :

Example 26 with D2RelativeStrategyProperties

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

Example 27 with D2RelativeStrategyProperties

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

Example 28 with D2RelativeStrategyProperties

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);
    }
}
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 29 with D2RelativeStrategyProperties

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

Example 30 with D2RelativeStrategyProperties

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

Aggregations

D2RelativeStrategyProperties (com.linkedin.d2.D2RelativeStrategyProperties)37 Test (org.testng.annotations.Test)27 LoadBalancerStrategyTestRunnerBuilder (com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder)17 HashMap (java.util.HashMap)15 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)13 LoadBalancerStrategyTestRunner (com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner)12 URI (java.net.URI)11 ArrayList (java.util.ArrayList)9 D2QuarantineProperties (com.linkedin.d2.D2QuarantineProperties)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 HttpStatusCodeRange (com.linkedin.d2.HttpStatusCodeRange)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 D2RingProperties (com.linkedin.d2.D2RingProperties)4 HttpStatusCodeRangeArray (com.linkedin.d2.HttpStatusCodeRangeArray)4 LatencyCorrelation (com.linkedin.d2.balancer.strategies.framework.LatencyCorrelation)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Map (java.util.Map)3 ConsistentHashAlgorithm (com.linkedin.d2.ConsistentHashAlgorithm)2 HashConfig (com.linkedin.d2.HashConfig)2 HashMethod (com.linkedin.d2.HashMethod)2