Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can spring-cloud and ribbon perform DNS-based load balancing?

Cloudfoundry plans to add support for DNS A records that maps to multiple IPs (one per app container instance), see docs-proposal. I wonder whether spring-cloud discovery coupled with ribbon can support DNS-based client load balancing.

The spring-cloud DiscoveryClient does not seem to do DNS resolutions, it manages host names

The ribbon load balancing library supports a list of FQDNs through the ListOfServers property.

But I could not spot documentation related to DNS lookup of the specified servers: i.e. would Ribbon load balance across IP address if a DNS A/AAA record (fetched from the ListOfServers ) returns multiple ip addresses ?

Where would I need to configure DNS caching directives ? Would this is JVM-wide in the java.security support or can I manage this as client-slide load balancing options (from ribbon) ?

like image 712
Guillaume Berche Avatar asked Oct 03 '17 10:10

Guillaume Berche


2 Answers

Ribbon does not perform any DNS lookups, it returns an entry from the ServerList as-is (either an IP or a name).

You don't need Ribbon for DNS-based load balancing; the OS resolver will rotate between the available IP addresses for each lookup. Just make sure not to cache DNS.

For a more complex load balancing you'll need to resolve DNS into a list of IPs and then pass that to Ribbon.

like image 193
rustyx Avatar answered Sep 20 '22 15:09

rustyx


If you are using spring cloud eureka service, every service instance registers at eureka. This means you can host multipe instances of the same service at the same host and eureka knows every single service.

If you use ribbon for client based loadbalancing so ribbon queries eureka for all instances of a services and knows every single instance of a service.

This way ribbon can choose to connect to every single instance. Because of this there is no need for multiple DNS A records. It's counterproductive to use multiple DNS A records because ribbon can't distinguish mutliple instances of a service by DNS any more. In this case I would suggest to set eureka.instance.preferIpAddress to true, to distinguish mutliple instances.

As far as I know ribbon supports 2 working modes, RoundRobinRule and AvailabilityFilteringRule.

A good introtuction you can find in the book "Spring microservices".

like image 39
slowjack2k Avatar answered Sep 20 '22 15:09

slowjack2k