我有一个Spring Boot REST服务,它使用来自Spring Cloud Netflix的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,这样就不会发生这种情况?
发布于 2018-07-19 21:52:41
我也有同样的问题(丢失“只”500ms)。
当HystrixCommandGroup第一次初始化时就会发生这种情况。大部分时间都是在创建HystrixMetrics时丢失的:hystrix profiling
我已经创建了一个问题:https://github.com/Netflix/Hystrix/issues/1832
不幸的是,只有在调用带注释的方法时,才会初始化HystrixCommand (以及HystrixCommandGroup中的)。您不能预编译它。作为变通办法,您可以使用抽象HystrixCommand类代替注释,并在启动时创建一个虚拟实例。例如:
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;
}
}https://stackoverflow.com/questions/49032383
复制相似问题