【问题标题】:Hystrix - slow response on first requestHystrix - 第一次请求响应缓慢
【发布时间】:2018-08-08 11:59:21
【问题描述】:

我有一个使用 Spring Cloud Netflix 的 Hystrix 的 Spring Boot REST 服务。我注意到第一次调用接口需要很多时间来处理,因为第一次调用与 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 以免发生这种情况?

【问题讨论】:

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

标签: spring spring-cloud-netflix hystrix


【解决方案1】:

我有同样的问题(“仅”丢失 500 毫秒)。

第一次初始化 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;
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-07
    • 2015-07-21
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-22
    • 1970-01-01
    相关资源
    最近更新 更多