Inflearn brand logo image

인프런 커뮤니티 질문&답변

soap님의 프로필 이미지
soap

작성한 질문수

장애 없는 서비스를 만들기 위한 Resilience4j - CircuitBreaker

어떤 예외를 recordExceptions로 지정할까?

recordException을 지정하지 않았을때 동작 방식 질문

해결된 질문

작성

·

84

0

Foo님 안녕하세요.

간단한 질문 드립니다!

recordException을 지정하지 않으면 서킷 브레이커 설정을 해도 동작을 안하는 걸까요? 아니면 기본적으로 RuntimeException과 Error만을 체크하는 걸까요?

 

감사합니다.

답변 3

1

이준형(Foo)님의 프로필 이미지
이준형(Foo)
지식공유자

soap님 오래 기다리셨습니다!

 

관련해서는 https://resilience4j.readme.io/docs/circuitbreaker#failure-rate-and-slow-call-rate-thresholds 에 아래와 같은 내용이 있습니다.

 

Failure rate and slow call rate thresholds

The state of the CircuitBreaker changes from CLOSED to OPEN when the failure rate is equal or greater than a configurable threshold. For example when more than 50% of the recorded calls have failed.
By default all exceptions count as a failure. You can define a list of exceptions which should count as a failure. All other exceptions are then counted as a success, unless they are ignored. Exceptions can also be ignored so that they neither count as a failure nor success.

The CircuitBreaker also changes from CLOSED to OPEN when the percentage of slow calls is equal or greater than a configurable threshold. For example when more than 50% of the recorded calls took longer than 5 seconds. This helps to reduce the load on an external system before it is actually unresponsive.

The failure rate and slow call rate can only be calculated, if a minimum number of calls were recorded. For example, if the minimum number of required calls is 10, then at least 10 calls must be recorded, before the failure rate can be calculated. If only 9 calls have been evaluated the CircuitBreaker will not trip open even if all 9 calls have failed.

 

즉, Resilience4j에서 구현한 서킷 브레이커는 기본적으로 모든 예외(RuntimeException, Error 포함)를 실패로 간주합니다. 여기서 특정 예외를 recordException로 지정했을 때는 해당 예외의 하위 예외들로 실패로 간주되는 예외의 폭이 줄어드는 겁니다.

 

혹시 추가적으로 궁금한 내용 있으면 질문 남겨주세요!

감사합니다.

1

이준형(Foo)님의 프로필 이미지
이준형(Foo)
지식공유자

soap님 안녕하세요!

제가 현재 해외에 나와있어서 내일 복귀하는대로 답변 드리겠습니다.

감사합니다.

0

안녕하세요, 인프런 AI 인턴입니다. soap님.

Resilience4j에서 recordException 설정은 서킷 브레이커가 어떤 예외를 “실패”로 기록할지를 결정하는 중요한 설정입니다. recordException을 지정하지 않으면 기본적으로 모든 예외(Exception)가 실패로 간주됩니다. 즉, 별도로 설정하지 않아도 기본값으로 모든 예외가 서킷 브레이커의 실패 기준에 포함됩니다.

따라서 서킷 브레이커는 recordException을 설정하지 않더라도 기본적으로 RuntimeException과 Error를 포함한 모든 예외를 감지하게 됩니다. 그러나 특정 조건에 맞는 예외만을 실패로 기록하고자 한다면, recordException 설정을 명시해야 합니다.

서킷 브레이커 설정을 더 자세히 이해하는 데 도움이 될 링크를 아래에 첨부드립니다:

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다. 현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏 추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.

soap님의 프로필 이미지
soap

작성한 질문수

질문하기