Turn off Eureka self-protection mode

Reprinted Disclaimer: The source of the article is to carry sacks of teenager

Tips: It is not recommended to turn off Eureka's self-protection mode in the production environment

What is protected mode

  The protection mode is mainly used for protection in a network partition scenario between a group of clients and Eureka Server. Once in the protected mode, Eureka Server will try to protect the information in its service registry and will no longer delete the data in the service registry, that is, it will not log out any microservice instances.

  When we see the following prompt on the homepage of Eureka Server service, it means that Eureka Server has entered the protection mode at this time.
Insert picture description here

Why does Eureka Server enter the protection mode

  By default, if Eureka Server does not receive the heartbeat of a microservice instance within a certain period of time, Eureka Server will log off the instance. (默认是90s)

  However 当网络分区发生故障(延迟、卡顿、拥挤)时, there is no normal communication between microservices and Eureka Server 在这种情况下微服务本身其实是健康的,本来是不应该注销这个服务的. At this time, Eureka will use the "self-protection mode" to solve this problem.

  Eureka's self-protection mechanism is in the CAP principle AP 分支. That is to satisfy: 可用性, 分区容错性.

The CAP principle is also known as the CAP theorem, which refers to the consistency (Consistency), availability (Availability), and partition tolerance (Partition tolerance) in a distributed system. The CAP principle means that these three elements can only achieve two at most at the same time, and it is impossible to take care of all three.

How to disable self protection

  In Eureka, the self-protection mode is the default 开启of. Here is just to demonstrate how to close. It is not recommended to turn off Eureka's self-protection mode in a production environment .

1. Eureka Server operation

Add the following configuration information:

eureka:
  server:
    #关闭自我保护机制,保证不可用服务被及时剔除
    enable-self-preservation: false
    #清理无效节点的时间间隔,默认60000毫秒,即60秒 (此处时间间隔设置为2s)
    eviction-interval-timer-in-ms: 2000

 
  
  

At this point, when you start Eureka Server, you will see a clear prompt message.
Insert picture description here

2. Eureka Client operation

Add the following configuration information:

eureka:
  instance:
    # Eureka客户端向服务端发送心跳的时间间隔,单位为妙(默认是30s)
    lease-renewal-interval-in-seconds: 1
    # Eureka服务端在收到最后一次心跳后的等待时间上限,单位为秒(默认90s),超时将移除服务
    lease-expiration-duration-in-seconds: 2

 
  
  

At this point, the configuration has been completed.

3. Test results

Insert picture description here
  In this case, we manually stop the microservice, and Eureka Server will remove it from the service after the 2s timeout. It will not give any chance, when faced with network 延迟、卡顿、拥挤time, this operation is clearly unfriendly.

Therefore, in most cases, it is recommended not to turn off Eureka's self-protection mode.

Guess you like

Origin blog.csdn.net/m0_37989980/article/details/108460794