Search in sources :

Example 6 with D2RelativeStrategyProperties

use of com.linkedin.d2.D2RelativeStrategyProperties 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 D2RelativeStrategyProperties

use of com.linkedin.d2.D2RelativeStrategyProperties 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 D2RelativeStrategyProperties

use of com.linkedin.d2.D2RelativeStrategyProperties 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 D2RelativeStrategyProperties

use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.

the class RelativeLoadBalancerStrategyFactory method getRequestHashFunction.

private HashFunction<Request> getRequestHashFunction(D2RelativeStrategyProperties relativeStrategyProperties) {
    if (relativeStrategyProperties.hasRingProperties() && relativeStrategyProperties.getRingProperties().hasHashConfig()) {
        HashMethod hashMethod = relativeStrategyProperties.getRingProperties().getHashMethod();
        HashConfig hashConfig = relativeStrategyProperties.getRingProperties().getHashConfig();
        switch(hashMethod) {
            case URI_REGEX:
                return new URIRegexHash(RelativeStrategyPropertiesConverter.toHashConfigMap(hashConfig));
            case RANDOM:
            default:
                return new RandomHash();
        }
    }
    // Fall back to RandomHash if not specified
    return new RandomHash();
}
Also used : HashMethod(com.linkedin.d2.HashMethod) URIRegexHash(com.linkedin.d2.balancer.util.hashing.URIRegexHash) RandomHash(com.linkedin.d2.balancer.util.hashing.RandomHash) HashConfig(com.linkedin.d2.HashConfig)

Example 10 with D2RelativeStrategyProperties

use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.

the class RelativeStrategyPropertiesConverterTest method testRelativeStrategyPropertiesConverter.

@Test
public void testRelativeStrategyPropertiesConverter() {
    double upStep = 0.2;
    double downStep = 0.1;
    double relativeLatencyHighThresholdFactor = 1.5;
    double relativeLatencyLowThresholdFactor = 1.2;
    double highErrorRate = 0.2;
    double lowErrorRate = 0.1;
    int minCallCount = 1000;
    long updateIntervalMs = 5000;
    double initialHealthScore = 0.0;
    double slowStartThreshold = 0.32;
    HttpStatusCodeRangeArray errorStatusRange = new HttpStatusCodeRangeArray(new HttpStatusCodeRange().setLowerBound(500).setUpperBound(599));
    int emittingIntervalMs = 5000;
    double quarantineMaxPercent = 0.1;
    HttpMethod quarantineMethod = HttpMethod.OPTIONS;
    String healthCheckPath = "";
    int pointsPerWeight = 100;
    HashMethod hashMethod = HashMethod.URI_REGEX;
    StringArray regexes = new StringArray("+231{w+)");
    boolean failOnNoMatch = false;
    boolean warnOnNoMatch = true;
    double hashringPointCleanupRate = 0.2;
    ConsistentHashAlgorithm consistentHashAlgorithm = ConsistentHashAlgorithm.POINT_BASED;
    int numberOfProbes = 1024;
    int numberOfPointsPerHost = 1;
    double boundedLoadBalancingFactor = 1.5;
    D2QuarantineProperties quarantineProperties = new D2QuarantineProperties().setQuarantineMaxPercent(quarantineMaxPercent).setHealthCheckMethod(quarantineMethod).setHealthCheckPath(healthCheckPath);
    HashConfig hashConfig = new HashConfig().setFailOnNoMatch(failOnNoMatch).setUriRegexes(regexes).setWarnOnNoMatch(warnOnNoMatch);
    D2RingProperties ringProperties = new D2RingProperties().setHashRingPointCleanupRate(hashringPointCleanupRate).setBoundedLoadBalancingFactor(boundedLoadBalancingFactor).setConsistentHashAlgorithm(consistentHashAlgorithm).setHashConfig(hashConfig).setHashMethod(hashMethod).setPointsPerWeight(pointsPerWeight).setNumberOfProbes(numberOfProbes).setNumberOfPointsPerHost(numberOfPointsPerHost);
    D2RelativeStrategyProperties properties = new D2RelativeStrategyProperties().setQuarantineProperties(quarantineProperties).setRingProperties(ringProperties).setUpStep(upStep).setDownStep(downStep).setRelativeLatencyHighThresholdFactor(relativeLatencyHighThresholdFactor).setRelativeLatencyLowThresholdFactor(relativeLatencyLowThresholdFactor).setHighErrorRate(highErrorRate).setLowErrorRate(lowErrorRate).setMinCallCount(minCallCount).setUpdateIntervalMs(updateIntervalMs).setInitialHealthScore(initialHealthScore).setSlowStartThreshold(slowStartThreshold).setErrorStatusFilter(errorStatusRange).setEmittingIntervalMs(emittingIntervalMs);
    Map<String, Object> propertyMap = new HashMap<>();
    Map<String, Object> ringPropertyMap = new HashMap<>();
    Map<String, Object> quarantinePropertyMap = new HashMap<>();
    Map<String, Object> hashConfigMap = new HashMap<>();
    Map<String, String> errorStatusRangeMap = new HashMap<>();
    quarantinePropertyMap.put(PropertyKeys.QUARANTINE_MAX_PERCENT, String.valueOf(quarantineMaxPercent));
    quarantinePropertyMap.put(PropertyKeys.QUARANTINE_HEALTH_CHECK_METHOD, quarantineMethod.toString());
    quarantinePropertyMap.put(PropertyKeys.QUARANTINE_HEALTH_CHECK_PATH, healthCheckPath);
    hashConfigMap.put(URIRegexHash.KEY_REGEXES, new ArrayList<>(regexes));
    hashConfigMap.put(URIRegexHash.KEY_WARN_ON_NO_MATCH, String.valueOf(warnOnNoMatch));
    hashConfigMap.put(URIRegexHash.KEY_FAIL_ON_NO_MATCH, String.valueOf(failOnNoMatch));
    ringPropertyMap.put(PropertyKeys.RING_HASH_RING_POINT_CLEANUP_RATE, String.valueOf(hashringPointCleanupRate));
    ringPropertyMap.put(PropertyKeys.RING_BOUNDED_LOAD_BALANCING_FACTOR, String.valueOf(boundedLoadBalancingFactor));
    ringPropertyMap.put(PropertyKeys.RING_CONSISTENT_HASH_ALGORITHM, DelegatingRingFactory.POINT_BASED_CONSISTENT_HASH);
    ringPropertyMap.put(PropertyKeys.RING_HASH_CONFIG, hashConfigMap);
    ringPropertyMap.put(PropertyKeys.RING_HASH_METHOD, RelativeLoadBalancerStrategy.HASH_METHOD_URI_REGEX);
    ringPropertyMap.put(PropertyKeys.RING_POINTS_PER_WEIGHT, String.valueOf(pointsPerWeight));
    ringPropertyMap.put(PropertyKeys.RING_NUMBER_OF_PROBES, String.valueOf(numberOfProbes));
    ringPropertyMap.put(PropertyKeys.RING_NUMBER_OF_POINTS_PER_HOST, String.valueOf(numberOfPointsPerHost));
    errorStatusRangeMap.put(PropertyKeys.ERROR_STATUS_UPPER_BOUND, String.valueOf(errorStatusRange.get(0).getUpperBound()));
    errorStatusRangeMap.put(PropertyKeys.ERROR_STATUS_LOWER_BOUND, String.valueOf(errorStatusRange.get(0).getLowerBound()));
    propertyMap.put(PropertyKeys.QUARANTINE_PROPERTIES, quarantinePropertyMap);
    propertyMap.put(PropertyKeys.RING_PROPERTIES, ringPropertyMap);
    propertyMap.put(PropertyKeys.UP_STEP, String.valueOf(upStep));
    propertyMap.put(PropertyKeys.DOWN_STEP, String.valueOf(downStep));
    propertyMap.put(PropertyKeys.RELATIVE_LATENCY_HIGH_THRESHOLD_FACTOR, String.valueOf(relativeLatencyHighThresholdFactor));
    propertyMap.put(PropertyKeys.RELATIVE_LATENCY_LOW_THRESHOLD_FACTOR, String.valueOf(relativeLatencyLowThresholdFactor));
    propertyMap.put(PropertyKeys.HIGH_ERROR_RATE, String.valueOf(highErrorRate));
    propertyMap.put(PropertyKeys.LOW_ERROR_RATE, String.valueOf(lowErrorRate));
    propertyMap.put(PropertyKeys.MIN_CALL_COUNT, String.valueOf(minCallCount));
    propertyMap.put(PropertyKeys.UPDATE_INTERVAL_MS, String.valueOf(updateIntervalMs));
    propertyMap.put(PropertyKeys.INITIAL_HEALTH_SCORE, String.valueOf(initialHealthScore));
    propertyMap.put(PropertyKeys.SLOW_START_THRESHOLD, String.valueOf(slowStartThreshold));
    propertyMap.put(PropertyKeys.ERROR_STATUS_FILTER, Arrays.asList(errorStatusRangeMap));
    propertyMap.put(PropertyKeys.EMITTING_INTERVAL_MS, String.valueOf(emittingIntervalMs));
    Assert.assertEquals(RelativeStrategyPropertiesConverter.toMap(properties), propertyMap);
    Assert.assertEquals(RelativeStrategyPropertiesConverter.toProperties(propertyMap), properties);
}
Also used : HashMethod(com.linkedin.d2.HashMethod) HashMap(java.util.HashMap) HttpStatusCodeRange(com.linkedin.d2.HttpStatusCodeRange) HttpStatusCodeRangeArray(com.linkedin.d2.HttpStatusCodeRangeArray) D2RingProperties(com.linkedin.d2.D2RingProperties) D2QuarantineProperties(com.linkedin.d2.D2QuarantineProperties) StringArray(com.linkedin.data.template.StringArray) ConsistentHashAlgorithm(com.linkedin.d2.ConsistentHashAlgorithm) HashConfig(com.linkedin.d2.HashConfig) HttpMethod(com.linkedin.d2.HttpMethod) 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