Search in sources :

Example 11 with LoadBalancerStrategyTestRunner

use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner 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 12 with LoadBalancerStrategyTestRunner

use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner 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 13 with LoadBalancerStrategyTestRunner

use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner 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 14 with LoadBalancerStrategyTestRunner

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

the class LoadBalancerStrategyTestRunnerBuilder method buildRelativeStrategy.

private LoadBalancerStrategyTestRunner buildRelativeStrategy() {
    if (_serviceProperties == null) {
        setRelativeLoadBalancerStrategies(new D2RelativeStrategyProperties());
    }
    _strategy = new RelativeLoadBalancerStrategyFactory(_clockedExecutor, null, new ArrayList<>(), null, _clockedExecutor).newLoadBalancer(_serviceProperties);
    _transportClients = _uris.stream().map(uri -> new MockTransportClient(_clockedExecutor, _latencyManager, _errorCountManager, uri, INTERVAL_IN_MILLIS, _currentErrorCountMap, _lastRequestCountMap, _callCountMap, _latencySumMap)).collect(Collectors.toList());
    Map<URI, TrackerClient> trackerClientMap = _transportClients.stream().map(transportClient -> {
        // If partition map is not specified, by default we only support one partition
        Map<Integer, PartitionData> partitionDataMap = _partitionDataMap.getOrDefault(transportClient.getUri(), DEFAULT_PARTITION_DATA_MAP);
        return new TrackerClientImpl(transportClient.getUri(), partitionDataMap, transportClient, _clockedExecutor, INTERVAL_IN_MILLIS, (status) -> status >= 500 && status <= 599);
    }).collect(Collectors.toMap(TrackerClient::getUri, trackerClient -> trackerClient));
    return buildInternal(trackerClientMap);
}
Also used : Arrays(java.util.Arrays) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) Callback(com.linkedin.common.callback.Callback) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) HashMap(java.util.HashMap) TransportCallback(com.linkedin.r2.transport.common.bridge.common.TransportCallback) RestResponse(com.linkedin.r2.message.rest.RestResponse) ArrayList(java.util.ArrayList) ClockedExecutor(com.linkedin.test.util.ClockedExecutor) Map(java.util.Map) DegraderConfigFactory(com.linkedin.d2.balancer.strategies.degrader.DegraderConfigFactory) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) URI(java.net.URI) HttpStatus(org.eclipse.jetty.http.HttpStatus) RelativeLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory) RestException(com.linkedin.r2.message.rest.RestException) RestRequest(com.linkedin.r2.message.rest.RestRequest) com.linkedin.d2.loadBalancerStrategyType(com.linkedin.d2.loadBalancerStrategyType) Set(java.util.Set) DegraderTrackerClientImpl(com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl) TrackerClientImpl(com.linkedin.d2.balancer.clients.TrackerClientImpl) PropertyKeys(com.linkedin.d2.balancer.properties.PropertyKeys) Collectors(java.util.stream.Collectors) DegraderLoadBalancerStrategyFactoryV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) TransportResponseImpl(com.linkedin.r2.transport.common.bridge.common.TransportResponseImpl) RequestContext(com.linkedin.r2.message.RequestContext) None(com.linkedin.common.util.None) RelativeStrategyPropertiesConverter(com.linkedin.d2.balancer.config.RelativeStrategyPropertiesConverter) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) RelativeLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map) DegraderTrackerClientImpl(com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl) TrackerClientImpl(com.linkedin.d2.balancer.clients.TrackerClientImpl) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties)

Example 15 with LoadBalancerStrategyTestRunner

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

the class LoadBalancerStrategyTestRunnerBuilder method buildDegraderStrategy.

private LoadBalancerStrategyTestRunner buildDegraderStrategy() {
    if (_serviceProperties == null) {
        setDegraderStrategies(new HashMap<>(), new HashMap<>());
    }
    _strategy = new DegraderLoadBalancerStrategyFactoryV3().newLoadBalancer(_serviceProperties);
    _transportClients = _uris.stream().map(uri -> new MockTransportClient(_clockedExecutor, _latencyManager, _errorCountManager, uri, INTERVAL_IN_MILLIS, _currentErrorCountMap, _lastRequestCountMap, _callCountMap, _latencySumMap)).collect(Collectors.toList());
    Map<URI, TrackerClient> trackerClientMap = _transportClients.stream().map(transportClient -> {
        // If partition map is not specified, by default we only support one partition
        Map<Integer, PartitionData> partitionDataMap = _partitionDataMap.getOrDefault(transportClient.getUri(), DEFAULT_PARTITION_DATA_MAP);
        return new DegraderTrackerClientImpl(transportClient.getUri(), partitionDataMap, transportClient, _clockedExecutor, DegraderConfigFactory.toDegraderConfig(_serviceProperties.getDegraderProperties()));
    }).collect(Collectors.toMap(TrackerClient::getUri, trackerClient -> trackerClient));
    return buildInternal(trackerClientMap);
}
Also used : Arrays(java.util.Arrays) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) Callback(com.linkedin.common.callback.Callback) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) HashMap(java.util.HashMap) TransportCallback(com.linkedin.r2.transport.common.bridge.common.TransportCallback) RestResponse(com.linkedin.r2.message.rest.RestResponse) ArrayList(java.util.ArrayList) ClockedExecutor(com.linkedin.test.util.ClockedExecutor) Map(java.util.Map) DegraderConfigFactory(com.linkedin.d2.balancer.strategies.degrader.DegraderConfigFactory) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) URI(java.net.URI) HttpStatus(org.eclipse.jetty.http.HttpStatus) RelativeLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory) RestException(com.linkedin.r2.message.rest.RestException) RestRequest(com.linkedin.r2.message.rest.RestRequest) com.linkedin.d2.loadBalancerStrategyType(com.linkedin.d2.loadBalancerStrategyType) Set(java.util.Set) DegraderTrackerClientImpl(com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl) TrackerClientImpl(com.linkedin.d2.balancer.clients.TrackerClientImpl) PropertyKeys(com.linkedin.d2.balancer.properties.PropertyKeys) Collectors(java.util.stream.Collectors) DegraderLoadBalancerStrategyFactoryV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) TransportResponseImpl(com.linkedin.r2.transport.common.bridge.common.TransportResponseImpl) RequestContext(com.linkedin.r2.message.RequestContext) None(com.linkedin.common.util.None) RelativeStrategyPropertiesConverter(com.linkedin.d2.balancer.config.RelativeStrategyPropertiesConverter) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) DegraderLoadBalancerStrategyFactoryV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3) DegraderTrackerClientImpl(com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map)

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