Search in sources :

Example 71 with ClusterProperties

use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.

the class SimpleLoadBalancerDelayTest method testLoadBalancerWithFastRecoveryAndSlowstartWithDegrading.

@Test(groups = { "small", "back-end" })
public void testLoadBalancerWithFastRecoveryAndSlowstartWithDegrading() 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_INITIAL_DROP_RATE, "0.99");
    degraderProperties.put(PropertyKeys.DEGRADER_SLOW_START_THRESHOLD, "0.1");
    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));
    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);
    // _log.info("Points is " + loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1));
    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, even though the points are increasing
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 10);
    assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2) >= 8);
    printStates(loadBalancerSimulator);
    // Got traffic, computedDrapRate recovered.
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
    printStates(loadBalancerSimulator);
    // degrading again with high latency: kicked out from recoveryMap
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
    assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2) < 32);
    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 72 with ClusterProperties

use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.

the class SimpleLoadBalancerDelayTest method testLoadBalancerWithFastRecoveryAndSlowstart.

@Test(groups = { "small", "back-end" })
public void testLoadBalancerWithFastRecoveryAndSlowstart() 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_INITIAL_DROP_RATE, "0.99");
    degraderProperties.put(PropertyKeys.DEGRADER_SLOW_START_THRESHOLD, "0.1");
    degraderProperties.put(PropertyKeys.DEGRADER_MIN_CALL_COUNT, "1");
    degraderProperties.put(PropertyKeys.DEGRADER_DOWN_STEP, "0.3");
    // constant delay generator
    LoadBalancerSimulator.TimedValueGenerator<String, Long> delayGenerator = (uri, time, unit) -> 100l;
    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, 20, 1, 1, 1, 1, 1, 1, 1, 1, 10));
    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);
    // _log.info("Points is " + loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1));
    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, even though the points are increasing
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 10);
    assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2) >= 4);
    printStates(loadBalancerSimulator);
    // only one possible recovery, points increasing by recoveryMap
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 8);
    assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2) >= 64);
    printStates(loadBalancerSimulator);
    // fully recovered
    loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 6);
    assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2), 100);
    printStates(loadBalancerSimulator);
}
Also used : DegraderLoadBalancerStrategyConfig(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyConfig) DefaultPartitionAccessor(com.linkedin.d2.balancer.util.partitions.DefaultPartitionAccessor) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) ArrayList(java.util.ArrayList) DegraderLoadBalancerTest(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerTest) Map(java.util.Map) DelegatingRingFactory(com.linkedin.d2.balancer.strategies.DelegatingRingFactory) URI(java.net.URI) Assert.assertFalse(org.testng.Assert.assertFalse) D2Monitor(com.linkedin.d2.balancer.event.D2Monitor) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) DegraderLoadBalancerStrategyV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyV3) EventEmitter(com.linkedin.d2.balancer.event.EventEmitter) PropertyKeys(com.linkedin.d2.balancer.properties.PropertyKeys) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Assert.assertTrue(org.testng.Assert.assertTrue) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) ServiceUnavailableException(com.linkedin.d2.balancer.ServiceUnavailableException) Collections(java.util.Collections) 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) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test) DegraderLoadBalancerTest(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerTest)

Example 73 with ClusterProperties

use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.

the class SimpleLoadBalancerStrawMan method main.

public static void main(String[] args) throws URISyntaxException, ServiceUnavailableException {
    // define the load balancing strategies that we support (round robin, etc)
    Map<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>> loadBalancerStrategyFactories = new HashMap<>();
    loadBalancerStrategyFactories.put("rr", new RandomLoadBalancerStrategyFactory());
    loadBalancerStrategyFactories.put("degrader", new DegraderLoadBalancerStrategyFactoryV3());
    // define the clients that we support (http, etc)
    Map<String, TransportClientFactory> clientFactories = new HashMap<>();
    clientFactories.put("http", new HttpClientFactory.Builder().build());
    // listen for service updates (could be a glu discovery client, zk discovery client,
    // config discovery client, etc)
    ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
    MockStore<ServiceProperties> serviceRegistry = new MockStore<>();
    MockStore<ClusterProperties> clusterRegistry = new MockStore<>();
    MockStore<UriProperties> uriRegistry = new MockStore<>();
    SimpleLoadBalancerState state = new SimpleLoadBalancerState(executorService, uriRegistry, clusterRegistry, serviceRegistry, clientFactories, loadBalancerStrategyFactories);
    // create the load balancer
    SimpleLoadBalancer loadBalancer = new SimpleLoadBalancer(state, executorService);
    final TransportClient tc = loadBalancer.getClient(new URIRequest("d2://browsemaps/52"), new RequestContext());
    final Client c = new TransportClientAdapter(tc, true);
    c.restRequest(null);
}
Also used : HashMap(java.util.HashMap) DegraderLoadBalancerStrategyFactoryV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3) MockStore(com.linkedin.d2.discovery.stores.mock.MockStore) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) RequestContext(com.linkedin.r2.message.RequestContext) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) Client(com.linkedin.r2.transport.common.Client) TransportClientFactory(com.linkedin.r2.transport.common.TransportClientFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) LoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.LoadBalancerStrategyFactory) RandomLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategyFactory) RandomLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategyFactory) URIRequest(com.linkedin.d2.balancer.util.URIRequest) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties)

Example 74 with ClusterProperties

use of com.linkedin.d2.balancer.properties.ClusterProperties 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 75 with ClusterProperties

use of com.linkedin.d2.balancer.properties.ClusterProperties 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)

Aggregations

ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)72 HashMap (java.util.HashMap)51 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)49 Test (org.testng.annotations.Test)47 ArrayList (java.util.ArrayList)42 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)41 URI (java.net.URI)38 Map (java.util.Map)32 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)24 DegraderLoadBalancerTest (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerTest)24 List (java.util.List)20 NullStateListenerCallback (com.linkedin.d2.balancer.LoadBalancerState.NullStateListenerCallback)18 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)18 None (com.linkedin.common.util.None)16 TransportClientFactory (com.linkedin.r2.transport.common.TransportClientFactory)16 FutureCallback (com.linkedin.common.callback.FutureCallback)15 HashSet (java.util.HashSet)14 DarkClusterConfigMap (com.linkedin.d2.DarkClusterConfigMap)13 RequestContext (com.linkedin.r2.message.RequestContext)13 ClusterPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer)12