Spring-eureka Source Interpretation----Why a service is perceived by other services for up to two minutes

Source: Internet
Author: User

Eureka Wiki has a word on the effect that it may take up to 2 minutes for a service to be perceived by other services, but the document does not explain why there are 2 minutes. In fact, this is caused by a three-place cache + a delay.

first, the HTTP response is cached by the Eureka. ApplicationResourceyou can see a row in the 109 row of the Controller class in Eureka

String payLoad = responseCache.get(cacheKey);
    • 1

Invocation, the function of the method in which the code resides getApplication() is to respond to the client's request for a service message:

// 从cache中拿响应数据if (payLoad != null) {       logger.debug("Found: {}", appName); return Response.ok(payLoad).build();} else { logger.debug("Not Found: {}", appName); return Response.status(Status.NOT_FOUND).build();}

In the above code, the responseCache reference is ResponseCache a type, the type is an interface, its get() method first will go to the cache to query the data, if not the generation of data return (that is, to actually query the registration list), and the cache is valid time is 30s. In other words, the client's response to Eureka is not necessarily instantaneous, and most of the time it just caches information.

second, the Eureka client has also made 30s caches of registered information that it has acquired . That is, the service will cache the result after the first query to the available service address through the Eureka client, and will not actually initiate an HTTP request to Eureka the next time it is called.

* * Again, the Load Balancer component Ribbon also has a 30s cache. **ribbon will get the list of services from the Eureka client mentioned above and then cache the results 30s.

Finally, if you are not using these components in the Spring cloud environment (Eureka, Ribbon), your service will not register with Eureka immediately after it is started, but will need to wait until the heartbeat request is first sent . The heartbeat request's send interval is also 30s. (Spring Cloud has made changes to this and will register as soon as the service starts)

These four 30 seconds are the reason why the official wiki has a maximum of 2 minutes to write service registrations.

Spring-eureka Source Interpretation----Why a service is perceived by other services for up to two minutes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.