主要通过expectedNumberOfRenewsPerMin,numberOfRenewsPerMinThreshold(expectedNumberOfClientsSendingRenews新版本,做了优化,具体这里不做分析,有兴趣者可自行研究)这两个值判断是否进入自我保护模式,当每分钟收到的心跳数量小于期望收到的心跳数量,EurekaServer便会进入自我保护模式,不会剔除任何一个服务,直到心跳回复正常后退出自我保护模式。
自我保护模式默认是开启的。服务注册和下线都会更新对应的值:expectedNumberOfRenewsPerMin和expectedNumberOfClientsSendingRenews,配置RenewalPercentThreshold默认值:0.85,expectedClientRenewalIntervalSeconds:30秒。
触发自我保护模式:Renews (last min) < Renews threshold。假如当前有10个服务,那么每分钟续约数Renews (last min)=10 * 2=20,阈值:20 * 0.85=17,这个是正常的不会触发。一旦出现Renews (last min)小于17,则会触发自我保护模式。
synchronized (lock) { if (this.expectedNumberOfClientsSendingRenews > 0) { // Since the client wants to register it, increase the number of clients sending renews // 期望客户端发送续约数增1 this.expectedNumberOfClientsSendingRenews = this.expectedNumberOfClientsSendingRenews + 1; // 更新每分钟续约阈值 updateRenewsPerMinThreshold(); } } // 更新每分钟续约阈值:期望客户端续约数*2(60/30秒默认)*百分比(0.85),即每分钟续约数量 protected void updateRenewsPerMinThreshold() { this.numberOfRenewsPerMinThreshold = (int) (this.expectedNumberOfClientsSendingRenews * (60.0 / serverConfig.getExpectedClientRenewalIntervalSeconds()) * serverConfig.getRenewalPercentThreshold()); }
synchronized (lock) { if (this.expectedNumberOfClientsSendingRenews > 0) { // Since the client wants to cancel it, reduce the number of clients to send renews // 期望客户端发送续约数减1 this.expectedNumberOfClientsSendingRenews = this.expectedNumberOfClientsSendingRenews - 1; // 更新每分钟续约阈值 updateRenewsPerMinThreshold(); } }
本文仅供学习!所有权归属原作者。侵删!文章来源: 搬运工来架构
文章评论