参考《互联网 Java 工程师面试突击(第二季)》第20讲 21min
关于CAP: Eureka保证AP:
Eureka各个节点是平等的,部分节点挂掉不影响正常节点的工作,剩余节点依然可以提供注册和查询服务。
Eureka客户端在向某个Eureka服务端注册或发现连接失败时,则会自动切换至其它Eureka服务端节点,只要有一个Eureka服务端节点正常,就能保证注册服务可用(保证可用性),只不过查到的信息可能不是最新的(不保证强一致性)。
Why is it so Slow to Register a Service?
https://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-eureka-server
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 hearbeats).
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.