Programing

Spring Cloud Eureka Server 자체 보존 및 갱신 임계 값 이해

lottogame 2020. 10. 25. 11:29
반응형

Spring Cloud Eureka Server 자체 보존 및 갱신 임계 값 이해


나는 마이크로 서비스 개발에 익숙하지 않지만 Spring의 문서와 Netflix의 문서를 모두 읽으며 한동안 조사해 왔습니다.

Github에서 사용할 수 있는 간단한 프로젝트를 시작했습니다 . 기본적으로 Eureka 서버 (Archimedes)와 3 개의 Eureka 클라이언트 마이크로 서비스 (공용 API 1 개, 개인용 2 개)입니다. 자세한 설명은 github의 readme를 확인하십시오.

요점은 모든 것이 실행 중일 때 개인 마이크로 서비스 중 하나가 죽으면 Eureka 서버가이를 인식하고 레지스트리에서 제거하기를 원한다는 것입니다.

나는 유래에이 문제를 발견 하고, 솔루션을 사용하여 전달 enableSelfPreservation:false유레카 서버 설정에서. 잠시 후이 작업을 수행하면 종료 된 서비스가 예상대로 사라집니다.

그러나 다음 메시지를 볼 수 있습니다.

자체 보존 모드가 꺼져있어 네트워크 / 기타 문제 발생시 인스턴스 만료를 보호하지 못할 수 있습니다.

1. 자기 보존의 목적은 무엇입니까? 문서의 상태가에 자기 보존과 "클라이언트가 더 이상 존재하지 않는 인스턴스를 얻을 수 있습니다" . 그렇다면 언제 켜고 끄는 것이 좋습니까?

또한 자체 보존이 켜져 있으면 Eureka 서버 콘솔 경고에 미해결 메시지가 표시 될 수 있습니다.

비상 사태! EUREKA는 그렇지 않은 경우 인스턴스가 잘못 청구되었을 수 있습니다. 갱신은 임계 값보다 적으므로 인스턴스는 안전을 위해 만료되지 않습니다.

이제 Spring Eureka Console로 진행합니다.

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

임계 값 수의 이상한 동작을 발견했습니다. Eureka 서버 만 시작하면 임계 값이 1입니다.

2. 단일 Eureka 서버가 있고 registerWithEureka: false다른 서버에 등록하지 못하도록 구성되어 있습니다. 그렇다면 임계 값 개수에 왜 표시됩니까?

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가 만난 것과 같은 질문을 받았는데, 많이 봤고 몇 가지 실험을했습니다. 여기에 유레카 서버와 인스턴스가 어떻게 작동하는지에 대한 지식을 제공하기 위해 왔습니다.

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

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

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.

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

  1. Question 1:

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. Question 2:

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.

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. Question 3:

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. Question 4:

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.

I have two suggestions for this:

  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.

I've created a blog post with the details of Eureka here, that fills in some missing detail from Spring doc or Netflix blog. It is the result of several days of debugging and digging through source code. I understand it's preferable to copy-paste rather than linking to an external URL, but the content is too big for an SO answer.


You can try to set renewal threshold limit in your eureka server properties. If you have around 3 to 4 Microservices to register on eureka, then you can set it to this:

eureka.server.renewalPercentThreshold=0.33

참고URL : https://stackoverflow.com/questions/33921557/understanding-spring-cloud-eureka-server-self-preservation-and-renew-threshold

반응형