Search in sources :

Example 6 with LoadBalancerStrategyTestRunnerBuilder

use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.

the class TestLoadBalancerStrategy method testQuarantineHittingMaxPercentage.

@Test(dataProvider = "strategy")
public void testQuarantineHittingMaxPercentage(loadBalancerStrategyType type) {
    Map<String, Object> strategyPropertiesWithQuarantineEnabled = new HashMap<>();
    D2RelativeStrategyProperties relativePropertiesWithQuarantineEnabled = new D2RelativeStrategyProperties();
    // Only 1/5 of the hosts can be quarantined
    double quarantinePercentage = 0.2;
    strategyPropertiesWithQuarantineEnabled.put(PropertyKeys.HTTP_LB_QUARANTINE_MAX_PERCENT, String.valueOf(quarantinePercentage));
    D2QuarantineProperties quarantineProperties = new D2QuarantineProperties().setQuarantineMaxPercent(quarantinePercentage);
    relativePropertiesWithQuarantineEnabled.setQuarantineProperties(quarantineProperties);
    LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(1000).setNumIntervals(10).setConstantLatency(Arrays.asList(UNHEALTHY_HOST_CONSTANT_LATENCY, UNHEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY));
    LoadBalancerStrategyTestRunner testRunner = type == loadBalancerStrategyType.DEGRADER ? builder.setDegraderStrategies(strategyPropertiesWithQuarantineEnabled, new HashMap<>()).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithQuarantineEnabled).build();
    testRunner.runWait();
    Map<URI, Integer> pointsMap = testRunner.getPoints();
    Assert.assertTrue(pointsMap.values().contains(QUARANTINED_POINTS));
    Assert.assertTrue(pointsMap.values().contains(INITIAL_RECOVERY_POINTS), "There should be host that is not quarantined but fully dropped");
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) LoadBalancerStrategyTestRunnerBuilder(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder) D2QuarantineProperties(com.linkedin.d2.D2QuarantineProperties) LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties) Test(org.testng.annotations.Test)

Example 7 with LoadBalancerStrategyTestRunnerBuilder

use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.

the class TestLoadBalancerStrategy method testDifferentUpDownStep.

@Test(dataProvider = "strategy")
public void testDifferentUpDownStep(loadBalancerStrategyType type) {
    Map<String, String> degraderPropertiesWithUpDownStep = new HashMap<>();
    D2RelativeStrategyProperties relativePropertiesWithUpDownStep = new D2RelativeStrategyProperties();
    // Set up/downStep to be 0.3
    double step = 0.3;
    degraderPropertiesWithUpDownStep.put(PropertyKeys.DEGRADER_UP_STEP, String.valueOf(step));
    degraderPropertiesWithUpDownStep.put(PropertyKeys.DEGRADER_DOWN_STEP, String.valueOf(step));
    relativePropertiesWithUpDownStep.setUpStep(step);
    relativePropertiesWithUpDownStep.setDownStep(step);
    LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(1000).setNumIntervals(3).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<>(), degraderPropertiesWithUpDownStep).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithUpDownStep).build();
    testRunner.runWait();
    Map<URI, Integer> pointsMap = testRunner.getPoints();
    assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), (int) (HEALTHY_POINTS - 2 * step * HEALTHY_POINTS));
    assertEquals(pointsMap.get(testRunner.getUri(1)).intValue(), HEALTHY_POINTS);
    assertEquals(pointsMap.get(testRunner.getUri(2)).intValue(), HEALTHY_POINTS);
    assertEquals(pointsMap.get(testRunner.getUri(3)).intValue(), HEALTHY_POINTS);
    assertEquals(pointsMap.get(testRunner.getUri(4)).intValue(), HEALTHY_POINTS);
}
Also used : LoadBalancerStrategyTestRunnerBuilder(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder) HashMap(java.util.HashMap) LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) URI(java.net.URI) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties) Test(org.testng.annotations.Test)

Example 8 with LoadBalancerStrategyTestRunnerBuilder

use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.

the class TestLoadBalancerStrategy method testSlowStartWithInitialHealthScore.

@Test(dataProvider = "strategy")
public void testSlowStartWithInitialHealthScore(loadBalancerStrategyType type) {
    Map<String, String> degraderPropertiesWithSlowStart = new HashMap<>();
    D2RelativeStrategyProperties relativePropertiesWithSlowStart = new D2RelativeStrategyProperties();
    degraderPropertiesWithSlowStart.put(PropertyKeys.DEGRADER_INITIAL_DROP_RATE, "0.99");
    degraderPropertiesWithSlowStart.put(PropertyKeys.DEGRADER_SLOW_START_THRESHOLD, "0.5");
    relativePropertiesWithSlowStart.setInitialHealthScore(0.01);
    relativePropertiesWithSlowStart.setSlowStartThreshold(0.5);
    LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(60).setNumIntervals(30).setDegraderStrategies(new HashMap<>(), degraderPropertiesWithSlowStart).setConstantLatency(Arrays.asList(HEALTHY_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<>(), degraderPropertiesWithSlowStart).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithSlowStart).build();
    testRunner.runWait();
    List<Integer> pointHistory = testRunner.getPointHistory().get(testRunner.getUri(0));
    assertTrue(hasPointsInHistory(pointHistory, Arrays.asList(1, 4, 16)));
}
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 9 with LoadBalancerStrategyTestRunnerBuilder

use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.

the class LoadBalancerStrategyTestRunnerBuilder method setDegraderStrategies.

public LoadBalancerStrategyTestRunnerBuilder setDegraderStrategies(Map<String, Object> strategyProperties, Map<String, String> degraderProperties) {
    // Copy a new map in case the original map is immutable
    Map<String, Object> strategyPropertiesCopy = new HashMap<>();
    if (strategyProperties != null) {
        strategyPropertiesCopy.putAll(strategyProperties);
    }
    strategyPropertiesCopy.put(PropertyKeys.CLOCK, _clockedExecutor);
    strategyPropertiesCopy.put(PropertyKeys.HTTP_LB_QUARANTINE_EXECUTOR_SERVICE, _clockedExecutor);
    Map<String, String> degraderPropertiesCopy = new HashMap<>();
    if (degraderPropertiesCopy != null) {
        degraderPropertiesCopy.putAll(degraderProperties);
    }
    _serviceProperties = new ServiceProperties(_serviceName, DEFAULT_CLUSTER_NAME, DEFAULT_PATH, DEFAULT_STRATEGY_LIST, strategyPropertiesCopy, null, degraderPropertiesCopy, null, null);
    return this;
}
Also used : ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) HashMap(java.util.HashMap)

Example 10 with LoadBalancerStrategyTestRunnerBuilder

use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder 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)

Aggregations

LoadBalancerStrategyTestRunnerBuilder (com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder)22 D2RelativeStrategyProperties (com.linkedin.d2.D2RelativeStrategyProperties)17 LoadBalancerStrategyTestRunner (com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner)17 Test (org.testng.annotations.Test)17 HashMap (java.util.HashMap)15 URI (java.net.URI)9 ArrayList (java.util.ArrayList)5 D2QuarantineProperties (com.linkedin.d2.D2QuarantineProperties)4 LatencyCorrelation (com.linkedin.d2.balancer.strategies.framework.LatencyCorrelation)4 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)3 HttpStatusCodeRange (com.linkedin.d2.HttpStatusCodeRange)1 HttpStatusCodeRangeArray (com.linkedin.d2.HttpStatusCodeRangeArray)1 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)1