Search in sources :

Example 16 with LoadBalancerSimulator

use of com.linkedin.d2.balancer.simple.LoadBalancerSimulator in project rest.li by linkedin.

the class SimpleLoadBalancerDelayTest method testLoadBalancerWithFastRecoveryNoSlowstart.

@Test(groups = { "small", "back-end" })
public void testLoadBalancerWithFastRecoveryNoSlowstart() throws Exception {
    // Generate service, cluster and uri properties for d2
    URI uri1 = URI.create("http://test.qa1.com:1234");
    URI uri2 = URI.create("http://test.qa2.com:2345");
    String clusterName = "cluster-2";
    Map<Integer, PartitionData> partitionData = new HashMap<>(1);
    partitionData.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d));
    Map<URI, Map<Integer, PartitionData>> uriData = new HashMap<>(1);
    uriData.put(uri1, partitionData);
    ClusterProperties clusterProperties = new ClusterProperties(clusterName);
    List<String> prioritizedSchemes = Collections.singletonList("http");
    // set initial drop rate and slow start threshold
    Map<String, String> degraderProperties = DegraderLoadBalancerTest.degraderDefaultConfig();
    degraderProperties.put(PropertyKeys.DEGRADER_MIN_CALL_COUNT, "1");
    degraderProperties.put(PropertyKeys.DEGRADER_DOWN_STEP, "0.3");
    // constant delay generator
    Map<String, List<Long>> delayMaps = new HashMap<>();
    delayMaps.put("test.qa1.com:1234", Arrays.asList(80L, 80L, 60L, 80L, 50L, 80L, 80L, 80L, 60L, 80L, 60L, 80L, 80L, 80L, 60L, 80L, 50L, 60L, 80L, 60L, 80L, 80L, 80L, 60L, 80L, 60L, 80L, 80L, 60L, 80L, 50L, 80L, 80L, 80L, 60L, 80L, 60L, 80L, 80L, 60L, 80L, 50L, 80L, 80L, 80L, 60L, 80L, 60L));
    delayMaps.put("test.qa2.com:2345", Arrays.asList(80L, 80L, 60L, 80L, 50L, 80L, 80L, 80L, 60L, 80L, 60L, 80L, 80L, 80L, 60L, 80L, 50L, 60L, 80L, 60L, 80L, 80L, 3080L, 3060L, 89L, 60L, 3080L, 3080L, 3000L, 3000L, 3000L, 3000L, 3080L, 4060L, 3080L, 4080L, 4060L, 80L, 80L, 60L, 60L, 60L, 60L));
    LoadBalancerSimulator.TimedValueGenerator<String, Long> delayGenerator = new DelayValueGenerator<>(delayMaps, DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
    LoadBalancerSimulator.QPSGenerator qpsGenerator = new QPSValueGenerator(Arrays.asList(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000, 1000, 1000));
    Map<String, Object> transportClientProperties = Collections.singletonMap("DelayGenerator", delayGenerator);
    ServiceProperties serviceProperties = new ServiceProperties("foo", clusterName, "/foo", Arrays.asList("degraderV3"), lbStrategyPropertiesWithSlowstart(), transportClientProperties, degraderProperties, prioritizedSchemes, null);
    UriProperties uriProperties = new UriProperties(clusterName, uriData);
    // pass all the info to the simulator
    LoadBalancerSimulator loadBalancerSimulator = new LoadBalancerSimulator(serviceProperties, clusterProperties, uriProperties, delayGenerator, qpsGenerator, null);
    // Start the simulation: wait for uri to its full points
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 5);
    assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1) >= 4);
    printStates(loadBalancerSimulator);
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 5);
    assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 100);
    printStates(loadBalancerSimulator);
    // Adding uri2
    uriData.put(uri2, partitionData);
    uriProperties = new UriProperties(clusterName, uriData);
    loadBalancerSimulator.updateUriProperties(uriProperties);
    // no traffic to uri2, still full points since no degrading
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 10);
    assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2) == 100);
    printStates(loadBalancerSimulator);
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test) DegraderLoadBalancerTest(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerTest)

Example 17 with LoadBalancerSimulator

use of com.linkedin.d2.balancer.simple.LoadBalancerSimulator in project rest.li by linkedin.

the class SimpleLoadBalancerDelayTest method testLoadBalancerWithFastRecovery.

@Test(groups = { "small", "back-end" })
public void testLoadBalancerWithFastRecovery() throws Exception {
    // Generate service, cluster and uri properties for d2
    URI uri1 = URI.create("http://test.qa1.com:1234");
    URI uri2 = URI.create("http://test.qa2.com:2345");
    String clusterName = "cluster-2";
    Map<Integer, PartitionData> partitionData = new HashMap<>(1);
    partitionData.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d));
    Map<URI, Map<Integer, PartitionData>> uriData = new HashMap<>(1);
    uriData.put(uri1, partitionData);
    uriData.put(uri2, partitionData);
    ClusterProperties clusterProperties = new ClusterProperties(clusterName);
    List<String> prioritizedSchemes = Collections.singletonList("http");
    // set initial drop rate and slow start threshold
    Map<String, String> degraderProperties = DegraderLoadBalancerTest.degraderDefaultConfig();
    degraderProperties.put(PropertyKeys.DEGRADER_MIN_CALL_COUNT, "1");
    // degraderProperties.put(PropertyKeys.DEGRADER_DOWN_STEP, "0.3");
    degraderProperties.put(PropertyKeys.DEGRADER_UP_STEP, "0.3");
    // constant delay generator
    Map<String, List<Long>> delayMaps = new HashMap<>();
    delayMaps.put("test.qa1.com:1234", Arrays.asList(80l, 30l, 30l, 30l, 30l, 80l, 30l, 30l, 30l, 30l, 30l, 80l, 60l, 80l, 80l, 60l, 80l, 80l, 60l, 80l, 80l, 80l, 80l));
    delayMaps.put("test.qa2.com:2345", Arrays.asList(3080l, 3080l, 3030l, 3030l, 3030l, 3080l, 30l, 30l, 60l, 80l, 50l, 80l, 80l, 80l, 60l, 80l, 60l, 80l, 60l, 80l, 80l));
    LoadBalancerSimulator.TimedValueGenerator<String, Long> delayGenerator = new DelayValueGenerator<>(delayMaps, DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
    // constant QPS generator
    LoadBalancerSimulator.QPSGenerator qpsGenerator = new ConstantQPSGenerator(8);
    Map<String, Object> transportClientProperties = Collections.singletonMap("DelayGenerator", delayGenerator);
    ServiceProperties serviceProperties = new ServiceProperties("foo", clusterName, "/foo", Arrays.asList("degraderV3"), lbStrategyPropertiesWithSlowstart(), transportClientProperties, degraderProperties, prioritizedSchemes, null);
    UriProperties uriProperties = new UriProperties(clusterName, uriData);
    // pass all the info to the simulator
    LoadBalancerSimulator loadBalancerSimulator = new LoadBalancerSimulator(serviceProperties, clusterProperties, uriProperties, delayGenerator, qpsGenerator, null);
    // Start the simulation: wait for uri2 to fully degrading
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 5);
    int prePoint = loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2);
    assertTrue(prePoint <= 10);
    printStates(loadBalancerSimulator);
    // recovering: because the QPS is low, uri2 won't get the traffic in most of the time, however its point is increasing
    // by the maxDropRate
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
    printStates(loadBalancerSimulator);
    int curPoint = loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2);
    assertTrue(curPoint >= prePoint);
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
    prePoint = curPoint;
    curPoint = loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2);
    assertTrue(curPoint >= prePoint);
    printStates(loadBalancerSimulator);
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
    prePoint = curPoint;
    curPoint = loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2);
    assertTrue(curPoint >= prePoint);
    printStates(loadBalancerSimulator);
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
    prePoint = curPoint;
    curPoint = loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2);
    assertTrue(curPoint >= prePoint);
    printStates(loadBalancerSimulator);
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
    prePoint = curPoint;
    curPoint = loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2);
    assertTrue(curPoint >= prePoint);
    printStates(loadBalancerSimulator);
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
    prePoint = curPoint;
    curPoint = loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2);
    assertTrue(curPoint >= prePoint);
    printStates(loadBalancerSimulator);
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
    prePoint = curPoint;
    curPoint = loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2);
    assertTrue(curPoint >= prePoint);
    printStates(loadBalancerSimulator);
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
    prePoint = curPoint;
    curPoint = loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2);
    assertTrue(curPoint >= prePoint);
    printStates(loadBalancerSimulator);
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
    prePoint = curPoint;
    curPoint = loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2);
    assertTrue(curPoint >= prePoint);
    printStates(loadBalancerSimulator);
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 6);
    assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2), 100);
    printStates(loadBalancerSimulator);
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test) DegraderLoadBalancerTest(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerTest)

Example 18 with LoadBalancerSimulator

use of com.linkedin.d2.balancer.simple.LoadBalancerSimulator in project rest.li by linkedin.

the class SimpleLoadBalancerDelayTest method loadBalancerQuarantineWithExpBackoffTest.

/**
 * Simple test to verify quarantine add/evict operations
 * @throws Exception
 */
@Test(groups = { "small", "back-end" })
public void loadBalancerQuarantineWithExpBackoffTest() throws Exception {
    String uri1 = "test.qa1.com:1234";
    String uri2 = "test.qa2.com:2345";
    List<String> uris = Arrays.asList(uri1, uri2);
    // Construct the delay patterns: for each URI there is a list of delays for each interval
    Map<String, List<Long>> delayMaps = new HashMap<>();
    delayMaps.put("test.qa1.com:1234", Arrays.asList(80l, 3000l, 3000l, 3000l, 3000l, 3000l, 3000l, 70l, 60l, 70l, 80l, 60l, 70l, 80l, 70l, 60l, 75l));
    delayMaps.put("test.qa2.com:2345", Arrays.asList(70l, 70l, 60l, 70l, 50l, 80l, 60l, 70l, 70l, 70l, 60l, 70l, 60l, 75l, 90l, 70l));
    LoadBalancerSimulator.TimedValueGenerator<String, Long> delayGenerator = new DelayValueGenerator<>(delayMaps, DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
    // Construct the QPS generator
    LoadBalancerSimulator.QPSGenerator qpsGenerator = new ConstantQPSGenerator(1000);
    // Create the simulator
    LoadBalancerSimulator loadBalancerSimulator = LoadBalancerSimulationBuilder.build("cluster-1", "foo", uris, lbStrategyPropertiesWithQuarantine(), null, null, delayGenerator, qpsGenerator);
    URI expectedUri1 = LoadBalancerSimulationBuilder.getExpectedUri("test.qa1.com:1234", "foo");
    // Start the simulation
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
    printStates(loadBalancerSimulator);
    // the points for uri1 should be 100
    assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 100);
    assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2), 100);
    // wait for 2 intervals due to call dropping involved
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
    printStates(loadBalancerSimulator);
    // the points for uri1 should be 60
    assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 60);
    // continue the simulation
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
    printStates(loadBalancerSimulator);
    // the points for uri1 should be 0 as it is now in quarantine
    assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 0);
    assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2), 100);
    // waiting for longer time to recover
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 4);
    printStates(loadBalancerSimulator);
    assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 0);
    // Evicted from quarantine finally. The point number should be none zero
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
    printStates(loadBalancerSimulator);
    assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1) > 0);
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 4);
    printStates(loadBalancerSimulator);
    // uri1 should fully recovered by now
    assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 100);
    // the points for uri3 should be around 60, recovering
    _log.info(loadBalancerSimulator.getClockedExecutor().toString());
    // Done. Shutdown the simulation
    loadBalancerSimulator.shutdown();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI) Test(org.testng.annotations.Test) DegraderLoadBalancerTest(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerTest)

Aggregations

DegraderLoadBalancerTest (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerTest)18 URI (java.net.URI)18 ArrayList (java.util.ArrayList)18 HashMap (java.util.HashMap)18 List (java.util.List)18 Test (org.testng.annotations.Test)18 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)7 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)7 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)7 Map (java.util.Map)7 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)6 D2Monitor (com.linkedin.d2.balancer.event.D2Monitor)5 ServiceUnavailableException (com.linkedin.d2.balancer.ServiceUnavailableException)3 EventEmitter (com.linkedin.d2.balancer.event.EventEmitter)3 PropertyKeys (com.linkedin.d2.balancer.properties.PropertyKeys)3 DelegatingRingFactory (com.linkedin.d2.balancer.strategies.DelegatingRingFactory)3 DegraderLoadBalancerStrategyConfig (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyConfig)3 DegraderLoadBalancerStrategyV3 (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyV3)3 DefaultPartitionAccessor (com.linkedin.d2.balancer.util.partitions.DefaultPartitionAccessor)3 Arrays (java.util.Arrays)3