Search in sources :

Example 16 with DegraderLoadBalancerStrategyV3

use of com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyV3 in project rest.li by linkedin.

the class DegraderLoadBalancerTest method testHighTrafficHighLatency1Client.

@Test(groups = { "small", "back-end" })
public void testHighTrafficHighLatency1Client() {
    Map<String, Object> myMap = new HashMap<String, Object>();
    Long timeInterval = 5000L;
    TestClock clock = new TestClock();
    myMap.put(PropertyKeys.CLOCK, clock);
    myMap.put(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_UPDATE_INTERVAL_MS, timeInterval);
    Map<String, String> degraderProperties = new HashMap<String, String>();
    degraderProperties.put(PropertyKeys.DEGRADER_HIGH_ERROR_RATE, "0.5");
    degraderProperties.put(PropertyKeys.DEGRADER_LOW_ERROR_RATE, "0.2");
    DegraderImpl.Config degraderConfig = DegraderConfigFactory.toDegraderConfig(degraderProperties);
    double qps = 121;
    //test Strategy V3
    List<TrackerClient> clients = createTrackerClient(1, clock, degraderConfig);
    DegraderLoadBalancerStrategyConfig config = DegraderLoadBalancerStrategyConfig.createHttpConfigFromMap(myMap);
    DegraderLoadBalancerStrategyV3 strategyV3 = new DegraderLoadBalancerStrategyV3(config, "DegraderLoadBalancerTest", null);
    DegraderLoadBalancerStrategyAdapter strategy = new DegraderLoadBalancerStrategyAdapter(strategyV3);
    testDegraderLoadBalancerSimulator(strategy, clock, timeInterval, clients, qps, degraderConfig);
    //test Strategy V2
    clients = createTrackerClient(1, clock, degraderConfig);
    config = DegraderLoadBalancerStrategyConfig.createHttpConfigFromMap(myMap);
    DegraderLoadBalancerStrategyV2_1 strategyV2 = new DegraderLoadBalancerStrategyV2_1(config, "DegraderLoadBalancerTest", null);
    strategy = new DegraderLoadBalancerStrategyAdapter(strategyV2);
    testDegraderLoadBalancerSimulator(strategy, clock, timeInterval, clients, qps, degraderConfig);
}
Also used : HashMap(java.util.HashMap) DegraderImpl(com.linkedin.util.degrader.DegraderImpl) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.testng.annotations.Test) TrackerClientTest(com.linkedin.d2.balancer.clients.TrackerClientTest)

Example 17 with DegraderLoadBalancerStrategyV3

use of com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyV3 in project rest.li by linkedin.

the class DegraderLoadBalancerTest method testClusterRecoverySlow1TC.

@Test(groups = { "small", "back-end" })
public void testClusterRecoverySlow1TC() {
    Map<String, Object> myMap = new HashMap<String, Object>();
    Long timeInterval = 5000L;
    TestClock clock = new TestClock();
    myMap.put(PropertyKeys.CLOCK, clock);
    // We want the degrader to have one cooling off period, and then re-enter the ring. This
    myMap.put(PropertyKeys.HTTP_LB_INITIAL_RECOVERY_LEVEL, 0.005);
    myMap.put(PropertyKeys.HTTP_LB_RING_RAMP_FACTOR, 2.0);
    myMap.put(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_UPDATE_INTERVAL_MS, timeInterval);
    // it will take two intervals for the TC to be reintroduced into the hash ring.
    int stepsToFullRecovery = 1;
    //test Strategy V3
    DegraderLoadBalancerStrategyConfig config = DegraderLoadBalancerStrategyConfig.createHttpConfigFromMap(myMap);
    DegraderLoadBalancerStrategyV3 strategyV3 = new DegraderLoadBalancerStrategyV3(config, "DegraderLoadBalancerTest", null);
    DegraderLoadBalancerStrategyAdapter strategy = new DegraderLoadBalancerStrategyAdapter(strategyV3);
    clusterRecovery1TC(myMap, clock, stepsToFullRecovery, timeInterval, strategy, null, DegraderLoadBalancerStrategyV3.PartitionDegraderLoadBalancerState.Strategy.LOAD_BALANCE);
    //test Strategy V2
    config = DegraderLoadBalancerStrategyConfig.createHttpConfigFromMap(myMap);
    DegraderLoadBalancerStrategyV2_1 strategyV2 = new DegraderLoadBalancerStrategyV2_1(config, "DegraderLoadBalancerTest", null);
    strategy = new DegraderLoadBalancerStrategyAdapter(strategyV2);
    clusterRecovery1TC(myMap, clock, stepsToFullRecovery, timeInterval, strategy, DegraderLoadBalancerStrategyV2_1.DegraderLoadBalancerState.Strategy.LOAD_BALANCE, null);
}
Also used : HashMap(java.util.HashMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.testng.annotations.Test) TrackerClientTest(com.linkedin.d2.balancer.clients.TrackerClientTest)

Example 18 with DegraderLoadBalancerStrategyV3

use of com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyV3 in project rest.li by linkedin.

the class DegraderLoadBalancerTest method stressTest.

@Test(groups = { "small", "back-end" })
public void stressTest() {
    final DegraderLoadBalancerStrategyV3 strategyV3 = getStrategy();
    TestClock testClock = new TestClock();
    String baseUri = "http://linkedin.com:9999";
    int numberOfPartitions = 10;
    Map<String, String> degraderProperties = new HashMap<String, String>();
    degraderProperties.put(PropertyKeys.DEGRADER_HIGH_ERROR_RATE, "0.5");
    degraderProperties.put(PropertyKeys.DEGRADER_LOW_ERROR_RATE, "0.2");
    DegraderImpl.Config degraderConfig = DegraderConfigFactory.toDegraderConfig(degraderProperties);
    final List<TrackerClient> clients = new ArrayList<TrackerClient>();
    for (int i = 0; i < numberOfPartitions; i++) {
        URI uri = URI.create(baseUri + i);
        TrackerClient client = new TrackerClient(uri, getDefaultPartitionData(1, numberOfPartitions), new TestLoadBalancerClient(uri), testClock, degraderConfig);
        clients.add(client);
    }
    final ExecutorService executor = Executors.newFixedThreadPool(100);
    final CountDownLatch startLatch = new CountDownLatch(1);
    final CountDownLatch finishLatch = new CountDownLatch(100);
    try {
        for (int i = 0; i < numberOfPartitions; i++) {
            Assert.assertFalse(strategyV3.getState().getPartitionState(i).isInitialized());
        }
        for (int i = 0; i < 100; i++) {
            final int partitionId = i % numberOfPartitions;
            executor.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        startLatch.await();
                    } catch (InterruptedException ex) {
                    }
                    strategyV3.getRing(1, partitionId, clients);
                    finishLatch.countDown();
                }
            });
        }
        // all threads would try to getRing simultanously
        startLatch.countDown();
        if (!finishLatch.await(10, TimeUnit.SECONDS)) {
            fail("Stress test failed to finish within 10 seconds");
        }
        for (int i = 0; i < numberOfPartitions; i++) {
            Assert.assertTrue(strategyV3.getState().getPartitionState(i).isInitialized());
        }
    } catch (InterruptedException ex) {
    } finally {
        executor.shutdownNow();
    }
}
Also used : HashMap(java.util.HashMap) DegraderImpl(com.linkedin.util.degrader.DegraderImpl) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) ExecutorService(java.util.concurrent.ExecutorService) Test(org.testng.annotations.Test) TrackerClientTest(com.linkedin.d2.balancer.clients.TrackerClientTest)

Example 19 with DegraderLoadBalancerStrategyV3

use of com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyV3 in project rest.li by linkedin.

the class DegraderLoadBalancerTest method testMediumTrafficHighLatency100Clients.

@Test(groups = { "small", "back-end" })
public void testMediumTrafficHighLatency100Clients() {
    Map<String, Object> myMap = new HashMap<String, Object>();
    Long timeInterval = 5000L;
    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_STRATEGY_PROPERTIES_UPDATE_INTERVAL_MS, timeInterval);
    Map<String, String> degraderProperties = new HashMap<String, String>();
    degraderProperties.put(PropertyKeys.DEGRADER_HIGH_ERROR_RATE, "0.5");
    degraderProperties.put(PropertyKeys.DEGRADER_LOW_ERROR_RATE, "0.2");
    DegraderImpl.Config degraderConfig = DegraderConfigFactory.toDegraderConfig(degraderProperties);
    double qps = 7.3;
    //test Strategy V3
    List<TrackerClient> clients = createTrackerClient(100, clock, degraderConfig);
    DegraderLoadBalancerStrategyConfig config = DegraderLoadBalancerStrategyConfig.createHttpConfigFromMap(myMap);
    DegraderLoadBalancerStrategyV3 strategyV3 = new DegraderLoadBalancerStrategyV3(config, "DegraderLoadBalancerTest", null);
    DegraderLoadBalancerStrategyAdapter strategy = new DegraderLoadBalancerStrategyAdapter(strategyV3);
    testDegraderLoadBalancerSimulator(strategy, clock, timeInterval, clients, qps, degraderConfig);
    //test Strategy V2
    clients = createTrackerClient(100, clock, degraderConfig);
    config = DegraderLoadBalancerStrategyConfig.createHttpConfigFromMap(myMap);
    DegraderLoadBalancerStrategyV2_1 strategyV2 = new DegraderLoadBalancerStrategyV2_1(config, "DegraderLoadBalancerTest", null);
    strategy = new DegraderLoadBalancerStrategyAdapter(strategyV2);
    testDegraderLoadBalancerSimulator(strategy, clock, timeInterval, clients, qps, degraderConfig);
}
Also used : HashMap(java.util.HashMap) DegraderImpl(com.linkedin.util.degrader.DegraderImpl) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.testng.annotations.Test) TrackerClientTest(com.linkedin.d2.balancer.clients.TrackerClientTest)

Example 20 with DegraderLoadBalancerStrategyV3

use of com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyV3 in project rest.li by linkedin.

the class DegraderLoadBalancerTest method testMediumTrafficHighLatency10Clients.

@Test(groups = { "small", "back-end" })
public void testMediumTrafficHighLatency10Clients() {
    Map<String, Object> myMap = new HashMap<String, Object>();
    Long timeInterval = 5000L;
    TestClock clock = new TestClock();
    myMap.put(PropertyKeys.CLOCK, clock);
    myMap.put(PropertyKeys.HTTP_LB_STRATEGY_PROPERTIES_UPDATE_INTERVAL_MS, timeInterval);
    Map<String, String> degraderProperties = new HashMap<String, String>();
    degraderProperties.put(PropertyKeys.DEGRADER_HIGH_ERROR_RATE, "0.5");
    degraderProperties.put(PropertyKeys.DEGRADER_LOW_ERROR_RATE, "0.2");
    DegraderImpl.Config degraderConfig = DegraderConfigFactory.toDegraderConfig(degraderProperties);
    double qps = 6.3;
    //test Strategy V3
    List<TrackerClient> clients = createTrackerClient(10, clock, degraderConfig);
    DegraderLoadBalancerStrategyConfig config = DegraderLoadBalancerStrategyConfig.createHttpConfigFromMap(myMap);
    DegraderLoadBalancerStrategyV3 strategyV3 = new DegraderLoadBalancerStrategyV3(config, "DegraderLoadBalancerTest", null);
    DegraderLoadBalancerStrategyAdapter strategy = new DegraderLoadBalancerStrategyAdapter(strategyV3);
    testDegraderLoadBalancerSimulator(strategy, clock, timeInterval, clients, qps, degraderConfig);
    //test Strategy V2
    clients = createTrackerClient(10, clock, degraderConfig);
    config = DegraderLoadBalancerStrategyConfig.createHttpConfigFromMap(myMap);
    DegraderLoadBalancerStrategyV2_1 strategyV2 = new DegraderLoadBalancerStrategyV2_1(config, "DegraderLoadBalancerTest", null);
    strategy = new DegraderLoadBalancerStrategyAdapter(strategyV2);
    testDegraderLoadBalancerSimulator(strategy, clock, timeInterval, clients, qps, degraderConfig);
}
Also used : HashMap(java.util.HashMap) DegraderImpl(com.linkedin.util.degrader.DegraderImpl) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.testng.annotations.Test) TrackerClientTest(com.linkedin.d2.balancer.clients.TrackerClientTest)

Aggregations

Test (org.testng.annotations.Test)45 TrackerClientTest (com.linkedin.d2.balancer.clients.TrackerClientTest)41 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)38 HashMap (java.util.HashMap)33 ArrayList (java.util.ArrayList)32 RequestContext (com.linkedin.r2.message.RequestContext)23 URI (java.net.URI)21 AtomicLong (java.util.concurrent.atomic.AtomicLong)18 DegraderImpl (com.linkedin.util.degrader.DegraderImpl)13 CallCompletion (com.linkedin.util.degrader.CallCompletion)9 DegraderControl (com.linkedin.util.degrader.DegraderControl)9 URIRequest (com.linkedin.d2.balancer.util.URIRequest)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)4 DegraderLoadBalancerStrategyV3 (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyV3)4 com.linkedin.d2.hashConfigType (com.linkedin.d2.hashConfigType)3 com.linkedin.d2.quarantineInfo (com.linkedin.d2.quarantineInfo)3 Map (java.util.Map)3 ExecutorService (java.util.concurrent.ExecutorService)3 D2LoadBalancerStrategyProperties (com.linkedin.d2.D2LoadBalancerStrategyProperties)2