Spring Hystrix-第一次请求响应缓慢

Spring Hystrix-第一次请求响应缓慢,spring,spring-cloud-netflix,hystrix,Spring,Spring Cloud Netflix,Hystrix,我有一个SpringBootREST服务,它使用来自SpringCloudNetflix的Hystrix。我注意到,对接口的第一次调用需要花很多时间来处理,因为对与Hystrix隔离的方法的第一次调用需要2-3秒才能加载Hystrix 代码如下: @HystrixCommand(ignoreExceptions = { BusinessException.class, TechnicalException.class }, fallbackMethod =

我有一个SpringBootREST服务,它使用来自SpringCloudNetflix的Hystrix。我注意到,对接口的第一次调用需要花很多时间来处理,因为对与Hystrix隔离的方法的第一次调用需要2-3秒才能加载Hystrix

代码如下:

@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");
}
有没有办法预加载Hystrix,这样就不会发生这种情况?

我也有同样的问题(仅“松开”500毫秒)

它发生在HystrixCommandGroup第一次初始化时。创建HystrixMetrics时会浪费大量时间:

我创造了一个问题:

不幸的是,HystrixCommand(以及HystrixCommand组内)仅在调用带注释的方法时初始化。您不能预编译它。作为一种解决方法,您可以使用抽象HystrixCommand类而不是注释,并在启动时创建一个虚拟实例。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;
    }

}
公共类TestCommand扩展了HystrixCommand{
静止的{
新建TestCommand();
}
受保护的TestCommand(){
super(HystrixCommandGroupKey.Factory.asKey(“mygroup”);
}
@凌驾
受保护的字符串run()引发异常{
//TODO自动生成的方法存根
返回null;
}
}

我认为这不是真的。启动断路器所需的一切都是在启动时设置的。我也这么认为,但很明显,从调用方法的那一刻起,到执行方法中的第一行代码的那一刻,2-3秒就会过去。。。