Search in sources :

Example 1 with RelativeLoadBalancerStrategy

use of com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy in project rest.li by linkedin.

the class RelativeLoadBalancerStrategyJmxTest method mockRelativeLoadBalancerStrategyJmx.

private RelativeLoadBalancerStrategyJmx mockRelativeLoadBalancerStrategyJmx(List<TrackerClient> trackerClients) {
    Map<TrackerClient, TrackerClientState> trackerClientsMap = new HashMap<>();
    for (TrackerClient trackerClient : trackerClients) {
        trackerClientsMap.put(trackerClient, new TrackerClientState(1, 1));
    }
    RelativeLoadBalancerStrategy strategy = Mockito.mock(RelativeLoadBalancerStrategy.class);
    PartitionState state = Mockito.mock(PartitionState.class);
    Mockito.when(state.getTrackerClientStateMap()).thenReturn(trackerClientsMap);
    Mockito.when(strategy.getFirstValidPartitionId()).thenReturn(DefaultPartitionAccessor.DEFAULT_PARTITION_ID);
    Mockito.when(strategy.getPartitionState(anyInt())).thenReturn(state);
    return new RelativeLoadBalancerStrategyJmx(strategy);
}
Also used : RelativeLoadBalancerStrategy(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) HashMap(java.util.HashMap) TrackerClientState(com.linkedin.d2.balancer.strategies.relative.TrackerClientState) PartitionState(com.linkedin.d2.balancer.strategies.relative.PartitionState)

Example 2 with RelativeLoadBalancerStrategy

use of com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy in project rest.li by linkedin.

the class SimpleLoadBalancerStateTest method testServiceStrategyListWithRelativeStrategy.

@Test
public void testServiceStrategyListWithRelativeStrategy() {
    reset();
    LinkedList<String> strategyList = new LinkedList<>();
    URI uri = URI.create("http://cluster-1/test");
    List<String> schemes = new ArrayList<>();
    Map<URI, Double> weights = new HashMap<>();
    weights.put(uri, 1d);
    schemes.add("http");
    _state.listenToService("service-1", new NullStateListenerCallback());
    _state.listenToCluster("cluster-1", new NullStateListenerCallback());
    strategyList.add(RelativeLoadBalancerStrategy.RELATIVE_LOAD_BALANCER_STRATEGY_NAME);
    strategyList.add(DegraderLoadBalancerStrategyV3.DEGRADER_STRATEGY_NAME);
    _serviceRegistry.put("service-1", new ServiceProperties("service-1", "cluster-1", "/test", strategyList, Collections.<String, Object>emptyMap(), null, null, schemes, null));
    _clusterRegistry.put("cluster-1", new ClusterProperties("cluster-1"));
    LoadBalancerStrategy strategy = _state.getStrategy("service-1", "http");
    assertNotNull(strategy);
    assertTrue(strategy instanceof RelativeLoadBalancerStrategy);
}
Also used : RelativeLoadBalancerStrategy(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RelativeLoadBalancerStrategy(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) RandomLoadBalancerStrategy(com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategy) URI(java.net.URI) LinkedList(java.util.LinkedList) NullStateListenerCallback(com.linkedin.d2.balancer.LoadBalancerState.NullStateListenerCallback) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) Test(org.testng.annotations.Test) DegraderLoadBalancerTest(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerTest)

Example 3 with RelativeLoadBalancerStrategy

use of com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy in project rest.li by linkedin.

the class RelativeLoadBalancerStrategyFactory method newLoadBalancer.

@Override
public RelativeLoadBalancerStrategy newLoadBalancer(ServiceProperties serviceProperties) {
    D2RelativeStrategyProperties relativeStrategyProperties = RelativeStrategyPropertiesConverter.toProperties(serviceProperties.getRelativeStrategyProperties());
    relativeStrategyProperties = putDefaultValues(relativeStrategyProperties);
    return new RelativeLoadBalancerStrategy(getRelativeStateUpdater(relativeStrategyProperties, serviceProperties.getServiceName(), serviceProperties.getClusterName(), serviceProperties.getPath()), getClientSelector(relativeStrategyProperties));
}
Also used : D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties)

Example 4 with RelativeLoadBalancerStrategy

use of com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy in project rest.li by linkedin.

the class LoadBalancerStrategyBenchmark method buildRelativeLoadBalancerStrategy.

private static RelativeLoadBalancerStrategy buildRelativeLoadBalancerStrategy() {
    D2RelativeStrategyProperties relativeStrategyProperties = new D2RelativeStrategyProperties();
    ServiceProperties serviceProperties = new ServiceProperties(DUMMY_SERVICE_NAME, DEFAULT_CLUSTER_NAME, DEFAULT_PATH, DEFAULT_STRATEGY_LIST, null, null, null, null, null, null, null, RelativeStrategyPropertiesConverter.toMap(relativeStrategyProperties));
    return new RelativeLoadBalancerStrategyFactory(EXECUTOR_SERVICE, null, new ArrayList<>(), null, SystemClock.instance()).newLoadBalancer(serviceProperties);
}
Also used : ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) RelativeLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory) ArrayList(java.util.ArrayList) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties)

Example 5 with RelativeLoadBalancerStrategy

use of com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy in project rest.li by linkedin.

the class RelativeLoadBalancerStrategyJmxTest method testNoValidPartitionData.

@Test
public void testNoValidPartitionData() {
    RelativeLoadBalancerStrategy strategy = Mockito.mock(RelativeLoadBalancerStrategy.class);
    Mockito.when(strategy.getFirstValidPartitionId()).thenReturn(DefaultPartitionAccessor.DEFAULT_PARTITION_ID);
    Mockito.when(strategy.getPartitionState(anyInt())).thenReturn(null);
    RelativeLoadBalancerStrategyJmx jmx = new RelativeLoadBalancerStrategyJmx(strategy);
    assertEquals(jmx.getLatencyStandardDeviation(), 0.0);
    assertEquals(jmx.getLatencyMeanAbsoluteDeviation(), 0.0);
    assertEquals(jmx.getAboveAverageLatencyStandardDeviation(), 0.0);
    assertEquals(jmx.getMaxLatencyRelativeFactor(), 0.0);
    assertEquals(jmx.getNthPercentileLatencyRelativeFactor(0.95), 0.0);
    assertEquals(jmx.getTotalPointsInHashRing(), 0);
    assertEquals(jmx.getUnhealthyHostsCount(), 0);
    assertEquals(jmx.getQuarantineHostsCount(), 0);
}
Also used : RelativeLoadBalancerStrategy(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy) Test(org.testng.annotations.Test)

Aggregations

RelativeLoadBalancerStrategy (com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy)3 D2RelativeStrategyProperties (com.linkedin.d2.D2RelativeStrategyProperties)2 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Test (org.testng.annotations.Test)2 NullStateListenerCallback (com.linkedin.d2.balancer.LoadBalancerState.NullStateListenerCallback)1 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)1 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)1 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)1 DegraderLoadBalancerTest (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerTest)1 RandomLoadBalancerStrategy (com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategy)1 PartitionState (com.linkedin.d2.balancer.strategies.relative.PartitionState)1 RelativeLoadBalancerStrategyFactory (com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory)1 TrackerClientState (com.linkedin.d2.balancer.strategies.relative.TrackerClientState)1 URI (java.net.URI)1 LinkedList (java.util.LinkedList)1