Resilience4j Retry - Memory consumption

745 Views Asked by At

I am using resilience4j with Spring Boot 2.x What is the impact of using Retry and circuit breaker modules on memory and cpu?

Also what is the memory impact if I have 2000 events/s incoming each payload around 10Mb and I have kept the wait duration of retry as 15 seconds with exponential backoff multiplier as 2? I have 8Gb of application memory

1

There are 1 best solutions below

0
On

The best way is to monitor your application with a profile like VisualVM. Then you can know where is the bottleneck.

One thing that I know that matters is where you create your circuitbreaker instance. In the end there is a collector that remove the instances not used. But in your case it seems to be a good idea to not place the creation of the circuit breaker on the get method like here

@Service
public static class DemoControllerService {
    private RestTemplate rest;
    private CircuitBreakerFactory cbFactory;
    public DemoControllerService(RestTemplate rest, CircuitBreakerFactory cbFactory) {
        this.rest = rest;
        this.cbFactory = cbFactory;
    }
    public String slow() {
        return cbFactory.create("slow").run(() -> rest.getForObject("/slow", String.class), throwable -> "fallback");
    }
}

But create the circuitbreaker on the constructor.

@Service
public class DemoControllerService {
    private RestTemplate restTemplate = new RestTemplate();
    private CircuitBreakerFactory circuitBreakerFactory;
    private CircuitBreaker circuitBreaker;

    @Autowired
    public DemoControllerService(CircuitBreakerFactory circuitBreakerFactory) {
        this.circuitBreakerFactory = circuitBreakerFactory;
        this.circuitBreaker = circuitBreakerFactory.create("circuitbreaker");
    }

There are also discussions to place one circuitbreaker per host. Other thing that you can do is to remove the instance of the Registry by yourself and not wait for the circuitbreaker component rome it in the future.

registry.remove(circuitBreakerName);

Here is a discussion also about to clean up the Registry memory.