use of com.linkedin.d2.balancer.clients.DegraderTrackerClient in project rest.li by linkedin.
the class DegraderLoadBalancerTest method testBadTrackerClients.
@Test(groups = { "small", "back-end" })
public void testBadTrackerClients() throws URISyntaxException {
DegraderLoadBalancerStrategyV3 strategy = getStrategy();
// test null twice (first time will have no state)
for (int i = 0; i < 2; ++i) {
assertNull(getTrackerClient(strategy, null, new RequestContext(), 0, null));
}
strategy = getStrategy();
// test empty twice (first time will have no state)
for (int i = 0; i < 2; ++i) {
assertNull(getTrackerClient(strategy, null, new RequestContext(), 0, new ArrayList<>()));
}
// test same cluster generation id but different client lists
strategy = getStrategy();
List<DegraderTrackerClient> clients1 = new ArrayList<>();
SettableClock clock1 = new SettableClock();
SettableClock clock2 = new SettableClock();
List<DegraderTrackerClient> clients2 = new ArrayList<>();
SettableClock clock3 = new SettableClock();
SettableClock clock4 = new SettableClock();
clients1.add(getClient(URI.create("http://test.linkedin.com:3242/fdsaf"), clock1));
clients1.add(getClient(URI.create("http://test.linkedin.com:3243/fdsaf"), clock2));
clients2.add(getClient(URI.create("http://asdbasdf.com:3242/fdsaf"), clock3));
clients2.add(getClient(URI.create("ftp://example.com:21/what"), clock4));
// same cluster generation id but different tracker clients
assertNotNull(getTrackerClient(strategy, null, new RequestContext(), 0, clients2));
assertNull(getTrackerClient(strategy, null, new RequestContext(), 0, clients1));
// now trigger an update by cluster generation id
assertNotNull(getTrackerClient(strategy, null, new RequestContext(), 1, clients1));
assertNull(getTrackerClient(strategy, null, new RequestContext(), 1, clients2));
}
use of com.linkedin.d2.balancer.clients.DegraderTrackerClient in project rest.li by linkedin.
the class DegraderLoadBalancerTest method testLowTrafficHighLatency100Clients.
@Test(groups = { "small", "back-end" })
public void testLowTrafficHighLatency100Clients() {
Map<String, Object> myMap = lbDefaultConfig();
Long timeInterval = 5000L;
TestClock clock = new TestClock();
myMap.put(PropertyKeys.CLOCK, clock);
myMap.put(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_UPDATE_INTERVAL_MS, timeInterval);
// we need to override the min call count to 0 because we're testing a service with low traffic.
// if we don't do this, the computedDropRate will not change and we will never be able to recover
// after we degraded the cluster.
Map<String, String> degraderImplProperties = degraderDefaultConfig();
degraderImplProperties.put(PropertyKeys.DEGRADER_MIN_CALL_COUNT, "1");
degraderImplProperties.put(PropertyKeys.DEGRADER_HIGH_ERROR_RATE, "0.5");
degraderImplProperties.put(PropertyKeys.DEGRADER_LOW_ERROR_RATE, "0.2");
DegraderImpl.Config degraderConfig = DegraderConfigFactory.toDegraderConfig(degraderImplProperties);
double qps = 0.3;
// test Strategy V3
List<DegraderTrackerClient> clients = createTrackerClient(100, clock, degraderConfig);
DegraderLoadBalancerStrategyConfig config = DegraderLoadBalancerStrategyConfig.createHttpConfigFromMap(myMap);
DegraderLoadBalancerStrategyV3 strategyV3 = new DegraderLoadBalancerStrategyV3(config, "DegraderLoadBalancerTest", null, DEGRADER_STATE_LISTENER_FACTORIES);
DegraderLoadBalancerStrategyAdapter strategy = new DegraderLoadBalancerStrategyAdapter(strategyV3);
testDegraderLoadBalancerSimulator(strategy, clock, timeInterval, clients, qps, degraderConfig);
}
use of com.linkedin.d2.balancer.clients.DegraderTrackerClient in project rest.li by linkedin.
the class DegraderLoadBalancerTest method getClient.
public static DegraderTrackerClient getClient(URI uri, Clock clock) {
Map<Integer, PartitionData> partitionDataMap = new HashMap<>(2);
partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1));
return new DegraderTrackerClientImpl(uri, partitionDataMap, new TestLoadBalancerClient(uri), clock, null);
}
use of com.linkedin.d2.balancer.clients.DegraderTrackerClient in project rest.li by linkedin.
the class DegraderLoadBalancerTest method testBalancingRing.
@Test(groups = { "small", "back-end" }, dataProvider = "consistentHashAlgorithms")
public void testBalancingRing(String consistentHashAlgorithm) throws URISyntaxException {
DegraderLoadBalancerStrategyV3 strategy = getStrategy(consistentHashAlgorithm);
List<DegraderTrackerClient> clients = new ArrayList<>();
URI uri1 = URI.create("http://someTestService/someTestUrl");
URI uri2 = URI.create("http://abcxfweuoeueoueoueoukeueoueoueoueoueouo/2354");
TestClock clock1 = new TestClock();
TestClock clock2 = new TestClock();
DegraderTrackerClient client1 = getClient(uri1, clock1);
DegraderTrackerClient client2 = getClient(uri2, clock2);
clients.add(client1);
clients.add(client2);
// force client2 to be disabled
DegraderControl dcClient2Default = client2.getDegraderControl(DEFAULT_PARTITION_ID);
dcClient2Default.setOverrideMinCallCount(1);
dcClient2Default.setMinCallCount(1);
dcClient2Default.setMaxDropRate(1d);
dcClient2Default.setUpStep(0.4d);
dcClient2Default.setHighErrorRate(0);
CallCompletion cc = client2.getCallTracker().startCall();
clock2.addMs(1);
cc.endCallWithError();
clock1.addMs(15000);
clock2.addMs(5000);
// now do a basic verification to verify getTrackerClient is properly weighting things
double calls = 10000d;
int client1Count = 0;
int client2Count = 0;
double tolerance = 0.05d;
for (int i = 0; i < calls; ++i) {
TrackerClient client = getTrackerClient(strategy, null, new RequestContext(), 1, clients);
assertNotNull(client);
if (client.getUri().equals(uri1)) {
++client1Count;
} else {
++client2Count;
}
}
assertTrue(Math.abs((client1Count / calls) - (100 / 160d)) < tolerance);
assertTrue(Math.abs((client2Count / calls) - (60 / 160d)) < tolerance);
}
use of com.linkedin.d2.balancer.clients.DegraderTrackerClient in project rest.li by linkedin.
the class DegraderLoadBalancerTest method testTargetHostHeaderBindingInvalidHost.
@Test
public void testTargetHostHeaderBindingInvalidHost() {
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")));
}
RestRequestBuilder builder = new RestRequestBuilder(URI.create("d2://fooservice"));
RestRequest request = builder.build();
RequestContext context = new RequestContext();
KeyMapper.TargetHostHints.setRequestContextTargetHost(context, URI.create("http://notinclientlist.testing:9876/foobar"));
TrackerClient client = getTrackerClient(strategy, request, context, 0, clients);
Assert.assertNull(client);
}
Aggregations