Reputation: 1425
I have a Spring Boot REST services which uses Hystrix from Spring Cloud Netflix. I noticed that the first call to the interface needs much time to process, since the first call to the method which is isolated with Hystrix takes 2-3 seconds for the Hystrix to load.
This is the code:
@HystrixCommand(ignoreExceptions = { BusinessException.class,
TechnicalException.class }, fallbackMethod = "testFall", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "15000") })
public void test() throws BusinessException, TechnicalException {
System.out.println("Inside");
}
Is there a way to preload Hystrix so that this doesn't happen?
Upvotes: 1
Views: 1383
Reputation: 11
I have the same issue (loosing "only" 500 ms).
It happens when the HystrixCommandGroup is initialized the first time. Most time is lost when creating the HystrixMetrics: hystrix profiling
I've created an issue: https://github.com/Netflix/Hystrix/issues/1832
Unfortunately the HystrixCommand (and within the HystrixCommandGroup) is only initialized when the annotated method is called. You cannot precompile it. As a workaround you could use the abstract HystrixCommand class instead of the annotation and create a dummy instance at startup. e.g.:
public class TestCommand extends HystrixCommand<String> {
static {
new TestCommand();
}
protected TestCommand() {
super(HystrixCommandGroupKey.Factory.asKey("mygroup"));
}
@Override
protected String run() throws Exception {
// TODO Auto-generated method stub
return null;
}
}
Upvotes: 1