了解 Spring Cloud Eureka Server 自保和更新阈值 [英] Understanding Spring Cloud Eureka Server self preservation and renew threshold

查看:68
本文介绍了了解 Spring Cloud Eureka Server 自保和更新阈值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是开发微服务的新手,虽然我已经研究了一段时间,阅读了 Spring 的文档和 Netflix 的文档.

I am new to developing microservices, although I have been researching about it for a while, reading both Spring's docs and Netflix's.

我已经开始了一个简单的项目可在 Github 上使用.它基本上是一个 Eureka 服务器(Archimedes)和三个 Eureka 客户端微服务(一个公共 API 和两个私有 API).查看 github 的自述文件以获得详细说明.

I have started a simple project available on Github. It is basically a Eureka server (Archimedes) and three Eureka client microservices (one public API and two private). Check github's readme for a detailed description.

关键是,当一切都在运行时,我希望如果其中一个私有微服务被杀死,Eureka 服务器会意识到并将其从注册表中删除.

The point is that when everything is running I would like that if one of the private microservices is killed, the Eureka server realizes and removes it from the registry.

在Stackoverflow上发现了这个问题,解决方案通过使用enableSelfPreservation:false 在 Eureka 服务器配置中.执行此操作一段时间后,被终止的服务会按预期消失.

I found this question on Stackoverflow, and the solution passes by using enableSelfPreservation:false in the Eureka Server config. Doing this after a while the killed service disappears as expected.

但是我可以看到以下消息:

However I can see the following message:

自我保护模式已关闭.这可能无法保护实例网络/其他问题时到期.

THE SELF PRESERVATION MODE IS TURNED OFF.THIS MAY NOT PROTECT INSTANCE EXPIRY IN CASE OF NETWORK/OTHER PROBLEMS.

1.自我保护的目的是什么?doc 指出,客户端可以获取不再存在的实例".那么什么时候开启/关闭它是可取的?

1. What is the purpose of the self preservation? The doc states that with self preservation on "clients can get the instances that do not exist anymore". So when is it advisable to have it on/off?

此外,当自我保护开启时,您可能会在 Eureka Server 控制台警告中收到一条未完成的消息:

Furthermore, when self preservation is on, you may get an outstanding message in the Eureka Server console warning:

紧急情况!EUREKA 可能不正确 索赔实例在他们不是.更新少于阈值,因此实例不会过期只是为了安全.

EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.

现在,继续使用 Spring Eureka 控制台.

Now, going on with the Spring Eureka Console.

Lease expiration enabled    true/false
Renews threshold    5
Renews (last min)   4

我遇到过阈值计数的奇怪行为:当我单独启动 Eureka Server 时,阈值是 1.

I have come across a weird behaviour of the threshold count: when I start the Eureka Server alone, the threshold is 1.

2.我有一个 Eureka 服务器并配置了 registerWithEureka: false 以防止它在另一台服务器上注册.那么,为什么它会出现在阈值计数中?

2. I have a single Eureka server and is configured with registerWithEureka: false to prevent it from registering on another server. Then, why does it show up in the threshold count?

3.对于我开始的每个客户端,阈值计数增加 +2.我猜是因为他们每分钟发送 2 条更新消息,对吗?

4.Eureka 服务器从不发送更新,因此最后一分钟更新总是低于阈值.这正常吗?

renew threshold 5
rewnews last min: (client1) +2 + (client2) +2 -> 4

服务器配置:

server:
  port: ${PORT:8761}

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  server:
    enableSelfPreservation: false
#   waitTimeInMsWhenSyncEmpty: 0

客户端 1 配置:

spring:
  application:
    name: random-image-microservice

server:
  port: 9999

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
    healthcheck:
      enabled: true

推荐答案

遇到和@codependent一样的问题,我google了很多,做了一些实验,在这里我来贡献一些关于Eureka服务器和实例如何工作的知识.

I got the same question as @codependent met, I googled a lot and did some experiment, here I come to contribute some knowledge about how Eureka server and instance work.

每个实例都需要以每 30 秒一次的频率更新对 Eureka Server 的租约,可以在 eureka.instance.leaseRenewalIntervalInSeconds 中定义.

Every instance needs to renew its lease to Eureka Server with frequency of one time per 30 seconds, which can be define in eureka.instance.leaseRenewalIntervalInSeconds.

Renews (last min):表示最后一分钟从 Eureka 实例收到的更新次数

Renews (last min): represents how many renews received from Eureka instance in last minute

Renews threshold:Eureka 服务器每分钟期望从 Eureka 实例收到的更新.

Renews threshold: the renews that Eureka server expects received from Eureka instance per minute.

例如,如果 registerWithEureka 设置为 false,则 eureka.instance.leaseRenewalIntervalInSeconds 设置为 30 并运行 2 个 Eureka 实例.两个Eureka实例每分钟会向Eureka服务器发送4次更新,Eureka服务器最小阈值为1(代码编写),所以阈值为5 (这个数字将乘以一个因子 eureka.server.renewalPercentThreshold,稍后将讨论).

For example, if registerWithEureka is set to false, eureka.instance.leaseRenewalIntervalInSeconds is set to 30 and run 2 Eureka instance. Two Eureka instance will send 4 renews to Eureka server per minutes, Eureka server minimal threshold is 1 (written in code), so the threshold is 5 (this number will be multiply a factor eureka.server.renewalPercentThreshold which will be discussed later).

自保模式:如果续订(最后一分钟)小于续订阈值,则会激活自保模式.

SELF PRESERVATION MODE: if Renews (last min) is less than Renews threshold, self preservation mode will be activated.

所以在上面的例子中,SELF PRESERVATION MODE 被激活,因为阈值是 5,但 Eureka 服务器只能接收 4 个更新/分钟.

So in upper example, the SELF PRESERVATION MODE is activated, because threshold is 5, but Eureka server can only receive 4 renews/min.

  1. 问题 1:

SELF PRESERVATION MODE 旨在避免不良的网络连接故障.Eureka 实例 A 和 B 之间的连通性是好的,但是 B 由于连接问题无法在短时间内续约到 Eureka 服务器,此时 Eureka 服务器不能简单地踢出实例 B.如果是,则实例尽管 B 可用,但 A 将无法从 Eureka 服务器获得可用的注册服务.所以这就是SELF PRESERVATION MODE的目的,最好开启.

The SELF PRESERVATION MODE is design to avoid poor network connectivity failure. Connectivity between Eureka instance A and B is good, but B is failed to renew its lease to Eureka server in a short period due to connectivity hiccups, at this time Eureka server can't simply just kick out instance B. If it does, instance A will not get available registered service from Eureka server despite B is available. So this is the purpose of SELF PRESERVATION MODE, and it's better to turn it on.

  1. 问题 2:

代码中写了最小阈值1.registerWithEureka 设置为 false,因此不会有 Eureka 实例注册,阈值为 1.

The minimal threshold 1 is written in the code. registerWithEureka is set to false so there will be no Eureka instance registers, the threshold will be 1.

在生产环境中,一般我们部署两个Eureka服务器,registerWithEureka会设置为true.所以阈值为 2,Eureka 服务器每分钟会更新租约两次,所以 RENEWALS ARE LESSER THAN THRESHOLD 不会有问题.

In production environment, generally we deploy two Eureka server and registerWithEureka will be set to true. So the threshold will be 2, and Eureka server will renew lease to itself twice/minute, so RENEWALS ARE LESSER THAN THRESHOLD won't be a problem.

  1. 问题 3:

是的,你是对的.eureka.instance.leaseRenewalIntervalInSeconds 定义了每分钟发送到服务器的更新次数,但它会乘以上面提到的因子eureka.server.renewalPercentThreshold,默认值为0.85.

Yes, you are right. eureka.instance.leaseRenewalIntervalInSeconds defines how many renews sent to server per minute, but it will multiply a factor eureka.server.renewalPercentThreshold mentioned above, the default value is 0.85.

  1. 问题 4:

是的,这是正常的,因为阈值初始值设置为1.所以如果registerWithEureka设置为false,renews 总是低于阈值.

Yes, it's normal, because the threshold initial value is set to 1. So if registerWithEureka is set to false, renews is always below threshold.

对此我有两个建议:

  1. 部署两个 Eureka 服务器并启用 registerWithEureka.
  2. 如果你只是想在demo/dev环境下部署,你可以将eureka.server.renewalPercentThreshold设置为0.49,这样当你单独启动一个Eureka服务器时,阈值为0.莉>
  1. Deploy two Eureka server and enable registerWithEureka.
  2. If you just want to deploy in demo/dev environment, you can set eureka.server.renewalPercentThreshold to 0.49, so when you start up a Eureka server alone, threshold will be 0.

这篇关于了解 Spring Cloud Eureka Server 自保和更新阈值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆