resilience4j / resilience4j-spring-boot2-demo

A Spring Boot 2 demo which shows how to use the Resilience4j Spring Boot 2 Starter
Apache License 2.0
253 stars 190 forks source link

how to check thread-pool-bulkhead health? #75

Open geekxingyun opened 9 months ago

geekxingyun commented 9 months ago

i had config these code in yaml file,but it not effected when i use 20 concurrent call with jmeter.

how can i check these issue?

resilience4j.thread-pool-bulkhead:
    instances:
      default:
        max-thread-pool-size: 1
        core-thread-pool-size: 1
        queue-capacity: 1
      singleAnalysisThreadPoolBulkhead:
        max-thread-pool-size: 1
        core-thread-pool-size: 1
        queue-capacity: 1
        keep-alive-duration: 1ms
        writable-stack-trace-enabled: true
      batchAnalysisThreadPoolBulkhead:
        max-thread-pool-size: 5
        core-thread-pool-size: 5
        queue-capacity: 10
        keep-alive-duration: 20ms
        writable-stack-trace-enabled: true

call method

    @Bulkhead(name = "singleAnalysisThreadPoolBulkhead",type = Bulkhead.Type.THREADPOOL,fallbackMethod ="fallbackForThreadPoolBulkhead")
    public VueElementAdminResponse singleAnalysis(HxConsistencyAnalysisParam param) {
        try {
            Stopwatch stopwatch=Stopwatch.createStarted();
            VueElementAdminResponse vueElementAdminResponse=analysis(param);
            stopwatch.stop();
            logger.warn("cost_time:{}",stopwatch);
            return vueElementAdminResponse;
        }catch (RejectedExecutionException e){
            VueElementAdminResponse vueElementAdminResponse = new VueElementAdminResponse();
            vueElementAdminResponse.setCode(ResponseCodeEnum.THREAD_POOL_OF_CALL.getCode());
            vueElementAdminResponse.setMessage("thread pool is full");
            vueElementAdminResponse.setData(e.getMessage());
            return vueElementAdminResponse;
        } catch (Exception e) {
            VueElementAdminResponse vueElementAdminResponse = new VueElementAdminResponse();
            vueElementAdminResponse.setCode(ResponseCodeEnum.OTHER_SERVER_EXCEPTION.getCode());
            vueElementAdminResponse.setMessage("call exception");
            vueElementAdminResponse.setData(e);
            return vueElementAdminResponse;
        }
    }
   public VueElementAdminResponse rateLimiterFallback(HxConsistencyAnalysisParam param, Throwable throwable) {
        return VueElementAdminResponse.builder()
                .code(ResponseCodeEnum.REQUEST_FREQUENCY_OF_CALL.getCode())
                .message(ResponseCodeEnum.REQUEST_FREQUENCY_OF_CALL.getMessage())
                .data(param)
                .build();
    }
    public VueElementAdminResponse fallbackForThreadPoolBulkhead(HxConsistencyAnalysisParam param,Throwable throwable) {
        return VueElementAdminResponse.builder()
                .code(ResponseCodeEnum.THREAD_POOL_OF_CALL.getCode())
                .message(ResponseCodeEnum.THREAD_POOL_OF_CALL.getMessage())
                .data(param)
                .build();
    }
RobWin commented 9 months ago

If you add implementation("io.micrometer:micrometer-registry-prometheus"), you can check the metrics of the prometheus endpoint. See: https://resilience4j.readme.io/docs/micrometer