Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

How to override the ribbon.serverListRefreshInterval default value in Spring Cloud Ribbon?

Ask Question

I wrote a simple Spring Cloud Ribbon application, to call a REST service which was registered in Eureka.

But how to override the ribbon.serverListRefreshInterval value? The default value is 30 seconds, I'd like to reduce the time interval.

Thanks in advance.

myService.ribbon.ServerListRefreshInterval=10000

where myService is the name of your destination microservice.

UPDATE:

After some source code digging I found out that LoadBalancerBuilder calls:

@Deprecated
public ZoneAwareLoadBalancer(IClientConfig clientConfig, IRule rule,
        IPing ping, ServerList<T> serverList, ServerListFilter<T> filter) {
    super(clientConfig, rule, ping, serverList, filter);

whose super is:

@Deprecated
public DynamicServerListLoadBalancer(IClientConfig clientConfig, IRule rule, IPing ping, 
        ServerList<T> serverList, ServerListFilter<T> filter) {
    this(
            clientConfig,
            rule,
            ping,
            serverList,
            filter,
            new PollingServerListUpdater()

Notice the PollingServerListUpdater constructors:

private static int LISTOFSERVERS_CACHE_REPEAT_INTERVAL = 30 * 1000; // msecs;
public PollingServerListUpdater() {
    this(LISTOFSERVERS_CACHE_UPDATE_DELAY, LISTOFSERVERS_CACHE_REPEAT_INTERVAL);
public PollingServerListUpdater(IClientConfig clientConfig) {
    this(LISTOFSERVERS_CACHE_UPDATE_DELAY, getRefreshIntervalMs(clientConfig));

The second one would allow us to override the default refresh interval. However it's the first one that's called, so it ignores the property.

UPDATE 2:

There's an open issue about this: https://github.com/spring-cloud/spring-cloud-netflix/issues/1304

is your service registered exactly as Compute-Service in your Eureka server? Mind the capital letters. – codependent Sep 19, 2016 at 9:16 Sure, double checked that there's no typo error, will attach some screen shots for your reference later – Anson Wang Sep 19, 2016 at 14:44

@codependent

After put below configuration in application.yml, it looked the configuration didnt take effect.

Compute-Service:   
  ribbon:  
    ServerListRefreshInterval: 1000

I observed that the instances list has been updated in Ribbon side (through eureka.client.registry-fetch-interval-seconds parameter), however Ribbon still point out a dead instance:

[tbeatExecutor-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_RIBBON-CONSUMER/192.168.1.101:Ribbon-Consumer:3333 - Heartbeat status: 200  
[freshExecutor-0] com.netflix.discovery.DiscoveryClient    : Got delta update with apps hashcode UP_2_  
[freshExecutor-0] com.netflix.discovery.DiscoveryClient    : Added instance 192.168.1.101:Ribbon-Consumer:3333 to the existing apps in region null  
[freshExecutor-0] com.netflix.discovery.DiscoveryClient    : Deleted instance 192.168.1.101:Compute-Service:2222 to the existing apps  
[freshExecutor-0] com.netflix.discovery.DiscoveryClient    : Added instance 192.168.1.101:Compute-Service:1111 to the existing apps in region null  
[freshExecutor-0] com.netflix.discovery.DiscoveryClient    : The total number of instances fetched by the delta processor : 3  
[freshExecutor-0] com.netflix.discovery.DiscoveryClient    : The total number of all instances in the client now is 2  
[freshExecutor-0] com.netflix.discovery.DiscoveryClient    : Completed cache refresh task for discovery. All Apps hash code is Local region apps hashcode: UP_2_, is fetching remote regions? false  
[nio-3333-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://Compute-Service/add": Connection refused; nested exception is java.net.ConnectException: Connection refused] with root cause 

192.168.1.101:Compute-Service:1111 was right service instance, while 192.168.1.101:Compute-Service:2222 was dead instance, obviously Ribbon still pointed to the dead instance, which meant Ribbon ServerList cache was not refreshed.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.