use of com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyV3 in project rest.li by linkedin.
the class DegraderLoadBalancerTest method testStateIsNullAndCallCountIsGreaterThanZero.
@Test(groups = { "small", "back-end" })
public void testStateIsNullAndCallCountIsGreaterThanZero() throws URISyntaxException, InterruptedException {
// check for average cluster latency < max latency
// max so we don't time out from lag on testing machine
DegraderLoadBalancerStrategyV3 strategy = new DegraderLoadBalancerStrategyV3(new DegraderLoadBalancerStrategyConfig(5000), "DegraderLoadBalancerTest", null, DEGRADER_STATE_LISTENER_FACTORIES);
List<DegraderTrackerClient> clients = new ArrayList<>();
TestClock clock1 = new TestClock();
TestClock clock2 = new TestClock();
clients.add(getClient(URI.create("http://test.linkedin.com:3242/fdsaf"), clock1));
clients.add(getClient(URI.create("http://test.linkedin.com:3243/fdsaf"), clock2));
for (int i = 0; i < 1000; ++i) {
clients.get(i % 2).getCallTracker().startCall().endCall();
}
clock1.addMs(5000);
// this should trigger setting _state (state is null and count > 0) with an override
// of 0d
getTrackerClient(strategy, null, new RequestContext(), -1, clients);
for (DegraderTrackerClient client : clients) {
assertEquals(client.getDegraderControl(DEFAULT_PARTITION_ID).getOverrideDropRate(), 0d);
}
}
use of com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyV3 in project rest.li by linkedin.
the class SimpleLoadBalancerState method createNewStrategies.
private Map<String, LoadBalancerStrategy> createNewStrategies(ServiceProperties serviceProperties) {
List<String> strategyList = serviceProperties.getLoadBalancerStrategyList();
LoadBalancerStrategyFactory<? extends LoadBalancerStrategy> factory = null;
if (strategyList != null && !strategyList.isEmpty()) {
for (String strategy : strategyList) {
factory = _loadBalancerStrategyFactories.get(strategy);
if (factory != null) {
break;
}
}
}
Map<String, LoadBalancerStrategy> newStrategies = new ConcurrentHashMap<>();
if (factory == null && strategyList != null && strategyList.size() == 1 && strategyList.contains(RelativeLoadBalancerStrategy.RELATIVE_LOAD_BALANCER_STRATEGY_NAME) && !_loadBalancerStrategyFactories.containsKey(RelativeLoadBalancerStrategy.RELATIVE_LOAD_BALANCER_STRATEGY_NAME)) {
factory = _loadBalancerStrategyFactories.get(DegraderLoadBalancerStrategyV3.DEGRADER_STRATEGY_NAME);
warn(_log, "unable to find cluster or factory for ", serviceProperties, ", defaulting to ", factory);
}
if (factory == null || serviceProperties.getPrioritizedSchemes() == null || serviceProperties.getPrioritizedSchemes().isEmpty()) {
warn(_log, "unable to find cluster or factory for ", serviceProperties, ": ", factory);
} else {
List<String> schemes = serviceProperties.getPrioritizedSchemes();
for (String scheme : schemes) {
LoadBalancerStrategy strategy = factory.newLoadBalancer(serviceProperties);
newStrategies.put(scheme, strategy);
}
}
info(_log, "putting strategies ", serviceProperties.getServiceName(), ": ", newStrategies);
return newStrategies;
}
Aggregations