Spring Cloud Eureka 注册服务慢怎么办?
介绍
通常情况下,服务注册到 Eureka Server 的过程较慢。在开发或测试时,常常希望能够加快此过程,从而提升工作效率。
Spring Cloud官方文档详细描述了该问题的原因并提供了解决方案
Why is it so Slow to Register a Service?
Being an instance also involves a periodic heartbeat to the registry (via the client’s serviceUrl) with default duration 30 seconds. A service is not available for discovery by clients until the instance, the server and the client all have the same metadata in their local cache (so it could take 3 heartbeats). You can change the period using eureka.instance.leaseRenewalIntervalInSeconds and this will speed up the process of getting clients connected to other services. In production it’s probably better to stick with the default because there are some computations internally in the server that make assumptions about the lease renewal period.
翻译Why is it so Slow to Register a Service
作为实例还涉及到与注册中心的周期性心跳,默认持续时间为30秒(通过serviceUrl)。在实例、服务器、客户端都在本地缓存中具有相同的元数据之前,服务不可用于客户端发现(所以可能需要3次心跳)。你可以使用eureka.instance.leaseRenewalIntervalInSeconds 配置,这将加快客户端连接到其他服务的过程。在生产中,最好坚持使用默认值,因为在服务器内部有一些计算,他们对续约做出假设。
配置示例
eureka:
client:
healthcheck:
enabled:true
instance:
#每5秒去服务端续约
lease-renewal-interval-in-seconds: 5
总结
综上,要想解决服务注册慢的问题,只需将eureka.instance.leaseRenewalIntervalInSec- onds 设成一个更小的值。该配置用于设置 Eureka Client 向 Eureka Server 发送心跳的时间间隔,默认是 30,单位是s。在生产环境中,建议坚持使用默认值。
CSDN_码404:Spring Cloud Eureka 注册服务慢怎么办?
https://www.code404.icu/1376.html