了解Spring Cloud Eureka Server的自我保存和续订阈值 [英] Understanding Spring Cloud Eureka Server self preservation and renew threshold

查看:116
本文介绍了了解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和两个私有).检查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上发现了这个问题,并且解决方案通过使用在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.

但是我看到以下消息:

关闭了自我保存模式.这可能无法立即保护 在发生网络问题或其他问题时出现问题.

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

服务器cfg:

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 cfg:

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秒1次的频率将其租约续签到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): represents how many renews received from Eureka instance in last minute

续订阈值: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实例将每分钟发送 4 个更新到Eureka服务器,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.

因此在上例中,由于阈值为5,所以激活了SELF PRESERVATION MODE,但是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:

自我保存模式"旨在避免不良的网络连接失败. Eureka实例A和B之间的连接性很好,但是B由于连接中断而未能在短时间内将其租约续期到Eureka服务器,此时Eureka服务器不能简单地将实例B踢出去.尽管B可用,但A不会从Eureka服务器获得可用的注册服务.因此,这是自我保存模式"的目的,最好将其打开.

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,则续订始终低于阈值.

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. 如果只想在演示/开发环境中进行部署,则可以将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天全站免登陆