Spring Cloud Eureka self-protection mechanisms actual analysis

A few days ago I shared stack Spring Cloud Eureka long series of articles in the Java technology stack micro-channel public number:

Among them, we may specific logic about self-protection mechanism is not particularly clear, long stack today on a detailed analysis and practical look, self-protection mechanism in the end is how it works.

Now we turn to protection mechanisms:

Focus on two important parameters in the upper right corner:

parameter Explanation
Renews threshold Eureka Server receive the expected total number of heartbeats per minute client instance
Renews (last min) The last minute of the total number of heartbeats received Eureka Server

I value as shown here:

Renews threshold    6
Renews (last min)   8

The 6 and 8 respectively, how come?

First look at the default setting of these two parameters, taken from " the Spring Cloud Eureka common configuration in detail ," the article:

eureka.server.renewal-percent-threshold:
represents Eureka Server open the coefficient of self-protection, default: 0.85.

eureka.instance.lease-renewal-interval-in- seconds:
indicates Eureka Client to send the heartbeat Eureka Server (default 30 seconds), if not received within a lease-expiration-duration-in- seconds time specified heartbeat, the instance is removed.

There are four registration instance, protection factor: 0.85, heartbeat frequency: 30 seconds (twice per minute), calculated as follows:

Renews threshold = 4 * 2 * 0.85 = 6.8(取整为:6)
Renews (last min) = 4 * 2 = 8

Now delete a distribution center to test instance:

Warning:

EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.

说明现在 Eureka Server 已经进行保护模式了,并且我删除的那个实例并不会从注册列表中移除,保护机制生效成功。

由此可知:Eureka Server 在一分钟内如果没有收到 6 个以上的心跳,即:Renews threshold >= Renews (last min),如果保护机制已开启的情况下,则会开启保护机制。

为什么移除一个实例后,Renews threshold 还是 6 呢,算出来应该是 5,这是因为 Eureka Server 还没刷新这个值,默认 15 分钟刷新一次,可以通过设计以下值进行调整:

eureka.server.renewal-threshold-update-interval-ms=900000

了解了心跳策略和保护机制后,对注册中心的日常维护就会有很多帮助。

好了,今天的分享就到这里了,建议转发收藏,不再迷路。

后续会分享更多 Eureka 高级玩法,栈长正在拼命撰写中……关注Java技术栈微信公众号可获取及时推送。在公众号后台回复:cloud,获取栈长整理的更多的 Spring Cloud 教程,都是实战干货,以下仅为部分预览。

  • Spring Cloud 配置中心高可用搭建
  • Spring Cloud 多版本如何选择
  • Spring Cloud 是什么,和 Dubbo 对比
  • Spring Cloud 注册中心高可用搭建
  • Spring Cloud Eureka 自我保护机制
  • ……

本文原创首发于微信公众号:Java技术栈(id:javastack),关注公众号在后台回复 "cloud" 可获取更多 Spring Cloud 教程,转载请原样保留本信息。

Guess you like

Origin www.cnblogs.com/javastack/p/10930373.html