A brief introduction to Eureka's implementation principle and self-protection mechanism

Eureka is a service registration and discovery component developed based on the Restful API in the Java language, and is open sourced by Netflix. Eureka follows the AP principle. At present, Eureka is only open source to the 1.X version, and the 2.X version has been announced as closed source.

Eureka uses the Server/Client model for design:

  • Server plays the role of the service registry, provides the functions of service registration and discovery for clients, maintains related information of clients registered with itself, and provides interfaces for clients to obtain information about other services in the registry.
  • The Client registers the information about its own services to the Server in a certain way, and maintains the consistency of its own information within the normal range, so that other services can find itself, and at the same time, it can obtain other service information that it depends on through the Server. Complete the service call.

Server does not conduct elections and does not have Leader. It is a decentralized architecture. The nodes are all peer-to-peer, and the availability is improved through mutual registration, and the ultimate consistency of data is achieved through data copy.

In a cluster environment, if a Server node goes down, Client's request will be automatically switched to the new Server node. When the down server is restored, Eureka will again incorporate it into the server cluster management.

Self-protection mechanism

By default, if the server does not receive the heartbeat of a service instance within a certain period of time (the default period is 30 seconds), the server will log out the instance (the default is 90 seconds). If more than 85% of the nodes do not have a normal heartbeat within 15 minutes, then Eureka believes that there is a network failure between the client and the registry and initiates a self-protection mechanism:

  1. Eureka no longer removes from the registry the service that expires because it has not received a heartbeat for a long time;
  2. Eureka can still accept new service registration and query requests, but it will not be synchronized to other nodes (that is, to ensure that the current node is still available);
  3. When the network is stable, the newly registered information of the current instance will be synchronized to other nodes;

The self-protection mechanism is the key to Eureka following the AP principle and ensuring availability. As long as one server is still available, it can provide external services, but strong consistency is not guaranteed, and the internal data of the server may not be up to date.

Guess you like

Origin blog.csdn.net/Anenan/article/details/115349477