use of com.linkedin.d2.hashConfigType in project rest.li by linkedin.
the class DarkClusterStrategyFactoryImpl method createStrategy.
/**
* In the future, additional strategies can be added, and the logic here can choose the appropriate one based on the config values.
*/
private DarkClusterStrategy createStrategy(String darkClusterName, DarkClusterConfig darkClusterConfig) {
if (darkClusterConfig.hasDarkClusterStrategyPrioritizedList()) {
DarkClusterStrategyNameArray strategyList = darkClusterConfig.getDarkClusterStrategyPrioritizedList();
for (com.linkedin.d2.DarkClusterStrategyName darkClusterStrategyName : strategyList) {
switch(darkClusterStrategyName) {
case RELATIVE_TRAFFIC:
if (RelativeTrafficMultiplierDarkClusterStrategy.isValidConfig(darkClusterConfig)) {
BaseDarkClusterDispatcher baseDarkClusterDispatcher = new BaseDarkClusterDispatcherImpl(darkClusterName, _darkClusterDispatcher, _notifier, _verifierManager);
return new RelativeTrafficMultiplierDarkClusterStrategy(_sourceClusterName, darkClusterName, darkClusterConfig.getMultiplier(), baseDarkClusterDispatcher, _notifier, _facilities.getClusterInfoProvider(), _random);
}
break;
case IDENTICAL_TRAFFIC:
if (IdenticalTrafficMultiplierDarkClusterStrategy.isValidConfig(darkClusterConfig)) {
BaseDarkClusterDispatcher baseDarkClusterDispatcher = new BaseDarkClusterDispatcherImpl(darkClusterName, _darkClusterDispatcher, _notifier, _verifierManager);
return new IdenticalTrafficMultiplierDarkClusterStrategy(_sourceClusterName, darkClusterName, darkClusterConfig.getMultiplier(), baseDarkClusterDispatcher, _notifier, _facilities.getClusterInfoProvider(), _random);
}
break;
case CONSTANT_QPS:
if (_rateLimiterSupplier == null) {
LOG.error("Dark Cluster {} configured to use CONSTANT_QPS strategy, but no rate limiter provided during instantiation. " + "No Dark Cluster strategy will be used!", darkClusterName);
break;
}
if (ConstantQpsDarkClusterStrategy.isValidConfig(darkClusterConfig)) {
BaseDarkClusterDispatcher baseDarkClusterDispatcher = new BaseDarkClusterDispatcherImpl(darkClusterName, _darkClusterDispatcher, _notifier, _verifierManager);
ConstantQpsRateLimiter rateLimiter = _rateLimiterSupplier.get();
rateLimiter.setBufferCapacity(darkClusterConfig.getDispatcherMaxRequestsToBuffer());
rateLimiter.setBufferTtl(darkClusterConfig.getDispatcherBufferedRequestExpiryInSeconds(), ChronoUnit.SECONDS);
return new ConstantQpsDarkClusterStrategy(_sourceClusterName, darkClusterName, darkClusterConfig.getDispatcherOutboundTargetRate(), baseDarkClusterDispatcher, _notifier, _facilities.getClusterInfoProvider(), rateLimiter);
}
break;
default:
break;
}
}
}
return new NoOpDarkClusterStrategy();
}
use of com.linkedin.d2.hashConfigType in project rest.li by linkedin.
the class ConsistentHashRingSimulatorConfig method toSimulator.
/**
* Creates a {@link ConsistentHashRingSimulator} from the config
*
* @return A ConsistentHashRingSimulator instance
*/
public ConsistentHashRingSimulator toSimulator() {
String hashingAlgorithm = getHashingAlgorithm();
double balancingFactor = getBoundedLoadBalancingFactor();
DegraderLoadBalancerStrategyConfig degraderLoadBalancerStrategyConfig = getConfig(hashingAlgorithm, balancingFactor);
RingFactory<String> testFactory = new DelegatingRingFactory<>(degraderLoadBalancerStrategyConfig);
Map<String, Integer> pointsMap = new HashMap<>();
int serverID = 0;
for (Server server : getServers()) {
for (int i = 0; i < server.getNumber(); i++) {
pointsMap.put("Server" + serverID, server.getPoints());
serverID += 1;
}
}
DegraderLoadBalancerStrategyConfig consistentConfig = getConfig(hashingAlgorithm, Double.POSITIVE_INFINITY);
RingFactory<String> consistentFactory = new DelegatingRingFactory<>(consistentConfig);
List<com.linkedin.d2.balancer.util.hashing.simulator.Client> clients = new ArrayList<>();
int clientID = 0;
for (ConsistentHashRingSimulatorConfig.Client client : getClients()) {
for (int i = 0; i < client.getNumber(); i++) {
clients.add(new com.linkedin.d2.balancer.util.hashing.simulator.Client("Client" + clientID, client, getShuffleRequests()));
clientID++;
}
}
int serverCapacity = getServerCapacity();
return new ConsistentHashRingSimulator(testFactory, consistentFactory, clients, pointsMap, serverCapacity);
}
use of com.linkedin.d2.hashConfigType in project rest.li by linkedin.
the class PartitionPropertiesConverterTest method testHashMD5PartitionProperties.
@Test
public void testHashMD5PartitionProperties() {
final String partitionKeyRegex = "/foo/bar/(\\d+)";
final int partitionCount = 8;
final HashBasedPartitionProperties.HashAlgorithm hashAlgorithm = HashBasedPartitionProperties.HashAlgorithm.MD5;
PartitionProperties partitionProperties = new HashBasedPartitionProperties(partitionKeyRegex, partitionCount, hashAlgorithm);
D2ClusterPartitionConfiguration.PartitionTypeSpecificData data = new D2ClusterPartitionConfiguration.PartitionTypeSpecificData();
data.setHashAlgorithm(com.linkedin.d2.HashAlgorithm.MD5);
D2ClusterPartitionConfiguration partitionConfig = new D2ClusterPartitionConfiguration().setType(PartitionTypeEnum.HASH).setPartitionKeyRegex(partitionKeyRegex).setPartitionCount(partitionCount).setPartitionTypeSpecificData(data);
Assert.assertEquals(PartitionPropertiesConverter.toProperties(partitionConfig), partitionProperties);
Assert.assertEquals(PartitionPropertiesConverter.toConfig(partitionProperties), partitionConfig);
}
Aggregations