use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class DegraderLoadBalancerTest method getTrackerClientMetrics.
private static Map<TrackerClient, TrackerClientMetrics> getTrackerClientMetrics(List<TrackerClient> clients) {
Map<TrackerClient, TrackerClientMetrics> map = new HashMap<TrackerClient, TrackerClientMetrics>();
for (TrackerClient client : clients) {
DegraderControl degraderControl = client.getDegraderControl(DEFAULT_PARTITION_ID);
map.put(client, new TrackerClientMetrics(degraderControl.getOverrideDropRate(), degraderControl.getMaxDropRate(), degraderControl.getOverrideMinCallCount()));
}
return map;
}
use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class DegraderLoadBalancerTest method clusterRecovery1TC.
/**
* helper method to test DegraderLoadBalancerStrategy recovery with 1 TrackerClient.
*
* We want to test DegraderV2 and V3 with 2 different strategies : LoadBalacing and Call Dropping.
* So this method needs to able to handle all 4 permutations.
*
* @param myMap
* @param clock
* @param stepsToFullRecovery
* @param timeInterval
* @param strategy
*/
public void clusterRecovery1TC(Map<String, Object> myMap, TestClock clock, int stepsToFullRecovery, Long timeInterval, DegraderLoadBalancerStrategyAdapter strategy, DegraderLoadBalancerStrategyV2_1.DegraderLoadBalancerState.Strategy strategyV2, DegraderLoadBalancerStrategyV3.PartitionDegraderLoadBalancerState.Strategy strategyV3) {
final int NUM_CHECKS = 5;
final Long TIME_INTERVAL = timeInterval;
int localStepsToFullRecovery = stepsToFullRecovery;
DegraderLoadBalancerStrategyConfig config = DegraderLoadBalancerStrategyConfig.createHttpConfigFromMap(myMap);
List<TrackerClient> clients = new ArrayList<TrackerClient>();
URI uri1 = URI.create("http://test.linkedin.com:3242/fdsaf");
URIRequest request = new URIRequest(uri1);
TrackerClient client1 = new TrackerClient(uri1, getDefaultPartitionData(1d), new TestLoadBalancerClient(uri1), clock, null);
clients.add(client1);
// force client1 to be disabled
DegraderControl dcClient1Default = client1.getDegraderControl(DEFAULT_PARTITION_ID);
dcClient1Default.setOverrideMinCallCount(5);
dcClient1Default.setMinCallCount(5);
dcClient1Default.setMaxDropRate(1d);
dcClient1Default.setUpStep(1.0d);
List<CallCompletion> ccList = new ArrayList<CallCompletion>();
CallCompletion cc;
for (int j = 0; j < NUM_CHECKS; j++) {
cc = client1.getCallTracker().startCall();
ccList.add(cc);
}
// add high latency and errors to shut off traffic to this tracker client.
// note: the default values for highError and lowError in the degrader are 1.1,
// which means we don't use errorRates when deciding when to lb/degrade.
// In addition, because we changed to use the
clock.addMs(3500);
//for (int j = 0; j < NUM_CHECKS; j++)
for (Iterator<CallCompletion> iter = ccList.listIterator(); iter.hasNext(); ) {
cc = iter.next();
cc.endCallWithError();
iter.remove();
}
// go to next time interval.
clock.addMs(TIME_INTERVAL);
Assert.assertEquals(dcClient1Default.getCurrentComputedDropRate(), 1.0);
// trigger a state update
TrackerClient resultTC = getTrackerClient(strategy, request, new RequestContext(), 1, clients);
if (config.getInitialRecoveryLevel() < 0.01) {
//the returned TrackerClient should be null
assertNull(resultTC, "expected null trackerclient");
// tracker client, so it's time to try it out. We need to enter this code at least once.
do {
// go to next time interval.
clock.addMs(TIME_INTERVAL);
// try adjusting the hash ring on this updateState
if (strategyV3 != null) {
strategy.setStrategyV3(DEFAULT_PARTITION_ID, strategyV3);
} else if (strategyV2 != null) {
strategy.setStrategyV2(strategyV2);
} else {
fail("should set strategy (either LoadBalance or Degrader");
}
resultTC = getTrackerClient(strategy, request, new RequestContext(), 1, clients);
localStepsToFullRecovery--;
} while (localStepsToFullRecovery > 0);
}
assertNotNull(resultTC, "expected non-null trackerclient");
// make calls to the tracker client to verify that it's on the road to healthy status.
for (int j = 0; j < NUM_CHECKS; j++) {
cc = resultTC.getCallTracker().startCall();
ccList.add(cc);
}
clock.addMs(10);
for (Iterator<CallCompletion> iter = ccList.listIterator(); iter.hasNext(); ) {
cc = iter.next();
cc.endCall();
iter.remove();
}
// go to next time interval.
clock.addMs(TIME_INTERVAL);
Assert.assertTrue(dcClient1Default.getCurrentComputedDropRate() < 1d);
resultTC = getTrackerClient(strategy, request, new RequestContext(), 1, clients);
assertNotNull(resultTC, "expected non-null trackerclient");
}
use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class LoadBalancerStrategyBenchmark method createDegraderTrackerClients.
private static Map<URI, TrackerClient> createDegraderTrackerClients(int numHosts) {
Map<URI, TrackerClient> trackerClients = new HashMap<>();
for (int i = 0; i < numHosts; i++) {
URI uri = URI.create(URI_PREFIX + i + URI_SUFFIX);
trackerClients.put(uri, new DegraderTrackerClientImpl(uri, DEFAULT_PARTITION_DATA_MAP, new BaseTransportTestClient(), CLOCK, null));
}
return trackerClients;
}
use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class TrackerClientMockHelper method mockTrackerClients.
/**
* Mock a list of {@link TrackerClient} for testing
*
* @param numTrackerClients The number of {@link TrackerClient} to be mocked
* @param callCountList The call count that each host receives
* @param outstandingCallCountList The outstanding call count that each host receives
* @param latencyList The latency of each host
* @param outstandingLatencyList The outstanding latency of each host
* @param errorCountList The error count of each host
* @return A list of mocked {@link TrackerClient}
*/
public static List<TrackerClient> mockTrackerClients(int numTrackerClients, List<Integer> callCountList, List<Integer> outstandingCallCountList, List<Long> latencyList, List<Long> outstandingLatencyList, List<Integer> errorCountList, boolean doNotSlowStart, List<Boolean> doNotLoadBalance) {
List<TrackerClient> trackerClients = new ArrayList<>();
for (int index = 0; index < numTrackerClients; index++) {
URI uri = URI.create("URI/" + index);
TrackerClient trackerClient = Mockito.mock(TrackerClient.class);
CallTracker callTracker = Mockito.mock(CallTracker.class);
LongStats longStats = new LongStats(callCountList.get(index), latencyList.get(index), 0, 0, 0, 0, 0, 0, 0);
Map<ErrorType, Integer> errorTypeCounts = new HashMap<>();
errorTypeCounts.put(ErrorType.SERVER_ERROR, errorCountList.get(index));
CallTrackerImpl.CallTrackerStats callStats = new CallTrackerImpl.CallTrackerStats(RelativeLoadBalancerStrategyFactory.DEFAULT_UPDATE_INTERVAL_MS, 0, RelativeLoadBalancerStrategyFactory.DEFAULT_UPDATE_INTERVAL_MS, callCountList.get(index), 0, 0, errorCountList.get(index), errorCountList.get(index), 1, RelativeLoadBalancerStrategyFactory.DEFAULT_UPDATE_INTERVAL_MS - outstandingLatencyList.get(index), outstandingCallCountList.get(index), longStats, errorTypeCounts, errorTypeCounts);
Mockito.when(trackerClient.getCallTracker()).thenReturn(callTracker);
Mockito.when(callTracker.getCallStats()).thenReturn(callStats);
Mockito.when(trackerClient.getUri()).thenReturn(uri);
Mockito.when(trackerClient.getPartitionWeight(anyInt())).thenReturn(1.0);
Mockito.when(trackerClient.getSubsetWeight(anyInt())).thenReturn(1.0);
Mockito.when(trackerClient.doNotSlowStart()).thenReturn(doNotSlowStart);
Mockito.when(trackerClient.doNotLoadBalance()).thenReturn(doNotLoadBalance.get(index));
trackerClients.add(trackerClient);
}
return trackerClients;
}
use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class TrackerClientMockHelper method mockTrackerClients.
/**
* Mock a list of {@link TrackerClient} without call stats
*
* @param numTrackerClients The number of hosts to be mocked
* @return A list of mocked {@link TrackerClient}
*/
public static List<TrackerClient> mockTrackerClients(int numTrackerClients) {
List<TrackerClient> trackerClients = new ArrayList<>();
for (int index = 0; index < numTrackerClients; index++) {
URI uri = URI.create("URI/" + index);
TrackerClient trackerClient = Mockito.mock(TrackerClient.class);
Mockito.when(trackerClient.getCallTracker()).thenReturn(new CallTrackerImpl(RelativeLoadBalancerStrategyFactory.DEFAULT_UPDATE_INTERVAL_MS));
Mockito.when(trackerClient.getUri()).thenReturn(uri);
Mockito.when(trackerClient.getPartitionWeight(anyInt())).thenReturn(1.0);
Mockito.when(trackerClient.getSubsetWeight(anyInt())).thenReturn(1.0);
trackerClients.add(trackerClient);
}
return trackerClients;
}
Aggregations