Search in sources :

Example 56 with DegraderLoadBalancerStrategyV3

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);
    }
}
Also used : DegraderTrackerClient(com.linkedin.d2.balancer.clients.DegraderTrackerClient) ArrayList(java.util.ArrayList) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test) DegraderTrackerClientTest(com.linkedin.d2.balancer.clients.DegraderTrackerClientTest)

Example 57 with DegraderLoadBalancerStrategyV3

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;
}
Also used : RelativeLoadBalancerStrategy(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Test (org.testng.annotations.Test)49 DegraderTrackerClientTest (com.linkedin.d2.balancer.clients.DegraderTrackerClientTest)44 DegraderTrackerClient (com.linkedin.d2.balancer.clients.DegraderTrackerClient)40 ArrayList (java.util.ArrayList)35 URI (java.net.URI)27 RequestContext (com.linkedin.r2.message.RequestContext)23 HashMap (java.util.HashMap)20 AtomicLong (java.util.concurrent.atomic.AtomicLong)19 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)16 DegraderImpl (com.linkedin.util.degrader.DegraderImpl)14 DegraderTrackerClientImpl (com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl)10 CallCompletion (com.linkedin.util.degrader.CallCompletion)9 DegraderControl (com.linkedin.util.degrader.DegraderControl)9 DegraderLoadBalancerStrategyV3 (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyV3)6 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)5 URIRequest (com.linkedin.d2.balancer.util.URIRequest)5 NullStateListenerCallback (com.linkedin.d2.balancer.LoadBalancerState.NullStateListenerCallback)4 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)4 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)4 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)4