spring-cloud-commons icon indicating copy to clipboard operation
spring-cloud-commons copied to clipboard

Weight-based LoadBalancer strategy

Open mario45211 opened this issue 3 years ago • 3 comments

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

mario45211 avatar Feb 03 '22 13:02 mario45211

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

mario45211 avatar Mar 07 '22 09:03 mario45211

@jizhuozhi is working on this issue.

OlgaMaciaszek avatar Jun 10 '22 09:06 OlgaMaciaszek

@jizhuozhi is working on this issue.

Received

jizhuozhi avatar Jun 10 '22 09:06 jizhuozhi