Search in sources :

Example 26 with URIRequest

use of com.linkedin.d2.balancer.util.URIRequest in project rest.li by linkedin.

the class DegraderLoadBalancerTest method testCallDroppingHelper.

private void testCallDroppingHelper(DegraderLoadBalancerStrategyAdapter strategyAdapter, List<DegraderTrackerClient> clients, TestClock clock, Long timeInterval) {
    // test clusterOverrideDropRate won't increase even though latency is 3000 ms because the traffic is low
    callClients(3000, 0.2, clients, clock, timeInterval, false, false);
    strategyAdapter.setStrategyToCallDrop();
    URIRequest request = new URIRequest(clients.get(0).getUri());
    getTrackerClient(strategyAdapter, request, new RequestContext(), 1, clients);
    assertTrue(isEqual(0.0d, strategyAdapter.getCurrentOverrideDropRate()));
    // if we increase the QPS from 0.2 to 25, then we'll start dropping calls
    callClients(3000, 25, clients, clock, timeInterval, false, false);
    strategyAdapter.setStrategyToCallDrop();
    getTrackerClient(strategyAdapter, request, new RequestContext(), 1, clients);
    assertTrue(isEqual(0.2d, strategyAdapter.getCurrentOverrideDropRate()));
    ;
    // if we set the QPS to be somewhere below high and low water mark then the drop rate stays the same
    // even though the latency is high
    callClients(3000, 2, clients, clock, timeInterval, false, false);
    strategyAdapter.setStrategyToCallDrop();
    getTrackerClient(strategyAdapter, request, new RequestContext(), 1, clients);
    assertTrue(isEqual(0.2d, strategyAdapter.getCurrentOverrideDropRate()));
    // now we want to degrade the cluster even further
    callClients(3000, 25, clients, clock, timeInterval, false, false);
    strategyAdapter.setStrategyToCallDrop();
    getTrackerClient(strategyAdapter, request, new RequestContext(), 1, clients);
    assertTrue(isEqual(0.4d, strategyAdapter.getCurrentOverrideDropRate()));
    callClients(3000, 25, clients, clock, timeInterval, false, false);
    strategyAdapter.setStrategyToCallDrop();
    getTrackerClient(strategyAdapter, request, new RequestContext(), 1, clients);
    assertTrue(isEqual(0.6d, strategyAdapter.getCurrentOverrideDropRate()));
    callClients(3000, 25, clients, clock, timeInterval, false, false);
    strategyAdapter.setStrategyToCallDrop();
    getTrackerClient(strategyAdapter, request, new RequestContext(), 1, clients);
    assertTrue(isEqual(0.8d, strategyAdapter.getCurrentOverrideDropRate()));
    callClients(3000, 25, clients, clock, timeInterval, false, false);
    strategyAdapter.setStrategyToCallDrop();
    getTrackerClient(strategyAdapter, request, new RequestContext(), 1, clients);
    assertTrue(isEqual(1.0d, strategyAdapter.getCurrentOverrideDropRate()));
    // if we have qps below lowWaterMark, we will reduce drop rate even though latency is high
    callClients(3000, 0.5, clients, clock, timeInterval, false, false);
    strategyAdapter.setStrategyToCallDrop();
    getTrackerClient(strategyAdapter, request, new RequestContext(), 1, clients);
    assertTrue(isEqual(0.8d, strategyAdapter.getCurrentOverrideDropRate()));
    // if we have qps below lowWaterMark and qps is low, we will also reduce drop rate
    callClients(100, 0.5, clients, clock, timeInterval, false, false);
    strategyAdapter.setStrategyToCallDrop();
    getTrackerClient(strategyAdapter, request, new RequestContext(), 1, clients);
    assertTrue(isEqual(0.6d, strategyAdapter.getCurrentOverrideDropRate()));
    // if we have qps between lowWaterMark and highWaterMark and latency is low, we will reduce drop rate
    callClients(100, 2, clients, clock, timeInterval, false, false);
    strategyAdapter.setStrategyToCallDrop();
    getTrackerClient(strategyAdapter, request, new RequestContext(), 1, clients);
    assertTrue(isEqual(0.4d, strategyAdapter.getCurrentOverrideDropRate()));
    // if we have qps higher than highWaterMark and latency is low, we will reduce drop rate
    callClients(100, 25, clients, clock, timeInterval, false, false);
    strategyAdapter.setStrategyToCallDrop();
    getTrackerClient(strategyAdapter, request, new RequestContext(), 1, clients);
    assertTrue(isEqual(0.2d, strategyAdapter.getCurrentOverrideDropRate()));
}
Also used : URIRequest(com.linkedin.d2.balancer.util.URIRequest) RequestContext(com.linkedin.r2.message.RequestContext)

Example 27 with URIRequest

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

Aggregations

URIRequest (com.linkedin.d2.balancer.util.URIRequest)26 RequestContext (com.linkedin.r2.message.RequestContext)24 URI (java.net.URI)20 ArrayList (java.util.ArrayList)17 Test (org.testng.annotations.Test)15 HashMap (java.util.HashMap)14 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)12 Map (java.util.Map)11 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)9 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)9 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)9 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)9 HashSet (java.util.HashSet)9 FutureCallback (com.linkedin.common.callback.FutureCallback)8 None (com.linkedin.common.util.None)8 DegraderTrackerClient (com.linkedin.d2.balancer.clients.DegraderTrackerClient)8 TransportClientFactory (com.linkedin.r2.transport.common.TransportClientFactory)8 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)7 LoadBalancerStrategyFactory (com.linkedin.d2.balancer.strategies.LoadBalancerStrategyFactory)7 DegraderLoadBalancerStrategyFactoryV3 (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3)7