Eureka 学习笔记1:服务端实例缓存

版本 awsVersion = '1.11.277'

缓存 类型
registry ConcurrentHashMap<String, Map<String, Lease<InstanceInfo>>> AbstractInstanceRegistry成员变量
readWriteCacheMap LoadingCache ResponseCacheImpl成员变量
readOnlyCacheMap ConcurrentMap<Key, Value> ResponseCacheImpl成员变量

registry

java 复制代码
// com.netflix.eureka.registry.AbstractInstanceRegistry
protected void postInit() {
    evictionTaskRef.set(new EvictionTask());
    evictionTimer.schedule(
        evictionTaskRef.get(),
        serverConfig.getEvictionIntervalTimerInMs(),
        // 配置evictionIntervalTimerInMs
        serverConfig.getEvictionIntervalTimerInMs());
}
class EvictionTask extends TimerTask {
    public void run() {
        long compensationTimeMs = getCompensationTimeMs();
        evict(compensationTimeMs);
    }
    // ...
}

evictionIntervalTimerInMs 指定清理未续约服务实例的时间间隔,默认 60s


readWriteCacheMap

java 复制代码
// com.netflix.eureka.registry.ResponseCacheImpl
this.readWriteCacheMap =
    CacheBuilder.newBuilder()
        // 配置initialCapacityOfResponseCache
        .initialCapacity(serverConfig.getInitialCapacityOfResponseCache())
        // 配置responseCacheAutoExpirationInSeconds
        .expireAfterWrite(serverConfig.getResponseCacheAutoExpirationInSeconds(), TimeUnit.SECONDS)

initialCapacityOfResponseCache 指定 readWriteCacheMap 缓存容量大小,默认 1000

responseCacheAutoExpirationInSeconds 指定 readWriteCacheMap 缓存有效时间,默认 180s


readOnlyCacheMap

java 复制代码
// com.netflix.eureka.registry.ResponseCacheImpl
// 配置shouldUseReadOnlyResponseCache
if (shouldUseReadOnlyResponseCache) {
    timer.schedule(getCacheUpdateTask(),
        new Date(((System.currentTimeMillis() / responseCacheUpdateIntervalMs) * responseCacheUpdateIntervalMs)
                            + responseCacheUpdateIntervalMs),
        // 配置responseCacheUpdateIntervalMs
        responseCacheUpdateIntervalMs);
}

private TimerTask getCacheUpdateTask() {
    return new TimerTask() {
        public void run() {
            // ...    
            for (Key key : readOnlyCacheMap.keySet()) {
                CurrentRequestVersion.set(key.getVersion());
                Value cacheValue = readWriteCacheMap.get(key);
                Value currentCacheValue = readOnlyCacheMap.get(key);
                if (cacheValue != currentCacheValue) {
                    readOnlyCacheMap.put(key, cacheValue);
                }
             }
        }
    };
}

shouldUseReadOnlyResponseCache 指定是否使用 readOnlyCacheMap,默认 true

responseCacheUpdateIntervalMs 指定 readOnlyCacheMap 更新的时间间隔,默认 30s

相关推荐
斯普信专业组16 小时前
Docker 常用命令与时区配置指南
docker·容器·eureka
return(b,a%b);2 天前
docker拉取失败,更换docker的源
docker·容器·eureka
Knight_AL2 天前
Docker 加载镜像时报 no space left on device 的彻底解决方案
docker·容器·eureka
hu1j3 天前
[HTB] 靶机学习(十二)Eureka
学习·安全·web安全·网络安全·云原生·eureka
没有bug.的程序员3 天前
Eureka 注册中心原理与服务注册发现机制
java·spring·云原生·eureka·架构·注册中心·服务注册发现
Aomnitrix3 天前
我的容器管理革命:从命令行地狱到可视化操控的蜕变
云原生·eureka
ABdolphin4 天前
Spring-cloud 主键Eureka
java·云原生·eureka
INFINI Labs6 天前
使用 Docker Compose 轻松实现 INFINI Console 离线部署与持久化管理
java·docker·eureka·devops·docker compose·console·easyserach
天地之于壹炁兮6 天前
Docker革命:软件开发的集装箱时代
docker·容器·eureka