use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class TestLoadBalancerPerformanceSimulation method buildDefaultRelativeRunnerWithLinearLatency.
private LoadBalancerStrategyTestRunner buildDefaultRelativeRunnerWithLinearLatency(int numHosts, double badHostLinearFactor, double normalHostLinearFactor, double relativeLatencyHighThresholdFactor, double relativeLatencyLowThresholdFactor, int requestCountPerInterval) {
List<LatencyCorrelation> latencyCorrelationList = new ArrayList<>();
latencyCorrelationList.add((requestsPerInterval, intervalIndex) -> HEALTHY_LATENCY + (long) (badHostLinearFactor * requestsPerInterval));
for (int i = 0; i < numHosts - 1; i++) {
latencyCorrelationList.add((requestsPerInterval, intervalIndex) -> HEALTHY_LATENCY + (long) (normalHostLinearFactor * requestsPerInterval));
}
D2RelativeStrategyProperties relativeStrategyProperties = new D2RelativeStrategyProperties().setRelativeLatencyHighThresholdFactor(relativeLatencyHighThresholdFactor).setRelativeLatencyLowThresholdFactor(relativeLatencyLowThresholdFactor);
return new LoadBalancerStrategyTestRunnerBuilder(loadBalancerStrategyType.RELATIVE, DEFAULT_SERVICE_NAME, numHosts).setConstantRequestCount(requestCountPerInterval).setNumIntervals(100).setDynamicLatency(latencyCorrelationList).setRelativeLoadBalancerStrategies(relativeStrategyProperties).build();
}
use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class RelativeStrategyPropertiesConverter method toProperties.
/**
* Convert from map to {@link D2RelativeStrategyProperties}
*
* @param properties key-value map that defines the relative load balancer related properties
* @return The converted {@link D2RelativeStrategyProperties}
*/
@SuppressWarnings({ "unchecked" })
public static D2RelativeStrategyProperties toProperties(Map<String, Object> properties) {
D2RelativeStrategyProperties config = new D2RelativeStrategyProperties();
if (properties.containsKey(PropertyKeys.UP_STEP)) {
config.setUpStep(coerce(properties.get(PropertyKeys.UP_STEP), Double.class));
}
if (properties.containsKey(PropertyKeys.DOWN_STEP)) {
config.setDownStep(coerce(properties.get(PropertyKeys.DOWN_STEP), Double.class));
}
if (properties.containsKey(PropertyKeys.RELATIVE_LATENCY_HIGH_THRESHOLD_FACTOR)) {
config.setRelativeLatencyHighThresholdFactor(coerce(properties.get(PropertyKeys.RELATIVE_LATENCY_HIGH_THRESHOLD_FACTOR), Double.class));
}
if (properties.containsKey(PropertyKeys.RELATIVE_LATENCY_LOW_THRESHOLD_FACTOR)) {
config.setRelativeLatencyLowThresholdFactor(coerce(properties.get(PropertyKeys.RELATIVE_LATENCY_LOW_THRESHOLD_FACTOR), Double.class));
}
if (properties.containsKey(PropertyKeys.HIGH_ERROR_RATE)) {
config.setHighErrorRate(coerce(properties.get(PropertyKeys.HIGH_ERROR_RATE), Double.class));
}
if (properties.containsKey(PropertyKeys.LOW_ERROR_RATE)) {
config.setLowErrorRate(coerce(properties.get(PropertyKeys.LOW_ERROR_RATE), Double.class));
}
if (properties.containsKey(PropertyKeys.MIN_CALL_COUNT)) {
config.setMinCallCount(coerce(properties.get(PropertyKeys.MIN_CALL_COUNT), Integer.class));
}
if (properties.containsKey(PropertyKeys.UPDATE_INTERVAL_MS)) {
config.setUpdateIntervalMs(coerce(properties.get(PropertyKeys.UPDATE_INTERVAL_MS), Long.class));
}
if (properties.containsKey(PropertyKeys.INITIAL_HEALTH_SCORE)) {
config.setInitialHealthScore(coerce(properties.get(PropertyKeys.INITIAL_HEALTH_SCORE), Double.class));
}
if (properties.containsKey(PropertyKeys.SLOW_START_THRESHOLD)) {
config.setSlowStartThreshold(coerce(properties.get(PropertyKeys.SLOW_START_THRESHOLD), Double.class));
}
if (properties.containsKey(PropertyKeys.EMITTING_INTERVAL_MS)) {
config.setEmittingIntervalMs(coerce(properties.get(PropertyKeys.EMITTING_INTERVAL_MS), Long.class));
}
if (properties.containsKey(PropertyKeys.ENABLE_FAST_RECOVERY)) {
config.setEnableFastRecovery(coerce(properties.get(PropertyKeys.ENABLE_FAST_RECOVERY), Boolean.class));
}
if (properties.containsKey(PropertyKeys.ERROR_STATUS_FILTER)) {
HttpStatusCodeRangeArray array = new HttpStatusCodeRangeArray();
List<Map<String, Object>> errorStatusFilterList = (List<Map<String, Object>>) properties.get(PropertyKeys.ERROR_STATUS_FILTER);
for (Map<String, Object> errorStatusRange : errorStatusFilterList) {
HttpStatusCodeRange httpStatusCodeRange = new HttpStatusCodeRange().setUpperBound(coerce(errorStatusRange.get(PropertyKeys.ERROR_STATUS_UPPER_BOUND), Integer.class)).setLowerBound(coerce(errorStatusRange.get(PropertyKeys.ERROR_STATUS_LOWER_BOUND), Integer.class));
array.add(httpStatusCodeRange);
}
config.setErrorStatusFilter(array);
}
if (properties.containsKey(PropertyKeys.QUARANTINE_PROPERTIES)) {
config.setQuarantineProperties(toQuarantineProperties((Map<String, Object>) properties.get(PropertyKeys.QUARANTINE_PROPERTIES)));
}
if (properties.containsKey(PropertyKeys.RING_PROPERTIES)) {
config.setRingProperties(toRingProperties((Map<String, Object>) properties.get(PropertyKeys.RING_PROPERTIES)));
}
return config;
}
use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testFastRecovery.
@Test(dataProvider = "strategy")
public void testFastRecovery(loadBalancerStrategyType type) {
Map<String, Object> strategyPropertiesWithQuarantineEnabled = new HashMap<>();
D2RelativeStrategyProperties relativePropertiesWithQuarantineEnabled = new D2RelativeStrategyProperties();
strategyPropertiesWithQuarantineEnabled.put(PropertyKeys.HTTP_LB_QUARANTINE_MAX_PERCENT, String.valueOf(DEFAULT_QUARANTINE_PERCENTAGE));
strategyPropertiesWithQuarantineEnabled.put(PropertyKeys.HTTP_LB_RING_RAMP_FACTOR, "2.0");
relativePropertiesWithQuarantineEnabled.setQuarantineProperties(new D2QuarantineProperties().setQuarantineMaxPercent(DEFAULT_QUARANTINE_PERCENTAGE));
relativePropertiesWithQuarantineEnabled.setEnableFastRecovery(true);
LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(100).setNumIntervals(30).setDegraderStrategies(strategyPropertiesWithQuarantineEnabled, new HashMap<>()).setDynamicLatency(Arrays.asList(HOST_RECOVERING_TO_HEALTHY_LATENCY, HEALTHY_HOST_LATENCY_CORRELATION, HEALTHY_HOST_LATENCY_CORRELATION, HEALTHY_HOST_LATENCY_CORRELATION, HEALTHY_HOST_LATENCY_CORRELATION));
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));
assertTrue(hasPointsInHistory(pointHistory, Arrays.asList(2)), "Fast recovery should recover the points from 1 to 2 initially");
}
use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testErrorStatusMatch.
@Test(dataProvider = "strategy")
public void testErrorStatusMatch(loadBalancerStrategyType type) {
Map<String, Object> strategyPropertiesWithErrorFilter = new HashMap<>();
D2RelativeStrategyProperties relativePropertiesWithErrorFilter = new D2RelativeStrategyProperties();
// Only 503 is counted as error
strategyPropertiesWithErrorFilter.put(PropertyKeys.HTTP_LB_ERROR_STATUS_REGEX, "(503)");
relativePropertiesWithErrorFilter.setErrorStatusFilter(new HttpStatusCodeRangeArray(Arrays.asList(new HttpStatusCodeRange().setLowerBound(503).setUpperBound(503))));
LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, DEFAULT_NUM_HOSTS).setConstantRequestCount(DEFAULT_REQUESTS_PER_INTERVAL).setNumIntervals(6).setConstantLatency(Arrays.asList(HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY)).setConstantErrorCount(Arrays.asList(UNHEALTHY_ERROR_COUNT, HEALTHY_ERROR_COUNT, HEALTHY_ERROR_COUNT, HEALTHY_ERROR_COUNT, HEALTHY_ERROR_COUNT));
LoadBalancerStrategyTestRunner testRunner = type == loadBalancerStrategyType.DEGRADER ? builder.setDegraderStrategies(strategyPropertiesWithErrorFilter, new HashMap<>()).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithErrorFilter).build();
testRunner.runWait();
Map<URI, Integer> pointsMap = testRunner.getPoints();
// Event with the error 500, the host is not marked as unhealthy
assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), 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);
}
use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testLowQps.
@Test(dataProvider = "strategy")
public void testLowQps(loadBalancerStrategyType type) {
Map<String, String> degraderPropertiesWithMinCallCount = new HashMap<>();
D2RelativeStrategyProperties relativePropertiesWithMinCallCount = new D2RelativeStrategyProperties();
// Set minCallCount to be 20
degraderPropertiesWithMinCallCount.put(PropertyKeys.DEGRADER_MIN_CALL_COUNT, "20");
relativePropertiesWithMinCallCount.setMinCallCount(20);
LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(10).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(new HashMap<>(), degraderPropertiesWithMinCallCount).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithMinCallCount).build();
testRunner.runWait();
Map<URI, Integer> pointsMap = testRunner.getPoints();
assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), 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);
}
Aggregations