Search in sources :

Example 11 with DegraderTrackerClient

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;
}
Also used : DegraderTrackerClient(com.linkedin.d2.balancer.clients.DegraderTrackerClient) DegraderTrackerClientImpl(com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl) URI(java.net.URI) LinkedList(java.util.LinkedList)

Example 12 with DegraderTrackerClient

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

Example 13 with DegraderTrackerClient

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;
}
Also used : DegraderTrackerClient(com.linkedin.d2.balancer.clients.DegraderTrackerClient) HashMap(java.util.HashMap) DegraderControl(com.linkedin.util.degrader.DegraderControl)

Example 14 with DegraderTrackerClient

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

Example 15 with DegraderTrackerClient

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

Aggregations

DegraderTrackerClient (com.linkedin.d2.balancer.clients.DegraderTrackerClient)58 Test (org.testng.annotations.Test)46 DegraderTrackerClientTest (com.linkedin.d2.balancer.clients.DegraderTrackerClientTest)42 ArrayList (java.util.ArrayList)34 URI (java.net.URI)31 RequestContext (com.linkedin.r2.message.RequestContext)30 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)20 DegraderImpl (com.linkedin.util.degrader.DegraderImpl)19 AtomicLong (java.util.concurrent.atomic.AtomicLong)17 DegraderControl (com.linkedin.util.degrader.DegraderControl)16 HashMap (java.util.HashMap)16 DegraderTrackerClientImpl (com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl)14 CallCompletion (com.linkedin.util.degrader.CallCompletion)11 URIRequest (com.linkedin.d2.balancer.util.URIRequest)9 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)7 SettableClock (com.linkedin.util.clock.SettableClock)6 LoadBalancerQuarantine (com.linkedin.d2.balancer.strategies.LoadBalancerQuarantine)4 RestRequest (com.linkedin.r2.message.rest.RestRequest)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4