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()));
}
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);
}
Aggregations