use of com.linkedin.d2.balancer.clients.DegraderTrackerClient in project rest.li by linkedin.
the class DegraderLoadBalancerTest method createTrackerClient.
/**
* create multiple trackerClients using the same clock
* @return
*/
private List<DegraderTrackerClient> createTrackerClient(int n, TestClock clock, DegraderImpl.Config config) {
String baseUri = "http://test.linkedin.com:10010/abc";
List<DegraderTrackerClient> result = new LinkedList<>();
for (int i = 0; i < n; i++) {
URI uri = URI.create(baseUri + i);
DegraderTrackerClient client = new DegraderTrackerClientImpl(uri, getDefaultPartitionData(1d), new TestLoadBalancerClient(uri), clock, config);
result.add(client);
}
return result;
}
use of com.linkedin.d2.balancer.clients.DegraderTrackerClient in project rest.li by linkedin.
the class DegraderLoadBalancerTest method testLoadBalancerCallDroppingMode.
/**
* Tests that overrideDropRate is affected by the minCallCount. If we don't have enough calls
* then it shouldn't affect cluster drop rate. There are many other pathways that we want to test here.
*/
@Test(groups = { "small", "back-end" })
public void testLoadBalancerCallDroppingMode() {
Map<String, Object> myMap = lbDefaultConfig();
Long timeInterval = 5000L;
double highWaterMark = 1000;
double lowWaterMark = 500;
long minCallHighWaterMark = 50l;
long minCallLowWaterMark = 20l;
TestClock clock = new TestClock();
myMap.put(PropertyKeys.CLOCK, clock);
myMap.put(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_UPDATE_INTERVAL_MS, timeInterval);
myMap.put(PropertyKeys.HTTP_LB_HIGH_WATER_MARK, highWaterMark);
myMap.put(PropertyKeys.HTTP_LB_LOW_WATER_MARK, lowWaterMark);
myMap.put(PropertyKeys.HTTP_LB_CLUSTER_MIN_CALL_COUNT_HIGH_WATER_MARK, minCallHighWaterMark);
myMap.put(PropertyKeys.HTTP_LB_CLUSTER_MIN_CALL_COUNT_LOW_WATER_MARK, minCallLowWaterMark);
DegraderLoadBalancerStrategyConfig config = DegraderLoadBalancerStrategyConfig.createHttpConfigFromMap(myMap);
// test strategy v3
DegraderLoadBalancerStrategyAdapter strategyAdapter = new DegraderLoadBalancerStrategyAdapter(new DegraderLoadBalancerStrategyV3(config, "DegraderLoadBalancerTest", null, DEGRADER_STATE_LISTENER_FACTORIES));
final List<DegraderTrackerClient> clients = createTrackerClient(3, clock, null);
testCallDroppingHelper(strategyAdapter, clients, clock, timeInterval);
}
use of com.linkedin.d2.balancer.clients.DegraderTrackerClient in project rest.li by linkedin.
the class DegraderLoadBalancerTest method getTrackerClientMetrics.
private static Map<DegraderTrackerClient, TrackerClientMetrics> getTrackerClientMetrics(List<DegraderTrackerClient> clients) {
Map<DegraderTrackerClient, TrackerClientMetrics> map = new HashMap<>();
for (DegraderTrackerClient 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.DegraderTrackerClient in project rest.li by linkedin.
the class DegraderLoadBalancerTest method testOverrideClusterDropRate.
@Test(groups = { "small", "back-end" })
public void testOverrideClusterDropRate() throws URISyntaxException {
DegraderLoadBalancerStrategyV3 strategy = getStrategy();
List<DegraderTrackerClient> clients = new ArrayList<>();
List<DegraderTrackerClientUpdater> clientUpdaters = new ArrayList<>();
for (DegraderTrackerClient client : clients) {
clientUpdaters.add(new DegraderTrackerClientUpdater(client, DEFAULT_PARTITION_ID));
}
clients.add(getClient(URI.create("http://test.linkedin.com:3242/fdsaf")));
clients.add(getClient(URI.create("http://test.linkedin.com:3243/fdsaf")));
DegraderLoadBalancerStrategyV3.overrideClusterDropRate(DEFAULT_PARTITION_ID, 1d, clientUpdaters);
for (DegraderTrackerClientUpdater clientUpdater : clientUpdaters) {
DegraderTrackerClient client = clientUpdater.getTrackerClient();
clientUpdater.update();
assertEquals(client.getDegraderControl(DEFAULT_PARTITION_ID).getOverrideDropRate(), 1d);
assertTrue(client.getDegrader(DEFAULT_PARTITION_ID).checkDrop());
}
DegraderLoadBalancerStrategyV3.overrideClusterDropRate(DEFAULT_PARTITION_ID, -1d, clientUpdaters);
// if we don't override, the degrader isn't degraded, so should not drop
for (DegraderTrackerClientUpdater clientUpdater : clientUpdaters) {
DegraderTrackerClient client = clientUpdater.getTrackerClient();
clientUpdater.update();
assertEquals(client.getDegraderControl(DEFAULT_PARTITION_ID).getOverrideDropRate(), -1d);
assertFalse(client.getDegrader(DEFAULT_PARTITION_ID).checkDrop());
}
DegraderLoadBalancerStrategyV3.overrideClusterDropRate(DEFAULT_PARTITION_ID, 0d, clientUpdaters);
for (DegraderTrackerClientUpdater clientUpdater : clientUpdaters) {
DegraderTrackerClient client = clientUpdater.getTrackerClient();
clientUpdater.update();
assertEquals(client.getDegraderControl(DEFAULT_PARTITION_ID).getOverrideDropRate(), 0d);
assertFalse(client.getDegrader(DEFAULT_PARTITION_ID).checkDrop());
}
}
use of com.linkedin.d2.balancer.clients.DegraderTrackerClient in project rest.li by linkedin.
the class DegraderLoadBalancerTest method testTargetHostHeaderBinding.
@Test
public void testTargetHostHeaderBinding() {
final int NUM_SERVERS = 10;
DegraderLoadBalancerStrategyV3 strategy = getStrategy();
List<DegraderTrackerClient> clients = new ArrayList<>(NUM_SERVERS);
for (int ii = 0; ii < NUM_SERVERS; ++ii) {
clients.add(getClient(URI.create("http://server" + ii + ".testing:9876/foobar")));
}
Map<TrackerClient, Integer> serverCounts = new HashMap<>();
RestRequestBuilder builder = new RestRequestBuilder(URI.create("d2://fooservice"));
final int NUM_REQUESTS = 100;
for (int ii = 0; ii < NUM_REQUESTS; ++ii) {
TrackerClient client = getTrackerClient(strategy, builder.build(), new RequestContext(), 0, clients);
Integer count = serverCounts.get(client);
if (count == null) {
count = 0;
}
serverCounts.put(client, count + 1);
}
// First, check that requests are normally evenly distributed.
Assert.assertEquals(serverCounts.size(), NUM_SERVERS);
serverCounts.clear();
RestRequest request = builder.build();
RequestContext context = new RequestContext();
KeyMapper.TargetHostHints.setRequestContextTargetHost(context, clients.get(0).getUri());
for (int ii = 0; ii < NUM_REQUESTS; ++ii) {
TrackerClient client = getTrackerClient(strategy, request, context, 0, clients);
Integer count = serverCounts.get(client);
if (count == null) {
count = 0;
}
serverCounts.put(client, count + 1);
}
Assert.assertEquals(serverCounts.size(), 1);
Assert.assertEquals(serverCounts.keySet().iterator().next(), clients.get(0));
}
Aggregations