I have a service that has uses 3 feign clients. Each time I start my application, I get a TimeoutException on the first call to any feign client.
I have to trigger each feign client at least once before everything is stable. Looking around online, the problem is that something inside of feign or hystrix is lazy loaded and the solution was to make a configuration class that overrides the spring defaults. I've tried that wiith the below code and it is still not helping. I still see the same issue. Anyone know a fix for this? Is the only solution to call the feignclient twice via a hystrix callback?
@FeignClient(value = "SERVICE-NAME", configuration =ServiceFeignConfiguration.class)
@Configuration
public class ServiceFeignConfiguration {
@Value("${service.feign.connectTimeout:60000}")
private int connectTimeout;
@Value("${service.feign.readTimeOut:60000}")
private int readTimeout;
@Bean
public Request.Options options() {
return new Request.Options(connectTimeout, readTimeout);
}
}
Spring Cloud - Brixton.SR4 Spring Boot - 1.4.0.RELEASE
This is all running in docker Ubuntu - 12.04 Docker - 1.12.1 Docker-Compose - 1.8
Now, add the @Hystrix command and @HystrixProperty for the Rest API and define the timeout in milliseconds value. Next, define the fallback method fallback_hello() if the request takes a long time to respond. In this example, REST API written in main Spring Boot application class file itself.
After quick investigation we discovered that Hystrix has a default timeout set to 500ms and apparently that wasn't enough for Garage service during holiday peaks.
According to my research Resilience4j is a robust option than hystrix .
It is officially deprecated. As a replacement to Hystrix, Resilience4J is introduced.
I found the solution to be that the default properties of Hystrix are not good. They have a very small timeout window and the request will always time out on the first try. I added these properties to my application.yml file in my config service and now all of my services can use feign with no problems and i dont have to code around the first time timeout
hystrix:
threadpool.default.coreSize: "20"
threadpool.default.maxQueueSize: "500000"
threadpool.default.keepAliveTimeMinutes: "2"
threadpool.default.queueSizeRejectionThreshold: "500000"
command:
default:
fallback.isolation.semaphore.maxConcurrentRequests: "20"
execution:
timeout:
enabled: "false"
isolation:
strategy: "THREAD"
thread:
timeoutInMilliseconds: "30000"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With