标签:默认 ram cli ini tar can user vat key
1. InstanceInfoFactory
2. com.netflix.discovery.DiscoveryClient
3. DefaultEurekaServerContext : Initializing ...
4. cluster.PeerEurekaNodes : Adding new peer nodes
5. AbstractInstanceRegistry : Finished initializing remote region registries.
6. DefaultEurekaServerContext : Initialized
7. EurekaServiceRegistry : Registering application EUREKASERVER with eureka with status UP
8. EurekaServerBootstrap : Initialized server context
this.initEurekaEnvironment();
this.initEurekaServerContext();
((PeerAwareInstanceRegistry)registry).openForTraffic(applicationInfoManager, registryCount);
public void openForTraffic(ApplicationInfoManager applicationInfoManager, int count) {
this.expectedNumberOfClientsSendingRenews = count;
this.updateRenewsPerMinThreshold();
public void evict(long additionalLeaseMs) {
.....
int registrySize = (int)this.getLocalRegistrySize();
int registrySizeThreshold = (int)((double)registrySize * this.serverConfig.getRenewalPercentThreshold());
int evictionLimit = registrySize - registrySizeThreshold;
int toEvict = Math.min(expiredLeases.size(), evictionLimit);
if (toEvict > 0) {
logger.info("Evicting {} items (expired={}, evictionLimit={})", new Object[]{toEvict, expiredLeases.size(), evictionLimit});
Random random = new Random(System.currentTimeMillis());
this.evictionTimer.schedule((TimerTask)this.evictionTaskRef.get(), this.serverConfig.getEvictionIntervalTimerInMs(), this.serverConfig.getEvictionIntervalTimerInMs());
register --> readWriteCacheMap --> readonlyCacheMap
每次注册的时候 更新register ,失效readWriteCacheMap中的相关服务
readWriteCacheMap readonly 之间 ,定时任务Timer 每隔30s 更新一次 (从readWriteCacheMap 中取数据放入readonlyCacheMap 主要提供读,高可用性)。不是强一致性
eureka.server.response-cache-update-interval-ms=1000
优化点 response-cache-update-interval-ms 配置时间间隔小一点,可以更快速的从readWriteCacheMap 取到数据,放入readonlyCacheMap
优化点 eureka.server.use-read-only-response-cache=false
三级缓存 默认为 true , false直接从readWriteCacheMap 中取数据,不去readonlyCacheMap,readonlyCacheMap数据一致性不高。
@VisibleForTesting
ResponseCacheImpl.Value getValue(Key key, boolean useReadOnlyCache) {
ResponseCacheImpl.Value payload = null;
try {
if (useReadOnlyCache) {
ResponseCacheImpl.Value currentPayload = (ResponseCacheImpl.Value)this.readOnlyCacheMap.get(key);
if (currentPayload != null) {
payload = currentPayload;
} else {
payload = (ResponseCacheImpl.Value)this.readWriteCacheMap.get(key);
this.readOnlyCacheMap.put(key, payload);
}
} else {
payload = (ResponseCacheImpl.Value)this.readWriteCacheMap.get(key);
}
} catch (Throwable var5) {
logger.error("Cannot get value for key : {}", key, var5);
}
return payload;
}
private final ConcurrentHashMap<String, Map<String, Lease<InstanceInfo>>> registry = new ConcurrentHashMap();
@POST
@Consumes({"application/json", "application/xml"})
public Response addInstance(InstanceInfo info, @HeaderParam("x-netflix-discovery-replication") String isReplication) {
public void register(final InstanceInfo info, final boolean isReplication) {
this.handleRegistration(info, this.resolveInstanceLeaseDuration(info), isReplication);
super.register(info, isReplication);
}
public void register(InstanceInfo registrant, int leaseDuration, boolean isReplication) {
try {
this.read.lock();
.......
Lease<InstanceInfo> existingLease = (Lease)((Map)gMap).get(registrant.getId());
synchronized(this.lock) {
if (this.expectedNumberOfClientsSendingRenews > 0) {
++this.expectedNumberOfClientsSendingRenews;
this.updateRenewsPerMinThreshold();
}
}
-----------------------------------------------------------------------------------------
Lease<InstanceInfo> lease = new Lease(registrant, leaseDuration);
-----------------------------------------------------------------------------------------
........
-----------------------------------------------------------------------------------------
this.invalidateCache(registrant.getAppName(), registrant.getVIPAddress(), registrant.getSecureVipAddress());
-----------------------------------------------------------------------------------------
logger.info("Registered instance {}/{} with status {} (replication={})", new Object[]{registrant.getAppName(), registrant.getId(), registrant.getStatus(), isReplication});
} finally {
this.read.unlock();
}
}
服务信息 注入Lease中, 由于每30s心跳后进行服务续约,这个数据结构便于服务续约 (直接调用方法,而不用进行get、set)
服务续约 和 服务下线
public void renew() {
this.lastUpdateTimestamp = System.currentTimeMillis() + this.duration;
}
public void cancel() {
if (this.evictionTimestamp <= 0L) {
this.evictionTimestamp = System.currentTimeMillis();
}
public void invalidate(String appName, @Nullable String vipAddress, @Nullable String secureVipAddress) {
@Import({EurekaServerInitializerConfiguration.class})
@ConditionalOnBean({Marker.class})
implements SmartLifecycle
SmartLifecycle extends Lifecycle
Lifecycle -------> springframework.context
EurekaServerInitializerConfiguration 实现了Lifecycle中 start();
标签:默认 ram cli ini tar can user vat key
原文地址:https://www.cnblogs.com/JMrLi/p/12964519.html