use of com.linkedin.d2.D2RelativeStrategyProperties 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.D2RelativeStrategyProperties in project rest.li by linkedin.
the class StateUpdaterTest method testInitializePartitionWithDoNotLoadBalance.
@Test(dataProvider = "trueFalse")
public void testInitializePartitionWithDoNotLoadBalance(boolean doNotLoadBalance) {
double initialHealthScore = 0.01;
D2RelativeStrategyProperties relativeStrategyProperties = new D2RelativeStrategyProperties().setInitialHealthScore(initialHealthScore);
setup(relativeStrategyProperties, new ConcurrentHashMap<>());
List<TrackerClient> trackerClients = TrackerClientMockHelper.mockTrackerClients(2, Arrays.asList(20, 20), Arrays.asList(10, 10), Arrays.asList(200L, 500L), Arrays.asList(100L, 200L), Arrays.asList(0, 0), false, Arrays.asList(false, doNotLoadBalance));
assertTrue(_stateUpdater.getPointsMap(DEFAULT_PARTITION_ID).isEmpty(), "There should be no state before initialization");
_stateUpdater.updateState(new HashSet<>(trackerClients), DEFAULT_PARTITION_ID, DEFAULT_CLUSTER_GENERATION_ID, false);
final TrackerClient trackerClient0 = trackerClients.get(0);
final TrackerClient trackerClient1 = trackerClients.get(1);
assertTrackerClientState(DEFAULT_PARTITION_ID, trackerClient0, (int) (initialHealthScore * RelativeLoadBalancerStrategyFactory.DEFAULT_POINTS_PER_WEIGHT), false);
if (!doNotLoadBalance) {
assertTrackerClientState(DEFAULT_PARTITION_ID, trackerClient1, (int) (initialHealthScore * RelativeLoadBalancerStrategyFactory.DEFAULT_POINTS_PER_WEIGHT), false);
} else {
assertTrackerClientState(DEFAULT_PARTITION_ID, trackerClient1, HEALTHY_POINTS, false);
}
}
use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class StateUpdaterTest method testInitializePartitionWithMultipleThreads.
@Test
public void testInitializePartitionWithMultipleThreads() throws InterruptedException {
setup(new D2RelativeStrategyProperties(), new ConcurrentHashMap<>());
List<TrackerClient> trackerClients = TrackerClientMockHelper.mockTrackerClients(2, Arrays.asList(20, 20), Arrays.asList(10, 10), Arrays.asList(200L, 500L), Arrays.asList(100L, 200L), Arrays.asList(0, 0));
assertTrue(_stateUpdater.getPointsMap(DEFAULT_PARTITION_ID).isEmpty(), "There should be no state before initialization");
int numThreads = 50;
ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
CountDownLatch countDownLatch = new CountDownLatch(numThreads);
Runnable runnable = () -> {
PartitionState lastState = _stateUpdater.getPartitionState(DEFAULT_PARTITION_ID);
_stateUpdater.updateState(new HashSet<>(trackerClients), DEFAULT_PARTITION_ID, DEFAULT_CLUSTER_GENERATION_ID, false);
PartitionState currentState = _stateUpdater.getPartitionState(DEFAULT_PARTITION_ID);
if (lastState != null) {
assertEquals(currentState, lastState, "The partition state should always be the same object created by the first thread that obtained the lock");
}
};
for (int threadIndex = 0; threadIndex < numThreads; threadIndex++) {
runIndividualConcurrentTask(executorService, runnable, countDownLatch);
}
if (!countDownLatch.await(2, TimeUnit.SECONDS)) {
fail("Initialization failed to finish within 2 seconds");
}
assertEquals(_stateUpdater.getPointsMap(DEFAULT_PARTITION_ID).get(trackerClients.get(0).getUri()).intValue(), HEALTHY_POINTS);
assertEquals(_stateUpdater.getPointsMap(DEFAULT_PARTITION_ID).get(trackerClients.get(1).getUri()).intValue(), HEALTHY_POINTS);
executorService.shutdown();
}
use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class StateUpdaterTest method testUpdateMultiplePartitions.
@Test
public void testUpdateMultiplePartitions() {
/**
* There are 2 partitions, and 4 tracker clients in total.
* Partition 0 contains tracker client 1,2,3
* Partition 1 contains tracker client 3,4
* TrackerClient 3 will be unhealthy in partition 0, but not in partition 1
*/
List<TrackerClient> trackerClients1 = TrackerClientMockHelper.mockTrackerClients(3, Arrays.asList(20, 20, 20), Arrays.asList(10, 10, 10), Arrays.asList(200L, 300L, 1000L), Arrays.asList(100L, 200L, 500L), Arrays.asList(0, 0, 0));
List<TrackerClient> trackerClients2 = TrackerClientMockHelper.mockTrackerClients(1, Arrays.asList(20), Arrays.asList(10), Arrays.asList(1000L), Arrays.asList(600L), Arrays.asList(0));
trackerClients2.add(trackerClients1.get(2));
PartitionState state1 = new PartitionStateTestDataBuilder().setClusterGenerationId(DEFAULT_CLUSTER_GENERATION_ID).setTrackerClientStateMap(trackerClients1, Arrays.asList(StateUpdater.MAX_HEALTH_SCORE, StateUpdater.MAX_HEALTH_SCORE, StateUpdater.MAX_HEALTH_SCORE), Arrays.asList(TrackerClientState.HealthState.HEALTHY, TrackerClientState.HealthState.HEALTHY, TrackerClientState.HealthState.HEALTHY), Arrays.asList(30, 30, 30)).build();
PartitionState state2 = new PartitionStateTestDataBuilder().setClusterGenerationId(DEFAULT_CLUSTER_GENERATION_ID).setTrackerClientStateMap(trackerClients2, Arrays.asList(StateUpdater.MAX_HEALTH_SCORE, StateUpdater.MAX_HEALTH_SCORE), Arrays.asList(TrackerClientState.HealthState.HEALTHY, TrackerClientState.HealthState.HEALTHY), Arrays.asList(30, 30)).build();
ConcurrentMap<Integer, PartitionState> partitionLoadBalancerStateMap = new ConcurrentHashMap<>();
partitionLoadBalancerStateMap.put(0, state1);
partitionLoadBalancerStateMap.put(1, state2);
setup(new D2RelativeStrategyProperties(), partitionLoadBalancerStateMap);
_stateUpdater.updateState();
URI overlapUri = trackerClients1.get(2).getUri();
assertEquals(partitionLoadBalancerStateMap.get(0).getPointsMap().get(overlapUri).intValue(), (int) (HEALTHY_POINTS - RelativeLoadBalancerStrategyFactory.DEFAULT_DOWN_STEP * RelativeLoadBalancerStrategyFactory.DEFAULT_POINTS_PER_WEIGHT));
assertEquals(partitionLoadBalancerStateMap.get(1).getPointsMap().get(overlapUri).intValue(), HEALTHY_POINTS);
}
use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class StateUpdaterTest method testUpdateOnePartition.
@Test
public void testUpdateOnePartition() {
List<TrackerClient> trackerClients = TrackerClientMockHelper.mockTrackerClients(3, Arrays.asList(20, 20, 20), Arrays.asList(10, 10, 10), Arrays.asList(200L, 300L, 1000L), Arrays.asList(100L, 200L, 500L), Arrays.asList(0, 0, 0));
PartitionState state = new PartitionStateTestDataBuilder().setClusterGenerationId(DEFAULT_CLUSTER_GENERATION_ID).setTrackerClientStateMap(trackerClients, Arrays.asList(1.0, 1.0, 1.0), Arrays.asList(TrackerClientState.HealthState.HEALTHY, TrackerClientState.HealthState.HEALTHY, TrackerClientState.HealthState.HEALTHY), Arrays.asList(30, 30, 30)).build();
ConcurrentMap<Integer, PartitionState> partitionLoadBalancerStateMap = new ConcurrentHashMap<>();
partitionLoadBalancerStateMap.put(DEFAULT_PARTITION_ID, state);
setup(new D2RelativeStrategyProperties(), partitionLoadBalancerStateMap);
_stateUpdater.updateState();
Map<URI, Integer> pointsMap = _stateUpdater.getPointsMap(DEFAULT_PARTITION_ID);
assertEquals(pointsMap.get(trackerClients.get(0).getUri()).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(trackerClients.get(1).getUri()).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(trackerClients.get(2).getUri()).intValue(), (int) (HEALTHY_POINTS - RelativeLoadBalancerStrategyFactory.DEFAULT_DOWN_STEP * RelativeLoadBalancerStrategyFactory.DEFAULT_POINTS_PER_WEIGHT));
}
Aggregations