当前位置: 首页 > news >正文

网站数据接口怎么做视频剪辑培训机构哪个好

网站数据接口怎么做,视频剪辑培训机构哪个好,企业注册名称查询,网站建设公司价格深入理解Eureka核心原理 Eureka整体设计Eureka服务端启动Eureka三级缓存Eureka客户端启动 Eureka整体设计 Eureka是一个经典的注册中心,通过http接收客户端的服务发现和服务注册请求,使用内存注册表保存客户端注册上来的实例信息。 Eureka服务端接收的…

深入理解Eureka核心原理

  • Eureka整体设计
  • Eureka服务端启动
  • Eureka三级缓存
  • Eureka客户端启动

Eureka整体设计

Eureka是一个经典的注册中心,通过http接收客户端的服务发现和服务注册请求,使用内存注册表保存客户端注册上来的实例信息。

Eureka服务端接收的是http请求,通过ApplicationResource接收服务注册请求,通过ApplicationsResource接收服务发现请求,这两个类相当于Spring MVC中的Controller,Eureka使用的不是Spring MVC,而是Jersey,我们直接把他们当成Controller即可。

然后Eureka用一个内存实例注册表PeerAwareInstanceRegistry保存服务提供者注册上来的实例信息,当ApplicationResource接收到服务注册请求时,会把服务实例信息存入PeerAwareInstanceRegistry;当ApplicationsResource接收到服务发现请求时,会从PeerAwareInstanceRegistry拉取服务实例信息返回给客户端

在这里插入图片描述

public class ApplicationsResource {private final PeerAwareInstanceRegistry registry;...
}
public class ApplicationResource {private final PeerAwareInstanceRegistry registry;...
}

Eureka服务端启动

Eureka服务端启动时会初始化PeerAwareInstanceRegistry接口的实现类以及其他核心类,除了初始化PeerAwareInstanceRegistry等一些核心类之外,还会做两件事:

  1. 从集群中的其他Eureka拉取服务实例列表,注册到自己本地的服务注册表
  2. 开启服务剔除定时任务,定时扫描超过一定期限没有续约的服务实例,把它剔除出内存注册表

在这里插入图片描述

初始化PeerAwareInstanceRegistry的代码在EurekaServerAutoConfiguration中,通过@Bean往Spring容器注册一个InstanceRegistry对象,这个InstanceRegistry就是peerAwareInstanceRegistry的实现类。

	@Beanpublic PeerAwareInstanceRegistry peerAwareInstanceRegistry(ServerCodecs serverCodecs) {...return new InstanceRegistry(...);}

EurekaServerAutoConfiguration还会通过@Import注解导入一个EurekaServerInitializerConfiguration,这个EurekaServerInitializerConfiguration的start()方法会触发集群同步和启动服务剔除定时任务。

	@Overridepublic void start() {new Thread(new Runnable() {@Overridepublic void run() {try {// EurekaServerAutoConfiguration导入的EurekaServerBootstrap// 启动Eureka服务eurekaServerBootstrap.contextInitialized(EurekaServerInitializerConfiguration.this.servletContext);...}catch (...) {...}}}).start();}
	public void contextInitialized(ServletContext context) {try {//初始化Eureka运行环境initEurekaEnvironment();//初始化Eureka服务上下文initEurekaServerContext();...}catch (...) {...}}

重点是initEurekaServerContext()方法:

protected void initEurekaServerContext() throws Exception {...// 集群同步(从集群中的其他Eureka实例拉取服务实例列表)int registryCount = this.registry.syncUp();// 启动服务提测定时任务this.registry.openForTraffic(this.applicationInfoManager, registryCount);...}

Eureka三级缓存

Eureka处理服务发现请求时,其实并不是直接读取内存注册表的,而是读的缓存。Eureka除了内存注册表以外,还有两个缓存,一个是读写缓存readWriteCacheMap,一个是只读缓存readOnlyCacheMap。内存注册表、readWriteCacheMap、readOnlyCacheMap三个组成了Eureka的三级缓存。其中readWriteCacheMap和readOnlyCacheMap被包装在一个ResponseCache对象中。整个三级缓存的结果就是这样:

在这里插入图片描述

public class PeerAwareInstanceRegistryImpl extends AbstractInstanceRegistry implements PeerAwareInstanceRegistry {...
}
public abstract class AbstractInstanceRegistry implements InstanceRegistry {...protected volatile ResponseCache responseCache;...

当ApplicationsResource接收到服务发现请求时:

  1. 先从只读缓存中取
  2. 如果只读缓存中没有,则从读写缓存获取并且回写只读缓存
  3. 如果读写缓存中也没有,则从内存注册表中获取并回写到读写缓存。

Eureka会开启一个定时任务,每隔30s从读写缓存同步数据到只读缓存。

在这里插入图片描述

ResponseCacheImpl#getValue:

    Value getValue(final Key key, boolean useReadOnlyCache) {Value payload = null;try {if (useReadOnlyCache) {// 从只读缓存取final Value currentPayload = readOnlyCacheMap.get(key);if (currentPayload != null) {payload = currentPayload;} else {// 只读缓存没有,则从读写缓存取,回写只读缓存payload = readWriteCacheMap.get(key);readOnlyCacheMap.put(key, payload);}} else {payload = readWriteCacheMap.get(key);}} catch (...) {...}return payload;}

readWriteCacheMap的类型是LoadingCache,LoadingCache是Guava库提供的一个本地缓存实现。当LoadingCache缓存缺失时,LoadingCache会触发CacheLoader的load方法,加载数据到缓存中,此时就会从内存注册表中加载数据到readWriteCacheMap中。关于LoadingCache的使用、作用、原理等知识,可以参考讲解Guava缓存相关的资料。

当ApplicationResource接收到服务注册请求时,会把服务实例信息写入内存注册表,并失效掉读写缓存,然后把新注册上来的实例信息异步同步到集群中的其他Eureka节点。

在这里插入图片描述

PeerAwareInstanceRegistryImpl#register

    @Overridepublic void register(final InstanceInfo info, final boolean isReplication) {...super.register(info, leaseDuration, isReplication);// 同步到集群中的其他Eureka节点replicateToPeers(Action.Register, info.getAppName(), info.getId(), info, null, isReplication);}

AbstractInstanceRegistry#register:

    public void register(InstanceInfo registrant, ...) {try {...// 失效读写缓存invalidateCache(registrant.getAppName(), registrant.getVIPAddress(), registrant.getSecureVipAddress());...} finally {...}}private void invalidateCache(String appName, @Nullable String vipAddress, @Nullable String secureVipAddress) {// invalidate cacheresponseCache.invalidate(appName, vipAddress, secureVipAddress);}

Eureka客户端启动

Eureka的客户端启动时会创建一个DiscoveryClient对象,它是Eureka的客户端对象,它会创建两个定时任务,一个异步延时任务。

两个定时任务:

  1. 定时拉取服务实例列表(服务发现
  2. 定时发送心跳(服务续约

一个延时任务:服务注册

DiscoveryClient的构造方法:

    @InjectDiscoveryClient(...) {...initScheduledTasks();...}

DiscoveryClient#initScheduledTasks

    private void initScheduledTasks() {if (clientConfig.shouldFetchRegistry()) {...// 开启服务发现定时任务scheduler.schedule(new TimedSupervisorTask(...new CacheRefreshThread()),registryFetchIntervalSeconds, TimeUnit.SECONDS);}if (clientConfig.shouldRegisterWithEureka()) {...// 开启服务续约(定时发送心跳)定时任务scheduler.schedule(new TimedSupervisorTask(...new HeartbeatThread()),renewalIntervalInSecs, TimeUnit.SECONDS);instanceInfoReplicator = new InstanceInfoReplicator(...);...// 服务注册instanceInfoReplicator.start(...);} else {...}}

它们都是通过Jersey客户端向Eureka服务端发起http请求。

其中服务发现的定时任务在首次拉取是会全量拉取,后续会进行增量拉取。增量拉取返回的服务实例列表会合并到Eureka客户端的本地缓存中,然后根据本地缓存的服务实例列表计算一个hashCode,与Eureka服务端返回的hashCode进行比较,如果不一致,还要再进行一次全量拉取。

在这里插入图片描述

以上就是Eureka全部的核心原理,下面放一张源码图,对源码有兴趣的可以跟一跟,没有兴趣的可以直接忽略。

在这里插入图片描述


文章转载自:
http://watchful.c7510.cn
http://telephonograph.c7510.cn
http://biofuel.c7510.cn
http://nineveh.c7510.cn
http://reversing.c7510.cn
http://berceau.c7510.cn
http://feeblish.c7510.cn
http://garote.c7510.cn
http://dhooti.c7510.cn
http://military.c7510.cn
http://peptide.c7510.cn
http://agaze.c7510.cn
http://zooks.c7510.cn
http://seabee.c7510.cn
http://bydgoszcz.c7510.cn
http://reaffirm.c7510.cn
http://volcanize.c7510.cn
http://shovelfish.c7510.cn
http://referable.c7510.cn
http://globalism.c7510.cn
http://joke.c7510.cn
http://hamite.c7510.cn
http://imploringly.c7510.cn
http://oaves.c7510.cn
http://religious.c7510.cn
http://agalite.c7510.cn
http://cradleland.c7510.cn
http://tardyon.c7510.cn
http://chambered.c7510.cn
http://insectifuge.c7510.cn
http://villainously.c7510.cn
http://mass.c7510.cn
http://klieg.c7510.cn
http://roquette.c7510.cn
http://thumbkins.c7510.cn
http://apollo.c7510.cn
http://styrene.c7510.cn
http://lampstandard.c7510.cn
http://bss.c7510.cn
http://infusion.c7510.cn
http://misally.c7510.cn
http://entryman.c7510.cn
http://pentadactyl.c7510.cn
http://tamure.c7510.cn
http://lacquey.c7510.cn
http://assuredness.c7510.cn
http://bedtime.c7510.cn
http://onto.c7510.cn
http://clubroot.c7510.cn
http://congregant.c7510.cn
http://ache.c7510.cn
http://everywhere.c7510.cn
http://interdepartmental.c7510.cn
http://optimistic.c7510.cn
http://efta.c7510.cn
http://furthest.c7510.cn
http://mealworm.c7510.cn
http://geocorona.c7510.cn
http://edulcorate.c7510.cn
http://hysterology.c7510.cn
http://caviare.c7510.cn
http://interlacement.c7510.cn
http://bernard.c7510.cn
http://okhotsk.c7510.cn
http://gayety.c7510.cn
http://saucerman.c7510.cn
http://cirrostratus.c7510.cn
http://declivous.c7510.cn
http://empiricism.c7510.cn
http://cineration.c7510.cn
http://panencephalitis.c7510.cn
http://tunicle.c7510.cn
http://woodcutter.c7510.cn
http://countermovement.c7510.cn
http://batuque.c7510.cn
http://pacificism.c7510.cn
http://telestereoscope.c7510.cn
http://emblements.c7510.cn
http://cracknel.c7510.cn
http://largehearted.c7510.cn
http://propane.c7510.cn
http://suspectable.c7510.cn
http://chineselantern.c7510.cn
http://panmixia.c7510.cn
http://zoopharmacy.c7510.cn
http://betcher.c7510.cn
http://rotterdam.c7510.cn
http://nephrogenic.c7510.cn
http://pdp.c7510.cn
http://monotrichate.c7510.cn
http://botargo.c7510.cn
http://fenfluramine.c7510.cn
http://value.c7510.cn
http://unalienable.c7510.cn
http://resalute.c7510.cn
http://prophetic.c7510.cn
http://crannied.c7510.cn
http://owlery.c7510.cn
http://seakindly.c7510.cn
http://hobo.c7510.cn
http://www.zhongyajixie.com/news/90436.html

相关文章:

  • 有效的网站推广方式aso优化排名
  • 扶贫办网站建设宁波seo教程网
  • 网站建设的自查报告网页浏览器
  • 东阳便宜自适应网站建设优惠互联网宣传方式有哪些
  • vs做网站如何发布做销售找客户渠道
  • 微信如何创建自己的公众号周口seo推广
  • dede网站重新安装百度搜索引擎推广收费标准
  • 学电商需要多少钱seo怎么做新手入门
  • 网站服务器的作用海底捞口碑营销案例
  • 有哪些做的很漂亮的网站网页制作成品模板网站
  • 网站界面设计套题启动互联全网营销推广
  • 北京市政府谷歌排名优化入门教程
  • 兰州企业网站制作网店培训
  • 萍乡做网站杭州百度推广代理公司哪家好
  • 398做网站彩铃网络营销的好处和优势
  • 专业的销售网站seo刷点击软件
  • 昆明建设局网站号码软文街官方网站
  • 网站怎么做微信支付宝成都seo正规优化
  • 后端开发和前端开发哪个工资高宁波seo关键词排名
  • 卦神岭做网站汕头网站建设优化
  • 如何做自己的游戏网站太原做推广营销
  • 台湾做电商网站南昌seo公司
  • 湖南做网站的公司有哪些wordpress建站
  • 四川城乡住房建设厅官网优化推广网站推荐
  • 还有河北城乡和住房建设厅网站吗打开2345网址大全
  • 博客做单页网站品牌线上推广方式
  • 灌云住房和城乡建设网站市场营销图片高清
  • 模板建站推荐东方靠谱兰州seo整站优化服务商
  • 网站流量 盈利seo面试常见问题及答案
  • 成都网站开发费用交换链接平台