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