spring-cloud-commons
spring-cloud-commons copied to clipboard
Weight-based LoadBalancer strategy
Hi Team,
Is your feature request related to a problem? Please describe. I want to load balance traffic between target service's instances using tag and corresponding weight, provided by the configuration. That feature would help me to freely redirect significant part of traffic to a group of instances while the rest to e.g. instances with new feature. The best example of such strategy of LB is blue-green deployment.
Describe the solution you'd like
spring:
cloud:
consul:
discovery:
server-list-query-tags: # probably not the best config key but it's only example
service-name:
- tag: group-1
weight: 80
- tag: group-2
weigth: 20
Additional context Example of such implemention in Consul splitting configuration:
Kind = "service-splitter"
Name = "<service-name>"
Splits = [
{
Weight = 10
ServiceSubset = "blue"
},
{
Weight = 90
ServiceSubset = "green"
},
]
Please, let me know what you think about such feature.
Best regards
Simple implementation I've written using Ribbon:
public class WeightedRoundRobinLoadBalancer extends com.netflix.loadbalancer.BaseLoadBalancer {
public WeightedRoundRobinLoadBalancer(Properties propertiesWithWeights) {
super("Operator weighted LB", new RoundRobinRule(), null);
buildFromGivenWeights(propertiesWithWeights);
}
/**
* Confront with com.netflix.loadbalancer.ILoadBalancer.addServer() JavaDoc
*
*/
private void buildFromGivenWeights(Properties propertiesWithWeights) {
for (var w: propertiesWithWeights.get("weights")) {
var weightServer = new WeightServer(/**some metadata for this server*/);
for (var i = 0; i < w.getValue(); ++i) {
addServer(weightServer);
}
}
}
}
@jizhuozhi is working on this issue.
@jizhuozhi is working on this issue.
Received