In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
What is the principle of Eureka in SpringCloud components, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
1. Analysis of Eureka service governance principles.
1. About service registration:
(1) as mentioned earlier, the service registry maintains a service inventory table, which stores all service names and all service instance information corresponding to that service name (such as IP address, port number, etc.). It can be quickly thought that the service list should be a Map structure.
(2) then, the service provider registers the service with the service center (that is, the Eureka server) through the Eureka client. This process actually sends its service name, IP address, port number and other information to the service registry for preservation.
two。 About service discovery (or service synchronization):
(1) Service registries and service providers:
After the service provider registers with the service registry, it always maintains a service list synchronization with the service center, that is, all the service list data in the Eureka server are obtained through the Eureka client, which is mainly realized through the configured registry address.
Eureka.client.serviceUrl.defaultZone= http://localhost:8081/eureka/
Therefore, in the case of a stand-alone service registry, once the service registry is down, the accuracy of service discovery cannot be guaranteed, but the service discovery can still be done, because a copy of the service list data will be cached locally to the service provider. Even if the service registry is hung up, the service discovery and invocation can still be carried out through this cached data, but the accuracy cannot be guaranteed. It is possible that a service has been offline or a new service instance has been online, which is imperceptible.
In other words, the Eureka server synchronizes the service list data to each Eureka client, which ensures that a service is offline or online and can be sensed by other services in time, thus ensuring service discovery. But the problem is that the service inventory data synchronization method of Eureka will lead to poor data consistency.
(2) Eureka service registry cluster: to put it bluntly, the Eureka cluster model regards the service registry itself as a service. If the service registry nodes in the cluster register with each other, they can synchronize the service list between the nodes and ensure high availability. Even if a service registry node dies, other service registry nodes can also carry out service governance.
3. About Service Renewal:
After service registration, the service provider must also make a "heartbeat" request to the service registry from time to time, which is used to tell the service registry that it is "alive" to prevent Eureka from removing the service from the service list and excluding it from the service list. This is the service renewal operation.
Service renewal has two important configuration attributes that can be adjusted according to the needs of the project.
Eureka.instance.lease-expiration-duration-in-seconds=90eureka.instance.lease-renewal-interval-in-seconds=30
Eureka.instance.lease-expiration-duration-in-seconds. This parameter indicates the time to determine service failure (in seconds). Default is 90 seconds.
The eureka.instance.lease-renewal-interval-in-seconds parameter indicates the interval between calls for the service renewal task, that is, how often the request for service renewal is made (in seconds). The default is 30 seconds.
You need to pay attention to the configuration of these two parameters, because if hundreds of services are registered and hundreds of instances are deployed for each service, it can be calculated that the number of daily requests made by service governance alone can reach tens of millions per day. Use an example to make a simple calculation.
By default, 100 services are deployed on 20 servers, which is equivalent to a total of 2000 service instances.
Each service instance requests to pull the registry twice per minute, and sends a heartbeat twice per minute, that is, four requests per minute to the service registry. 2000 service instances have 8000 requests per minute. Estimated to be about 150 times per second.
Then 8000,240,60 = 11.52 million requests will be made to the service registry in one day, that is, tens of millions of requests per day.
Therefore, these two configuration parameters also need to be adjusted appropriately. As for why the service registry can withstand tens of millions of daily requests, the later analysis of the source code is described in detail.
4. Service offline: during the operation of the whole system, a service may be offline due to a variety of reasons, so for those service callers, these services must not be called. Therefore, the service center must remove these offline services.
5. For the service consumer: the service consumer is usually also a service. Like the service provider, the service consumer needs to obtain the list of services available in the service registry through the Eureka client, and then the service can be invoked according to the list. The specific invocation and configuration will be explained in combination with Ribbon and Feign later. Service consumers mainly need to configure two parameters
Eureka.client.registry-fetch-interval-seconds=30: this parameter represents the interval between updating the service list from the service registry, in seconds. The default is to get the service list every 30 seconds.
Eureka.client.fetch-registry=true: whether the parameter table gets the service list. This parameter must be true, and default is true.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.