Self-protection background
First of all, we need to understand about the Eureka registration center that all nodes in Eureka are equal, and there is no concept of roles in ZK. Even if N-1 nodes are lost, it will not affect the normal operation of other nodes.
By default, if Eureka Server does not receive a heartbeat from a microservice instance within a certain time (default 90 seconds), Eureka Server will remove the instance. However, when a network partition failure occurs, the microservice cannot communicate normally with Eureka Server, and the microservice itself is running normally. This microservice should not be removed at this time, so a self-protection mechanism is introduced.
Self-protection mechanism
Official definition of self-protection mechanism: https://github.com/Netflix/eureka/wiki/Understanding-Eureka-Peer-to-Peer-Communication
Self-protection mode is a security protection measure for abnormal network fluctuations. Using self-protection mode can make the Eureka cluster run more robustly and stably.
The working mechanism of the self-protection mechanism is that if more than 85% of the client nodes do not have normal heartbeat within 15 minutes, then Eureka believes that the client and the registration center have a network failure, and Eureka Server automatically enters the self-protection mechanism. At this time, the following situations will occur:
1. Eureka Server no longer removes services that should expire because they have not received a heartbeat for a long time. /
2. Eureka Server can still accept registration and query requests for new services, but will not be synchronized to other nodes to ensure that the current node is still available. /
3. When the network is stable, the new registration information of Eureka Server will be synchronized to other nodes.
Therefore, Eureka Server can deal with the situation where some nodes are lost due to network failure, and will not cause half of them to become paralyzed like ZK.
Self-protection switch
Eureka self-protection mechanism, true to enable/false by configuring eureka.server.enable-self-preservation to disable the self-protection mechanism. The default is turned on. It is recommended to open this configuration in the production environment.
Development environment configuration
If you want to automatically remove service failure in the development environment, you only need to modify the following configuration.
1. The registration center closes the self-protection mechanism and modifyes the time for checking the invalid service.
eureka: server: enable-self-preservation: false eviction-interval-timer-in-ms: 3000
2. Microservice modifications reduce the time of service heartbeat.
# Default 90 seconds lease-expiration-duration-in-seconds: 10# Default 30 seconds lease-renewal-interval-in-seconds: 3
The above configuration is recommended to use the default time configuration in the production environment. I hope it will be helpful to everyone's learning, and I hope everyone will support Wulin.com more.