eureka服务发现过慢的优化

 
低版本
版本信息:
  spring boot 1.5.3
  spring-cloud-dependencies:Edgware.SR3
 
#writeRead缓存定时同步到ReadOnly的缓存
eureka.server.responseCacheUpdateIntervalMs =30000 



#拉取服务注册表的间隔
eureka.client.registryFetchIntervalSeconds = 30000
#心跳的间隔
eureka.client.leaseRenewalIntervalInSeconds = 30 
#定时检查心跳
eureka.server.evictionIntervalTimerInMs = 60000
#如果超过多少秒没检测到,视为服务down机
eureka.instance.leaseExpirationDurationInSeconds = 90

  

高版本
spring boot 2.1.6
spring cloud :Greenwich.SR1

eureka服务器设置:

eureka:
  server:
    enable-self-preservation: false   #关闭自我保护机制
    response-cache-update-interval-ms: 5000   #writeRead缓存定时同步到ReadOnly的缓存
    eviction-interval-timer-in-ms: 5000    #定时检查心跳

 

client的设置:

eureka:
  instance:
    lease-renewal-interval-in-seconds: 5 #发送心跳
    lease-expiration-duration-in-seconds: 8  #这个实例多少秒没检查到心跳视为下线
  client:
    registry-fetch-interval-seconds: 10  #定时拉取注册表

  

案例分析:客户端设置的参数的效果
 
我的服务端设置成这样 
eureka:
    enable-self-preservation: false
    response-cache-update-interval-ms: 5000
    eviction-interval-timer-in-ms: 1000
 
我的客户端设置成这样:
eureka:
  instance:
    lease-renewal-interval-in-seconds: 30
    lease-expiration-duration-in-seconds: 8
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
    registry-fetch-interval-seconds: 10

  

1. 可以看到Running the evict task with compensationTime 0ms 这一句话是1秒一次,这个就是代表定时检查心跳的间隔
2.可以看到up->cancelled时间大概是8秒 这就是我设置的lease-expiration-duration-in-seconds的时间,up->up时间大概是30秒,这就是 lease-renewal-interval-in-seconds的时间

 
 
原文地址:https://www.cnblogs.com/dabenxiang/p/14619722.html