Search in sources :

Example 26 with LoadBalancerStrategyTestRunner

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

the class TestLoadBalancerStrategy method testRaceCondition.

@Test(dataProvider = "raceConditionScenario")
public void testRaceCondition(loadBalancerStrategyType type, int numTrackerClients) {
    Map<String, String> degraderProperties = new HashMap<>();
    degraderProperties.put(PropertyKeys.DEGRADER_INITIAL_DROP_RATE, "0.99");
    degraderProperties.put(PropertyKeys.DEGRADER_SLOW_START_THRESHOLD, "0.16");
    D2RelativeStrategyProperties relativeProperties = new D2RelativeStrategyProperties().setSlowStartThreshold(0.16).setInitialHealthScore(0.01);
    LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 10).setConstantRequestCount(30).setNumIntervals(50).setConstantLatency(Arrays.asList(HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, 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<>(), degraderProperties).build() : builder.setRelativeLoadBalancerStrategies(relativeProperties).build();
    testRunner.runWaitInconsistentTrackerClients(numTrackerClients);
    assertEquals(testRunner.getPoints().size(), 10);
    assertEquals(testRunner.getPoints().get(testRunner.getUri(0)).intValue(), 100);
}
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 27 with LoadBalancerStrategyTestRunner

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

the class TestLoadBalancerStrategy method testStayQuarantined.

@Test(dataProvider = "strategy")
public void testStayQuarantined(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(10).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(strategyPropertiesWithQuarantineEnabled, new HashMap<>()).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithQuarantineEnabled).build();
    testRunner.runWait();
    List<Integer> pointHistory = testRunner.getPointHistory().get(testRunner.getUri(0));
    assertEquals(pointHistory.get(9).intValue(), QUARANTINED_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)

Example 28 with LoadBalancerStrategyTestRunner

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

the class TestLoadBalancerStrategy method testPartitionWeightChange.

@Test(dataProvider = "strategy")
public void testPartitionWeightChange(loadBalancerStrategyType type) {
    double weight = 0.5;
    Map<Integer, PartitionData> partitionDataMap = new HashMap<>();
    partitionDataMap.put(LoadBalancerStrategyTestRunner.DEFAULT_PARTITION_ID, new PartitionData(weight));
    LoadBalancerStrategyTestRunner testRunner = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, DEFAULT_NUM_HOSTS).setConstantRequestCount(DEFAULT_REQUESTS_PER_INTERVAL).addPartitionDataMap(0, partitionDataMap).setNumIntervals(3).setConstantLatency(Arrays.asList(HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY)).build();
    testRunner.runWait();
    Map<URI, Integer> pointsMap = testRunner.getPoints();
    assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), (int) (weight * 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) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) HashMap(java.util.HashMap) LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 29 with LoadBalancerStrategyTestRunner

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

the class TestLoadBalancerPerformanceSimulation method testLinearCallCountLatencyCorrelation.

@Test(dataProvider = "latencyFactorThreshold")
public void testLinearCallCountLatencyCorrelation(double relativeLatencyLowThresholdFactor, double relativeLatencyHighThresholdFactor, int requestCountPerInterval) {
    double badHostLinearFactor = 0.1;
    double normalHostLinearFactor = 0.01;
    LoadBalancerStrategyTestRunner testRelativeRunner = buildDefaultRelativeRunnerWithLinearLatency(10, badHostLinearFactor, normalHostLinearFactor, relativeLatencyHighThresholdFactor, relativeLatencyLowThresholdFactor, requestCountPerInterval);
    testRelativeRunner.runWait();
    double relativeStrategyAverageLatency = testRelativeRunner.getAvgLatency();
    LoadBalancerStrategyTestRunner testDegraderRunner = buildDefaultDegraderRunnerWithLinearLatency(10, badHostLinearFactor, normalHostLinearFactor, requestCountPerInterval);
    testDegraderRunner.runWait();
    double degraderStrategyAverageLatency = testDegraderRunner.getAvgLatency();
    if (relativeLatencyHighThresholdFactor <= 1.2 && requestCountPerInterval >= 10000) {
        Assert.assertTrue(relativeStrategyAverageLatency < degraderStrategyAverageLatency, "With lower latency threshold and higher request number, the load balancer kicks in earlier, which gives a lower average cluster latency");
    }
}
Also used : LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) Test(org.testng.annotations.Test)

Example 30 with LoadBalancerStrategyTestRunner

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

the class TestLoadBalancerPerformanceSimulation method buildRelativeRunnerWithRandomLatencyInRange.

private LoadBalancerStrategyTestRunner buildRelativeRunnerWithRandomLatencyInRange(boolean isFastRecovery, long badHostBaseLatency, long regularBaseLatency) {
    int numHosts = 20;
    int numRequestsPerInterval = 20;
    List<LatencyCorrelation> latencyCorrelationList = new ArrayList<>();
    long leftLimit = 0L;
    long rightLimit = 400L;
    latencyCorrelationList.add((requestsPerInterval, intervalIndex) -> badHostBaseLatency + (long) (Math.random() * (rightLimit - leftLimit)));
    for (int i = 1; i < numHosts; i++) {
        latencyCorrelationList.add((requestsPerInterval, intervalIndex) -> regularBaseLatency + (long) (Math.random() * (rightLimit - leftLimit)));
    }
    D2RelativeStrategyProperties relativeStrategyProperties = new D2RelativeStrategyProperties().setEnableFastRecovery(isFastRecovery);
    return new LoadBalancerStrategyTestRunnerBuilder(loadBalancerStrategyType.RELATIVE, DEFAULT_SERVICE_NAME, numHosts).setConstantRequestCount(numRequestsPerInterval).setNumIntervals(200).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)

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