Search in sources :

Example 1 with RelativeLoadBalancerStrategyFactory

use of com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory in project rest.li by linkedin.

the class D2ClientBuilder method createDefaultLoadBalancerStrategyFactories.

/**
 * Adds the default load balancer strategy factories only if they are not present in the provided factories
 * during the transition period.
 *
 * @return Default mapping of the load balancer strategy names and the strategies
 */
private Map<String, LoadBalancerStrategyFactory<?>> createDefaultLoadBalancerStrategyFactories() {
    final Map<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>> loadBalancerStrategyFactories = new HashMap<>(_config.loadBalancerStrategyFactories);
    final RandomLoadBalancerStrategyFactory randomStrategyFactory = new RandomLoadBalancerStrategyFactory();
    loadBalancerStrategyFactories.putIfAbsent("random", randomStrategyFactory);
    final DegraderLoadBalancerStrategyFactoryV3 degraderStrategyFactoryV3 = new DegraderLoadBalancerStrategyFactoryV3(_config.healthCheckOperations, _config._executorService, _config.eventEmitter, Collections.emptyList());
    loadBalancerStrategyFactories.putIfAbsent("degrader", degraderStrategyFactoryV3);
    loadBalancerStrategyFactories.putIfAbsent("degraderV2", degraderStrategyFactoryV3);
    loadBalancerStrategyFactories.putIfAbsent("degraderV3", degraderStrategyFactoryV3);
    loadBalancerStrategyFactories.putIfAbsent("degraderV2_1", degraderStrategyFactoryV3);
    if (_config.enableRelativeLoadBalancer) {
        final RelativeLoadBalancerStrategyFactory relativeLoadBalancerStrategyFactory = new RelativeLoadBalancerStrategyFactory(_config._executorService, _config.healthCheckOperations, Collections.emptyList(), _config.eventEmitter, SystemClock.instance());
        loadBalancerStrategyFactories.putIfAbsent(RelativeLoadBalancerStrategy.RELATIVE_LOAD_BALANCER_STRATEGY_NAME, relativeLoadBalancerStrategyFactory);
    }
    return loadBalancerStrategyFactories;
}
Also used : RandomLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategyFactory) RelativeLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory) LoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.LoadBalancerStrategyFactory) HashMap(java.util.HashMap) DegraderLoadBalancerStrategyFactoryV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3) RandomLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategyFactory) RelativeLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory) RelativeLoadBalancerStrategy(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)

Example 2 with RelativeLoadBalancerStrategyFactory

use of com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory in project rest.li by linkedin.

the class LoadBalancerStrategyBenchmark method buildRelativeLoadBalancerStrategy.

private static RelativeLoadBalancerStrategy buildRelativeLoadBalancerStrategy() {
    D2RelativeStrategyProperties relativeStrategyProperties = new D2RelativeStrategyProperties();
    ServiceProperties serviceProperties = new ServiceProperties(DUMMY_SERVICE_NAME, DEFAULT_CLUSTER_NAME, DEFAULT_PATH, DEFAULT_STRATEGY_LIST, null, null, null, null, null, null, null, RelativeStrategyPropertiesConverter.toMap(relativeStrategyProperties));
    return new RelativeLoadBalancerStrategyFactory(EXECUTOR_SERVICE, null, new ArrayList<>(), null, SystemClock.instance()).newLoadBalancer(serviceProperties);
}
Also used : ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) RelativeLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory) ArrayList(java.util.ArrayList) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties)

Example 3 with RelativeLoadBalancerStrategyFactory

use of com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory in project rest.li by linkedin.

the class SimpleLoadBalancerStateTest method reset.

public void reset(boolean useSSL, boolean enableRelativeLoadBalancer) {
    _executorService = new SynchronousExecutorService();
    _uriRegistry = new MockStore<>();
    _clusterRegistry = new MockStore<>();
    _serviceRegistry = new MockStore<>();
    _clientFactories = new HashMap<>();
    _loadBalancerStrategyFactories = new HashMap<>();
    if (enableRelativeLoadBalancer) {
        _loadBalancerStrategyFactories.put(RelativeLoadBalancerStrategy.RELATIVE_LOAD_BALANCER_STRATEGY_NAME, new RelativeLoadBalancerStrategyFactory(new ClockedExecutor(), null, Collections.emptyList(), new NoopEventEmitter(), SystemClock.instance()));
    }
    _loadBalancerStrategyFactories.put("random", new RandomLoadBalancerStrategyFactory());
    _loadBalancerStrategyFactories.put("degraderV3", new DegraderLoadBalancerStrategyFactoryV3());
    _loadBalancerStrategyFactories.put(DegraderLoadBalancerStrategyV3.DEGRADER_STRATEGY_NAME, new DegraderLoadBalancerStrategyFactoryV3());
    try {
        _sslContext = SSLContext.getDefault();
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
    _sslParameters = new SSLParameters();
    if (useSSL) {
        _clientFactories.put("https", new SimpleLoadBalancerTest.DoNothingClientFactory());
        _state = new SimpleLoadBalancerState(_executorService, new PropertyEventBusImpl<>(_executorService, _uriRegistry), new PropertyEventBusImpl<>(_executorService, _clusterRegistry), new PropertyEventBusImpl<>(_executorService, _serviceRegistry), _clientFactories, _loadBalancerStrategyFactories, _sslContext, _sslParameters, true, null, SSL_SESSION_VALIDATOR_FACTORY);
    } else {
        _clientFactories.put("http", new SimpleLoadBalancerTest.DoNothingClientFactory());
        _state = new SimpleLoadBalancerState(_executorService, _uriRegistry, _clusterRegistry, _serviceRegistry, _clientFactories, _loadBalancerStrategyFactories);
    }
    FutureCallback<None> callback = new FutureCallback<>();
    _state.start(callback);
    try {
        callback.get();
    } catch (Exception e) {
        Assert.fail("State start failed", e);
    }
}
Also used : SynchronousExecutorService(com.linkedin.d2.discovery.event.SynchronousExecutorService) NoopEventEmitter(com.linkedin.d2.balancer.event.NoopEventEmitter) DegraderLoadBalancerStrategyFactoryV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3) RandomLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategyFactory) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ClockedExecutor(com.linkedin.test.util.ClockedExecutor) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SslSessionNotTrustedException(com.linkedin.r2.transport.http.client.common.ssl.SslSessionNotTrustedException) ExecutionException(java.util.concurrent.ExecutionException) SSLParameters(javax.net.ssl.SSLParameters) RelativeLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory) PropertyEventBusImpl(com.linkedin.d2.discovery.event.PropertyEventBusImpl) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback)

Example 4 with RelativeLoadBalancerStrategyFactory

use of com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory in project rest.li by linkedin.

the class LoadBalancerStrategyTestRunnerBuilder method buildRelativeStrategy.

private LoadBalancerStrategyTestRunner buildRelativeStrategy() {
    if (_serviceProperties == null) {
        setRelativeLoadBalancerStrategies(new D2RelativeStrategyProperties());
    }
    _strategy = new RelativeLoadBalancerStrategyFactory(_clockedExecutor, null, new ArrayList<>(), null, _clockedExecutor).newLoadBalancer(_serviceProperties);
    _transportClients = _uris.stream().map(uri -> new MockTransportClient(_clockedExecutor, _latencyManager, _errorCountManager, uri, INTERVAL_IN_MILLIS, _currentErrorCountMap, _lastRequestCountMap, _callCountMap, _latencySumMap)).collect(Collectors.toList());
    Map<URI, TrackerClient> trackerClientMap = _transportClients.stream().map(transportClient -> {
        // If partition map is not specified, by default we only support one partition
        Map<Integer, PartitionData> partitionDataMap = _partitionDataMap.getOrDefault(transportClient.getUri(), DEFAULT_PARTITION_DATA_MAP);
        return new TrackerClientImpl(transportClient.getUri(), partitionDataMap, transportClient, _clockedExecutor, INTERVAL_IN_MILLIS, (status) -> status >= 500 && status <= 599);
    }).collect(Collectors.toMap(TrackerClient::getUri, trackerClient -> trackerClient));
    return buildInternal(trackerClientMap);
}
Also used : Arrays(java.util.Arrays) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) Callback(com.linkedin.common.callback.Callback) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) HashMap(java.util.HashMap) TransportCallback(com.linkedin.r2.transport.common.bridge.common.TransportCallback) RestResponse(com.linkedin.r2.message.rest.RestResponse) ArrayList(java.util.ArrayList) ClockedExecutor(com.linkedin.test.util.ClockedExecutor) Map(java.util.Map) DegraderConfigFactory(com.linkedin.d2.balancer.strategies.degrader.DegraderConfigFactory) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) URI(java.net.URI) HttpStatus(org.eclipse.jetty.http.HttpStatus) RelativeLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory) RestException(com.linkedin.r2.message.rest.RestException) RestRequest(com.linkedin.r2.message.rest.RestRequest) com.linkedin.d2.loadBalancerStrategyType(com.linkedin.d2.loadBalancerStrategyType) Set(java.util.Set) DegraderTrackerClientImpl(com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl) TrackerClientImpl(com.linkedin.d2.balancer.clients.TrackerClientImpl) PropertyKeys(com.linkedin.d2.balancer.properties.PropertyKeys) Collectors(java.util.stream.Collectors) DegraderLoadBalancerStrategyFactoryV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) TransportResponseImpl(com.linkedin.r2.transport.common.bridge.common.TransportResponseImpl) RequestContext(com.linkedin.r2.message.RequestContext) None(com.linkedin.common.util.None) RelativeStrategyPropertiesConverter(com.linkedin.d2.balancer.config.RelativeStrategyPropertiesConverter) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) RelativeLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map) DegraderTrackerClientImpl(com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl) TrackerClientImpl(com.linkedin.d2.balancer.clients.TrackerClientImpl) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties)

Aggregations

RelativeLoadBalancerStrategyFactory (com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory)4 DegraderLoadBalancerStrategyFactoryV3 (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3)3 None (com.linkedin.common.util.None)2 D2RelativeStrategyProperties (com.linkedin.d2.D2RelativeStrategyProperties)2 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)2 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)2 RandomLoadBalancerStrategyFactory (com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategyFactory)2 ClockedExecutor (com.linkedin.test.util.ClockedExecutor)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Callback (com.linkedin.common.callback.Callback)1 FutureCallback (com.linkedin.common.callback.FutureCallback)1 DegraderTrackerClientImpl (com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl)1 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)1 TrackerClientImpl (com.linkedin.d2.balancer.clients.TrackerClientImpl)1 RelativeStrategyPropertiesConverter (com.linkedin.d2.balancer.config.RelativeStrategyPropertiesConverter)1 NoopEventEmitter (com.linkedin.d2.balancer.event.NoopEventEmitter)1 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)1 PropertyKeys (com.linkedin.d2.balancer.properties.PropertyKeys)1 LoadBalancerStrategyFactory (com.linkedin.d2.balancer.strategies.LoadBalancerStrategyFactory)1