Search in sources :

Example 36 with D2RelativeStrategyProperties

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

the class TestLoadBalancerPerformanceSimulation method buildDefaultRunnerWithRecoveringBadHost.

private LoadBalancerStrategyTestRunner buildDefaultRunnerWithRecoveringBadHost(int numHosts, LatencyCorrelation recoveringHostLatencyCorrelation, double relativeLatencyLowThresholdFactor) {
    List<LatencyCorrelation> latencyCorrelationList = new ArrayList<>();
    latencyCorrelationList.add(recoveringHostLatencyCorrelation);
    for (int i = 0; i < numHosts - 1; i++) {
        latencyCorrelationList.add(HEALTHY_HOST_LATENCY_CORRELATION);
    }
    D2RelativeStrategyProperties relativeStrategyProperties = new D2RelativeStrategyProperties().setRelativeLatencyLowThresholdFactor(relativeLatencyLowThresholdFactor).setRelativeLatencyHighThresholdFactor(1.5);
    return new LoadBalancerStrategyTestRunnerBuilder(loadBalancerStrategyType.RELATIVE, DEFAULT_SERVICE_NAME, numHosts).setConstantRequestCount(DEFAULT_REQUESTS_PER_INTERVAL).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)

Example 37 with D2RelativeStrategyProperties

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

the class RelativeLoadBalancerStrategyFactory method putDefaultValues.

static D2RelativeStrategyProperties putDefaultValues(D2RelativeStrategyProperties properties) {
    properties.setUpStep(getOrDefault(properties.getUpStep(), DEFAULT_UP_STEP));
    properties.setDownStep(getOrDefault(properties.getDownStep(), DEFAULT_DOWN_STEP));
    properties.setHighErrorRate(getOrDefault(properties.getHighErrorRate(), DEFAULT_HIGH_ERROR_RATE));
    properties.setLowErrorRate(getOrDefault(properties.getLowErrorRate(), DEFAULT_LOW_ERROR_RATE));
    properties.setRelativeLatencyHighThresholdFactor(getOrDefault(properties.getRelativeLatencyHighThresholdFactor(), DEFAULT_RELATIVE_LATENCY_HIGH_THRESHOLD_FACTOR));
    properties.setRelativeLatencyLowThresholdFactor(getOrDefault(properties.getRelativeLatencyLowThresholdFactor(), DEFAULT_RELATIVE_LATENCY_LOW_THRESHOLD_FACTOR));
    properties.setMinCallCount(getOrDefault(properties.getMinCallCount(), DEFAULT_MIN_CALL_COUNT));
    properties.setUpdateIntervalMs(getOrDefault(properties.getUpdateIntervalMs(), DEFAULT_UPDATE_INTERVAL_MS));
    properties.setInitialHealthScore(getOrDefault(properties.getInitialHealthScore(), DEFAULT_INITIAL_HEALTH_SCORE));
    properties.setSlowStartThreshold(getOrDefault(properties.getSlowStartThreshold(), DEFAULT_SLOW_START_THRESHOLD));
    properties.setErrorStatusFilter(getOrDefault(properties.getErrorStatusFilter(), DEFAULT_ERROR_STATUS_FILTER));
    properties.setEmittingIntervalMs(getOrDefault(properties.getEmittingIntervalMs(), DEFAULT_EMITTING_INTERVAL_MS));
    properties.setEnableFastRecovery(getOrDefault(properties.isEnableFastRecovery(), DEFAULT_ENABLE_FAST_RECOVERY));
    D2QuarantineProperties quarantineProperties = properties.hasQuarantineProperties() ? properties.getQuarantineProperties() : new D2QuarantineProperties();
    quarantineProperties.setQuarantineMaxPercent(getOrDefault(quarantineProperties.getQuarantineMaxPercent(), DEFAULT_QUARANTINE_MAX_PERCENT));
    quarantineProperties.setHealthCheckMethod(getOrDefault(quarantineProperties.getHealthCheckMethod(), DEFAULT_HTTP_METHOD));
    properties.setQuarantineProperties(quarantineProperties);
    // Most ring properties are initialized in {@link DelegatingRingFactory}
    D2RingProperties ringProperties = properties.hasRingProperties() ? properties.getRingProperties() : new D2RingProperties();
    ringProperties.setPointsPerWeight(getOrDefault(ringProperties.getPointsPerWeight(), DEFAULT_POINTS_PER_WEIGHT));
    properties.setRingProperties(ringProperties);
    return properties;
}
Also used : D2QuarantineProperties(com.linkedin.d2.D2QuarantineProperties) D2RingProperties(com.linkedin.d2.D2RingProperties)

Example 38 with D2RelativeStrategyProperties

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

the class RelativeLoadBalancerStrategyFactory method newLoadBalancer.

@Override
public RelativeLoadBalancerStrategy newLoadBalancer(ServiceProperties serviceProperties) {
    D2RelativeStrategyProperties relativeStrategyProperties = RelativeStrategyPropertiesConverter.toProperties(serviceProperties.getRelativeStrategyProperties());
    relativeStrategyProperties = putDefaultValues(relativeStrategyProperties);
    return new RelativeLoadBalancerStrategy(getRelativeStateUpdater(relativeStrategyProperties, serviceProperties.getServiceName(), serviceProperties.getClusterName(), serviceProperties.getPath()), getClientSelector(relativeStrategyProperties));
}
Also used : D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties)

Example 39 with D2RelativeStrategyProperties

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

the class ServicePropertiesSerializerTest method testServicePropertiesSerializerWithRelativeStrategy.

@Test
public void testServicePropertiesSerializerWithRelativeStrategy() throws PropertySerializationException {
    ServicePropertiesJsonSerializer serializer = new ServicePropertiesJsonSerializer();
    D2RelativeStrategyProperties relativeStrategyProperties = createRelativeStrategyProperties();
    ServiceProperties property = new ServiceProperties(TEST_SERVICE_NAME, TEST_CLUSTER_NAME, "/foo", Arrays.asList("rr"), new HashMap<>(), null, null, Arrays.asList("HTTPS"), Collections.emptySet(), Collections.emptyMap(), Collections.emptyList(), RelativeStrategyPropertiesConverter.toMap(relativeStrategyProperties));
    assertEquals(serializer.fromBytes(serializer.toBytes(property)), property);
}
Also used : D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties) Test(org.testng.annotations.Test)

Example 40 with D2RelativeStrategyProperties

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

the class RelativeStrategyPropertiesConverter method toMap.

/**
 * Convert {@link D2RelativeStrategyProperties} to Map
 *
 * @param properties relative strategy properties
 * @return The converted key-value map
 */
public static Map<String, Object> toMap(D2RelativeStrategyProperties properties) {
    if (properties == null) {
        return Collections.emptyMap();
    }
    Map<String, Object> map = new HashMap<>();
    if (properties.hasUpStep()) {
        map.put(PropertyKeys.UP_STEP, properties.getUpStep().toString());
    }
    if (properties.hasDownStep()) {
        map.put(PropertyKeys.DOWN_STEP, properties.getDownStep().toString());
    }
    if (properties.hasRelativeLatencyHighThresholdFactor()) {
        map.put(PropertyKeys.RELATIVE_LATENCY_HIGH_THRESHOLD_FACTOR, properties.getRelativeLatencyHighThresholdFactor().toString());
    }
    if (properties.hasRelativeLatencyLowThresholdFactor()) {
        map.put(PropertyKeys.RELATIVE_LATENCY_LOW_THRESHOLD_FACTOR, properties.getRelativeLatencyLowThresholdFactor().toString());
    }
    if (properties.hasHighErrorRate()) {
        map.put(PropertyKeys.HIGH_ERROR_RATE, properties.getHighErrorRate().toString());
    }
    if (properties.hasLowErrorRate()) {
        map.put(PropertyKeys.LOW_ERROR_RATE, properties.getLowErrorRate().toString());
    }
    if (properties.hasMinCallCount()) {
        map.put(PropertyKeys.MIN_CALL_COUNT, properties.getMinCallCount().toString());
    }
    if (properties.hasUpdateIntervalMs()) {
        map.put(PropertyKeys.UPDATE_INTERVAL_MS, properties.getUpdateIntervalMs().toString());
    }
    if (properties.hasInitialHealthScore()) {
        map.put(PropertyKeys.INITIAL_HEALTH_SCORE, properties.getInitialHealthScore().toString());
    }
    if (properties.hasSlowStartThreshold()) {
        map.put(PropertyKeys.SLOW_START_THRESHOLD, properties.getSlowStartThreshold().toString());
    }
    if (properties.hasEmittingIntervalMs()) {
        map.put(PropertyKeys.EMITTING_INTERVAL_MS, properties.getEmittingIntervalMs().toString());
    }
    if (properties.hasEnableFastRecovery()) {
        map.put(PropertyKeys.ENABLE_FAST_RECOVERY, properties.isEnableFastRecovery().toString());
    }
    if (properties.hasErrorStatusFilter()) {
        List<Map<String, Object>> errorStatusFilterList = new ArrayList<>();
        for (HttpStatusCodeRange errorStatusRange : properties.getErrorStatusFilter()) {
            Map<String, Object> errorStatusFilterMap = new HashMap<>();
            errorStatusFilterMap.put(PropertyKeys.ERROR_STATUS_LOWER_BOUND, errorStatusRange.getLowerBound().toString());
            errorStatusFilterMap.put(PropertyKeys.ERROR_STATUS_UPPER_BOUND, errorStatusRange.getUpperBound().toString());
            errorStatusFilterList.add(errorStatusFilterMap);
        }
        map.put(PropertyKeys.ERROR_STATUS_FILTER, errorStatusFilterList);
    }
    if (properties.hasQuarantineProperties()) {
        D2QuarantineProperties quarantineProperties = properties.getQuarantineProperties();
        Map<String, Object> quarantinePropertyMap = toQuarantinePropertyMap(quarantineProperties);
        map.put(PropertyKeys.QUARANTINE_PROPERTIES, quarantinePropertyMap);
    }
    if (properties.hasRingProperties()) {
        D2RingProperties ringProperties = properties.getRingProperties();
        Map<String, Object> ringPropertyMap = toRingPropertyMap(ringProperties);
        map.put(PropertyKeys.RING_PROPERTIES, ringPropertyMap);
    }
    return map;
}
Also used : D2QuarantineProperties(com.linkedin.d2.D2QuarantineProperties) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HttpStatusCodeRange(com.linkedin.d2.HttpStatusCodeRange) D2RingProperties(com.linkedin.d2.D2RingProperties) HashMap(java.util.HashMap) Map(java.util.Map)

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