标签:本地 模式 wal http请求 负载均衡算法 增量更新 ast 完成 ecs
有两个比较重要的配置
服务过期时间配置:eureka.instance.lease-expiration-duration-in-seconds
服务刷新时间配置:eureka.instance.lease-renewal-interval-in-seconds
Eureka注册中心有一个Map来保存所有的服务及映射的机器信息:
private final ConcurrentHashMap<String, Map<String, Lease<InstanceInfo>>> registry
= new ConcurrentHashMap<String, Map<String, Lease<InstanceInfo>>>();
而ResponseCache又分为了两个部分,一个是ReadWriteMap,一个是ReadOnlyMap。
服务在启动完成后,会启动一个线程,去执行注册信息,具体代码在InstanceInfoReplicator中,这个类实现了Runnable:
public void run() {
try {
discoveryClient.refreshInstanceInfo();
Long dirtyTimestamp = instanceInfo.isDirtyWithTime();
if (dirtyTimestamp != null) {
discoveryClient.register();
instanceInfo.unsetIsDirty(dirtyTimestamp);
}
} catch (Throwable t) {
logger.warn("There was a problem with the instance info replicator", t);
} finally {
Future next = scheduler.schedule(this, replicationIntervalSeconds, TimeUnit.SECONDS);
scheduledPeriodicRef.set(next);
}
}
private ConcurrentLinkedQueue<RecentlyChangedItem> recentlyChangedQueue =
new ConcurrentLinkedQueue<RecentlyChangedItem>();
之所以要维护一个这样的队列,是为了方便服务增量更新服务列表的信息。
在服务启动时,会创建一个后台心跳任务,定时去续约服务信息:
scheduler.schedule(
new TimedSupervisorTask(
"heartbeat",
scheduler,
heartbeatExecutor,
renewalIntervalInSecs,
TimeUnit.SECONDS,
expBackOffBound,
new HeartbeatThread()
),
renewalIntervalInSecs, TimeUnit.SECONDS);
HeartbeatThread就是心跳线程,这里把它包装成了一个TimedSupervisorTask,
注意:scheduler.schedule方法只会在延时一定时间后执行一次提交的任务,所以这里会延时执行,同时,虽然schedule只会执行一次,但是TimedSupervisorTask里封装了循环调用的信息,所以其实是定时调用了。
而HeartbeatThread非常简单:
private class HeartbeatThread implements Runnable {
public void run() {
if (renew()) {
lastSuccessfulHeartbeatTimestamp = System.currentTimeMillis();
}
}
}
服务停止前会向服务治理中心发一个服务取消的请求,用于注销服务。收到服务注销的请求之后,服务治理中心会做以下操作:
标签:本地 模式 wal http请求 负载均衡算法 增量更新 ast 完成 ecs
原文地址:https://www.cnblogs.com/bolang100/p/11819230.html