use of com.linkedin.d2.ConsistentHashAlgorithm in project rest.li by linkedin.
the class DegraderLoadBalancerTest method testInconsistentHashAndTrackerclients.
@Test(groups = { "small", "back-end" }, dataProvider = "consistentHashAlgorithms")
public void testInconsistentHashAndTrackerclients(String consistentHashAlgorithm) throws URISyntaxException, InterruptedException {
// check if the inconsistent Hash ring and trackerlients can be handled
TestClock clock = new TestClock();
Map<String, Object> myMap = lbDefaultConfig();
myMap.put(PropertyKeys.CLOCK, clock);
myMap.put(PropertyKeys.HTTP_LB_CONSISTENT_HASH_ALGORITHM, consistentHashAlgorithm);
DegraderLoadBalancerStrategyConfig config = DegraderLoadBalancerStrategyConfig.createHttpConfigFromMap(myMap);
DegraderLoadBalancerStrategyV3 strategy = new DegraderLoadBalancerStrategyV3(config, "DegraderLoadBalancerTest", null, DEGRADER_STATE_LISTENER_FACTORIES);
List<DegraderTrackerClient> clients = new ArrayList<>();
clients.add(getClient(URI.create("http://test.linkedin.com:3242/fdsaf"), clock));
clients.add(getClient(URI.create("http://test.linkedin.com:3243/fdsaf"), clock));
TrackerClient chosen = getTrackerClient(strategy, null, new RequestContext(), 0, clients);
assertNotNull(chosen);
// remove the client from the list, now the ring and the trackerClient list are inconsistent
clients.remove(chosen);
assertNotNull(getTrackerClient(strategy, null, new RequestContext(), 0, clients));
// update the hash ring we should get the results as well
assertNotNull(getTrackerClient(strategy, null, new RequestContext(), 1, clients));
}
use of com.linkedin.d2.ConsistentHashAlgorithm in project rest.li by linkedin.
the class LoadBalancerStrategyPropertiesConverterTest method testLoadBalancerStrategyPropertiesConverter.
@Test
public void testLoadBalancerStrategyPropertiesConverter() {
final Double globalStepDown = 0.4;
final Double globalStepUp = 0.3;
final Double recoveryLevel = 1.0;
final Double ringRampFactor = 0.01;
final Double highWaterMark = 1000d;
final Double lowWaterMark = 500d;
final Integer pointsPerWeight = 100;
final Long updateIntervalMs = 50000l;
final Integer minCallCountHighWaterMark = 3000;
final Integer minCallCountLowWaterMark = 1500;
final hashMethodEnum hashMethod = hashMethodEnum.URI_REGEX;
final hashConfigType hashConfig = new hashConfigType();
final StringArray regexes = new StringArray("+231{w+)");
final Double hashringPointCleanupRate = 0.2;
final ConsistentHashAlgorithmEnum consistentHashAlgorithm = ConsistentHashAlgorithmEnum.MULTI_PROBE;
final Integer numProbes = 1024;
final Integer numPointsPerHost = 1;
final Double quarantineMaxPercent = 0.2;
final String quarantineMethod = "OPTIONS:/test/path";
final quarantineInfo quarantineInfo = new quarantineInfo().setQuarantineMaxPercent(quarantineMaxPercent).setQuarantineMethod(quarantineMethod);
final String errorStatusRegex = "(5..)";
final Integer lowEmittingInterval = 10;
final Integer highEmittingInterval = 60;
hashConfig.setUriRegexes(regexes);
hashConfig.setWarnOnNoMatch(false);
hashConfig.setFailOnNoMatch(true);
Map<String, Object> loadBalancerStrategyProperties = new HashMap<>();
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_GLOBAL_STEP_DOWN, globalStepDown.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_GLOBAL_STEP_UP, globalStepUp.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_INITIAL_RECOVERY_LEVEL, recoveryLevel.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_RING_RAMP_FACTOR, ringRampFactor.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_HIGH_WATER_MARK, highWaterMark.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_LOW_WATER_MARK, lowWaterMark.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_POINTS_PER_WEIGHT, pointsPerWeight.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_UPDATE_INTERVAL_MS, updateIntervalMs.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_CLUSTER_MIN_CALL_COUNT_HIGH_WATER_MARK, minCallCountHighWaterMark.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_CLUSTER_MIN_CALL_COUNT_LOW_WATER_MARK, minCallCountLowWaterMark.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_HASH_METHOD, DegraderLoadBalancerStrategyV3.HASH_METHOD_URI_REGEX);
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_HASHRING_POINT_CLEANUP_RATE, hashringPointCleanupRate.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_CONSISTENT_HASH_ALGORITHM, DelegatingRingFactory.MULTI_PROBE_CONSISTENT_HASH);
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_CONSISTENT_HASH_NUM_PROBES, numProbes.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_CONSISTENT_HASH_POINTS_PER_HOST, numPointsPerHost.toString());
Map<String, Object> hashConfigMap = new HashMap<>();
hashConfigMap.put(URIRegexHash.KEY_REGEXES, new ArrayList<>(regexes));
hashConfigMap.put(URIRegexHash.KEY_WARN_ON_NO_MATCH, "false");
hashConfigMap.put(URIRegexHash.KEY_FAIL_ON_NO_MATCH, "true");
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_HASH_CONFIG, hashConfigMap);
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_QUARANTINE_MAX_PERCENT, quarantineMaxPercent.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_QUARANTINE_METHOD, quarantineMethod);
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_ERROR_STATUS_REGEX, errorStatusRegex);
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_LOW_EVENT_EMITTING_INTERVAL, lowEmittingInterval.toString());
loadBalancerStrategyProperties.put(PropertyKeys.HTTP_LB_HIGH_EVENT_EMITTING_INTERVAL, highEmittingInterval.toString());
D2LoadBalancerStrategyProperties d2LoadBalancerStrategyProperties = new D2LoadBalancerStrategyProperties().setGlobalStepDown(globalStepDown).setGlobalStepUp(globalStepUp).setInitialRecoveryLevel(recoveryLevel).setRingRampFactor(ringRampFactor).setHighWaterMark(highWaterMark).setLowWaterMark(lowWaterMark).setPointsPerWeight(pointsPerWeight).setUpdateIntervalMs(updateIntervalMs).setMinCallCountHighWaterMark(minCallCountHighWaterMark).setMinCallCountLowWaterMark(minCallCountLowWaterMark).setHashMethod(hashMethod).setHashConfig(hashConfig).setHashRingPointCleanupRate(hashringPointCleanupRate).setConsistentHashAlgorithm(consistentHashAlgorithm).setNumberOfProbes(numProbes).setNumberOfPointsPerHost(numPointsPerHost).setQuarantineCfg(quarantineInfo).setErrorStatusRegex(errorStatusRegex).setLowEmittingInterval(lowEmittingInterval).setHighEmittingInterval(highEmittingInterval);
Assert.assertEquals(LoadBalancerStrategyPropertiesConverter.toConfig(loadBalancerStrategyProperties), d2LoadBalancerStrategyProperties);
Assert.assertEquals(LoadBalancerStrategyPropertiesConverter.toProperties(d2LoadBalancerStrategyProperties), loadBalancerStrategyProperties);
}
use of com.linkedin.d2.ConsistentHashAlgorithm 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);
}
use of com.linkedin.d2.ConsistentHashAlgorithm in project rest.li by linkedin.
the class ServicePropertiesSerializerTest method createRelativeStrategyProperties.
private D2RelativeStrategyProperties createRelativeStrategyProperties() {
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));
double quarantineMaxPercent = 0.1;
HttpMethod quarantineMethod = HttpMethod.OPTIONS;
String healthCheckPath = "";
ConsistentHashAlgorithm consistentHashAlgorithm = ConsistentHashAlgorithm.POINT_BASED;
D2QuarantineProperties quarantineProperties = new D2QuarantineProperties().setQuarantineMaxPercent(quarantineMaxPercent).setHealthCheckMethod(quarantineMethod).setHealthCheckPath(healthCheckPath);
D2RingProperties ringProperties = new D2RingProperties().setConsistentHashAlgorithm(consistentHashAlgorithm);
return 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);
}
use of com.linkedin.d2.ConsistentHashAlgorithm in project rest.li by linkedin.
the class DegraderLoadBalancerTest method TestRandomIncreaseReduceTrackerClients.
@Test(groups = { "small", "back-end" }, dataProvider = "consistentHashAlgorithms")
public void TestRandomIncreaseReduceTrackerClients(String consistentHashAlgorithm) {
final DegraderLoadBalancerStrategyV3 strategy = getStrategy(consistentHashAlgorithm);
TestClock testClock = new TestClock();
String baseUri = "http://linkedin.com:9999";
int numberOfClients = 100;
int loopNumber = 100;
Map<String, String> degraderProperties = new HashMap<>();
degraderProperties.put(PropertyKeys.DEGRADER_HIGH_ERROR_RATE, "0.5");
degraderProperties.put(PropertyKeys.DEGRADER_LOW_ERROR_RATE, "0.2");
DegraderImpl.Config degraderConfig = DegraderConfigFactory.toDegraderConfig(degraderProperties);
Random random = new Random();
final List<DegraderTrackerClient> clients = new ArrayList<>();
random.setSeed(123456789L);
for (int i = 0; i < loopNumber; ++i) {
int currentSize = clients.size();
if (currentSize > numberOfClients) {
// need to remove some clients
clients.subList(numberOfClients, currentSize).clear();
} else {
// add more clients
for (int j = currentSize; j < numberOfClients; j++) {
URI uri = URI.create(baseUri + j);
DegraderTrackerClient client = new DegraderTrackerClientImpl(uri, getDefaultPartitionData(1, 1), new TestLoadBalancerClient(uri), testClock, degraderConfig);
clients.add(client);
}
}
TrackerClient client = strategy.getTrackerClient(null, new RequestContext(), i, DefaultPartitionAccessor.DEFAULT_PARTITION_ID, toMap(clients));
assertNotNull(client);
// update the client number
if (random.nextBoolean()) {
numberOfClients += random.nextInt(numberOfClients / 5);
} else {
numberOfClients -= random.nextInt(numberOfClients / 5);
}
}
}
Aggregations