【问题标题】:spring boot 2: actuator/health endpoint is taking more timespring boot 2:执行器/健康端点需要更多时间
【发布时间】:2020-08-31 05:21:56
【问题描述】:

在我的一个服务 /actuator/health 端点中需要更多时间(大约 9 秒)。我正在使用以下依赖项,如何调试?

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

使用的 Spring boot 版本: 2.0.3.RELEASE

谢谢, 哈里

【问题讨论】:

    标签: spring spring-boot-actuator


    【解决方案1】:

    基本上health端点的实现方式是它包含实现接口HealthIndicator的所有Spring bean的列表。

    每个健康指标负责提供一个子系统的健康信息(此类子系统的示例有:disk、postgres、mongo 等),spring boot 自带一些预定义的 HealthIndicators。

    这样当health 端点被调用时,它会遍历这个列表并获取有关每个子系统的信息,然后构造答案。

    因此,您可以在相关的健康指标中放置一个断点(假设您知道检查了哪些子系统)并查看会发生什么。

    如果您正在寻找 HTTP 入口点 - 当您调用 http://&lt;host-port&gt;/health 时调用的代码(可能会因您的设置而异,但您明白了)`,可以找到 here

    想到的另一种方法是禁用“可疑”健康检查并通过消除找到缓慢的健康检查。

    例如,如果您有一个 elastricsearch 并想禁用它,请在 application.properties 中使用:

    management.health.elasticsearch.enabled = false
    

    【讨论】:

      【解决方案2】:

      在马克的回答之上,在你的 application.properties / application.yml 中设置这个属性

      management.endpoint.health.show-details=always
      

      将帮助确定哪些组件构成了健康检查, 因为 GET /actuator/health 会产生更多细节

      【讨论】:

        【解决方案3】:

        Mark's great answer之上:

        作为在调用 /health 端点时同步运行所有运行状况检查的替代方法(当您添加更多运行状况检查时,这只会导致执行时间越来越长),您可以让您的 HealthIndicators 异步运行使用库 spring-boot-async-health-indicator(对于 Spring Boot >= 2.2) 使用 @AsyncHealth 注释它们。

        除了使/health 端点立即返回(在不同线程上计算返回healths)之外,它还包括每个异步health() 方法执行的执行时间作为附加细节,这极大地有助于计算找出哪个底层服务在生产系统上响应缓慢。

        免责声明:我编写这个库是为了帮助解决现有 HealthIndicator 系统的多个限制,包括这个

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-03-10
          • 2019-05-29
          • 1970-01-01
          • 2018-03-03
          • 2015-07-04
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多