Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ribbon load balance algorithms

I am using Spring Cloud with NetflixOSS in my microservice project. Also, I am using Ribbon with Feign Client as my client side load balancer. I was wondering, is there any possibility to implement or choose different types of load balancing algorithms for Ribbon? Because as I understood, the default is round robin.

Thanks in advance!

like image 759
branko terzic Avatar asked Dec 06 '16 10:12

branko terzic


People also ask

What load balancing strategy does ribbon follow?

The Ribbon mainly provides client-side load balancing algorithms. It is a client-side load balancer that provides control over the behavior of HTTP and TCP client. The important point is that when we use Feign, the Ribbon also applies.

How does a ribbon load balancer work?

A central concept in Ribbon is that of the named client. Each load balancer is part of an ensemble of components that work together to contact a remote server on demand, and the ensemble has a name that you give it as an application developer (for example, by using the @FeignClient annotation).

What is the difference between Zuul and ribbon?

Regarding Zuul, there is a RibbonRoutingFilter that routes your request to an actual service instance. RibbonRoutingFilter is using Ribbon to choose a server from the list that is given from your configuration or from Eureka. So if you want to use Zuul as a load-balanced reverse proxy, Zuul needs Ribbon.


1 Answers

Yes, it is possible. See the docs for full details how to customize. For a @FeignClient("foo") and a random load-balancing rule you could do:

@Configuration
@RibbonClient(name = "foo", configuration = FooConfiguration.class)
public class TestConfiguration {
}

@Configuration
public class FooConfiguration {
    @Bean
    public IRule ribbonRule(IClientConfig config) {
        IRule rule = new RandomRule();
        rule.initWithNiwsConfig(config);
        return rule;
    }
}

See the ribbon wiki for some more details and here for more implementations.

like image 57
spencergibb Avatar answered Nov 15 '22 07:11

spencergibb