Eureka caching mechanism

One, Eureka Server

Here Insert Picture Description

Eureka Server existence of three variables :( Registry, readWriteCacheMap, readOnlyCacheMap ) Save the service registration information, by default scheduled task to synchronize every 30s will readWriteCacheMap readOnlyCacheMap, clean up every 60s over 90s not to renew node, Eureka Client updates every 30s from readOnlyCacheMap service registration information, and UI service registration information from the registry update

Three-level cache

Cache Types of Explanation
registry ConcurrentHashMap Real-time updates , AbstractInstanceRegistry class member variables, UI client requests service registration information is here
readWriteCacheMap Guava Cache/LoadingCache Real-time updates , ResponseCacheImpl class member variables, buffer time 180 seconds
readOnlyCacheMap ConcurrentHashMap Cycle update , ResponseCacheImpl class member variable, by default every 30s from readWriteCacheMap update, Eureka client update here from the default service registration information, can be configured to update directly from readWriteCacheMap

Cache configuration

Configuration default Explanation
eureka.server.useReadOnlyResponseCache true Client from readOnlyCacheMap update data, false is skipped readOnlyCacheMap updates directly from readWriteCacheMap
eureka.server.responsecCacheUpdateIntervalMs 30000 readWriteCacheMap update to readOnlyCacheMap cycle, default 30s
eureka.server.evictionIntervalTimerInMs 60000 清理未续约节点周期,默认60s
eureka.instance.leaseExpirationDurationInSeconds 90 清理未续约节点超时时间,默认90s

二、Eureka Client

Eureka Client存在两种角色:服务提供者服务消费者,作为服务消费者一般配合Ribbon或Feign(Feign内部使用Ribbon)使用。Eureka Client启动后,作为服务提供者立即向Eureka Server注册,默认情况下每30s续约;作为服务消费者立即向Server全量更新服务注册信息,默认情况下每30s增量更新服务注册信息;Ribbon延时1s向Client获取使用的服务注册信息,默认每30s更新使用的服务注册信息,只保存状态为UP的服务。

二级缓存

缓存 类型 说明
localRegionApps AtomicReference 周期更新,类DiscoveryClient成员变量,Eureka Client保存服务注册信息,启动后立即向Server全量更新,默认每30s增量更新
upServerListZoneMap ConcurrentHashMap 周期更新,类LoadBalancerStats成员变量,Ribbon保存使用且状态为UP的服务注册信息,启动后延时1s向Client更新,默认每30s更新

缓存相关配置

配置 默认 说明
eureka.instance.leaseRenewalIntervalInSeconds 30 Eureka Client续约周期,默认30s
eureka.client.registryFetchIntervalSeconds 30 Eureka Client incremental update period, default 30s (normally incremental update, timeout, or the like is inconsistent with the Server side where the total amount Update)
ribbon.ServerListRefreshInterval 30000 Ribbon update cycle, default 30s
Published 177 original articles · won praise 407 · views 80000 +

Guess you like

Origin blog.csdn.net/qq_40378034/article/details/103850144