Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

04. Hystrix Circuit Open 테스트


  • [display] application.yml 수정하여 Hystrix 프로퍼티 추가.
    • 10초동안 20개 이상의 호출이 발생 했을때 50% 이상의 호출에서 에러가 발생하면 Circuit Open
    • Code Block
      hystrix:
        command:
          default:    # command key. use 'default' for global setting.
            execution:
              isolation:
                thread:
                  timeoutInMilliseconds: 3000
            circuitBreaker:
              requestVolumeThreshold: 1   # Minimum number of request to calculate circuit breaker's health. default 20
              errorThresholdPercentage: 50 # Error percentage to open circuit. default 50
  • [product] ProductController 다시 수정하여 Exception 던지도록 수정
    • Code Block
      @RestController
      @RequestMapping("/products")
      public class ProductController {
      
          @GetMapping(path = "{productId}")
          public String getProductInfo(@PathVariable String productId) {
      //        try {
      //            Thread.sleep(2000);
      //        } catch (InterruptedException e) {
      //            e.printStackTrace();
      //        }
      //
      //        return "[product id = " + productId + " at " + System.currentTimeMillis() + "]";
              throw new RuntimeException("I/O Exception");
          }
      }


  • Display → Product 호출 확인
    • Info

      Image Added

      Image Added

      Code Block
      2020-02-25 12:38:13.284  INFO 96380 --- [io-8081-exec-10] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
      2020-02-25 12:38:13.285  INFO 96380 --- [io-8081-exec-10] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
      2020-02-25 12:38:13.360  INFO 96380 --- [io-8081-exec-10] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 74 ms
      t = org.springframework.web.client.HttpServerErrorException: 500 null
      t = java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN
      t = java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN
      t = java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN
  • 정리
    • Info
      • Circuit Open 여부는 통계를 기반으로 한다.
      • 최근 10초간 호출 통계 (metrics.rollingStats.timeInMilliseconds : 10000)
      • 최소 요청 갯수(20) 넘는 경우만 (circuitBreaker.requestVolumeThreshold : 20)
      • 에러 비율 넘는 경우(50%) (circuitBreaker.errorThresholdPercentage : 50)
      • 한번 Circuit이 오픈되면 5초간 호출이 차단되며, 5초 경과후 단 “1개”의 호출을 허용하며 (Half-Open), 이것이 성공하면 Circuit을 다시 CLOSE하고, 여전히 실패하면 Open이 5초 연장된다.
        (circuitBreaker.sleepWindowInMilliseconds : 5000)