前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SpringCloud服务降级与熔断Hystrix

SpringCloud服务降级与熔断Hystrix

作者头像
cheese
发布2023-10-25 11:21:14
1810
发布2023-10-25 11:21:14
举报
文章被收录于专栏:Java PorterJava Porter

概述

业务场景

分布式系统面临的问题

  • 复杂分布式体系结构中的应用程序有数十个依赖关系,每个依赖关系在某些时候将不可避免地失败。
image.png
image.png
  • 服务雪崩现象

  • 多个微服务之间调用的时候,假设微服务A调用微服务B和微服务C,微服务B和微服务C又调用其它的微服务,这就是所谓的“扇出”。如果扇出的链路上某个微服务的调用响应时间过长或者不可用,对微服务A的调用就会占用越来越多的系统资源,进而引起系统崩溃,所谓的“雪崩效应”.
  • 对于高流量的应用来说,单一的后端依赖可能会导致所有服务器上的所有资源都在几秒钟内饱和。比失败更糟糕的是,这些应用程序还可能导致服务之间的延迟增加,备份队列,线程和其他系统资源紧张,导致整个系统发生更多的级联故障。这些都表示需要对故障和延迟进行隔离和管理,以便单个依赖关系的失败,不能取消整个应用程序或系统。
  • 所以,通常当你发现一个模块下的某个实例失败后,这时候这个模块依然还会接收流量,然后这个有问题的模块还调用了其他的模块,这样就会发生级联故障,或者叫雪崩。

Hystrix的作用

  • Hystrix是一个用于处理分布式系统的延迟和容错的开源库,在分布式系统里,许多依赖不可避免的会调用失败,比如超时、异常等,Hystrix能够保证在一个依赖出问题的情况下,
  • 不会导致整体服务失败,避免级联故障,以提高分布式系统的弹性。
  • “断路器”本身是一种开关装置,当某个服务单元发生故障之后,通过断路器的故障监控(类似熔断保险丝),
  • 向调用方返回一个符合预期的、可处理的备选响应(FallBack),而不是长时间的等待或者抛出调用方无法处理的异常,
  • 这样就保证了服务调用方的线程不会被长时间、不必要地占用,从而避免了故障在分布式系统中的蔓延,乃至雪崩。

Hystrix有特点

能够提供如下功能的实现

  • 服务降级
  • 服务熔断
  • 接近实时的监控

关于Hystrix

image.png
image.png
  • 被动修复bugs
  • 不再接受合并请求
  • 不再发布新版

Hystrix的重要概念

服务降级fallback

  • 用处,当服务响应超时时返回友好提示

服务器忙,请稍后再试,不让客户端等待并立刻返回一个友好提示,fallback

  • 发生服务降级的场景
    • 程序运行异常
    • 超时
    • 服务熔断触发服务降级
    • 线程池/信号量打满也会导致服务降级

服务熔断break

  • 用处,当服务承受的服务到达服务最大的承受压力时,直接拒绝访问,调用服务降级方法提示用户
  • 执行顺序
    • 服务的降级->进而熔断->恢复调用链路

服务限流flowlimit

  • 用处,单出现高并发请求场景时,为请求消息设置缓冲队列,减少服务器压力

秒杀高并发等操作,严禁一窝蜂的过来拥挤,大家排队,一秒钟N个,有序进行

Hystrix案例

构建模块

  • 搭建环境
    • 新建模块cloud-provider-hystrix-payment8003
    • 编写pom文件
代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>cloud2023</artifactId>
        <groupId>top.ljzstudy.springcloud</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>cloud-provider-hystrix-payment8003</artifactId>

    <dependencies>
        <!--hystrix-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <!--eureka client-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <!--web-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency><!-- 引入自己定义的api通用包,可以使用Payment支付Entity -->
            <groupId>top.ljzstudy.springcloud</groupId>
            <artifactId>cloud-api-commons</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
  • 编写application.yml配置
代码语言:javascript
复制
server:
  port: 8003

spring:
  application:
    name: cloud-provider-hystrix-payment

eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      #defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
      defaultZone: http://eureka7001.com:7001/eureka
  • 编写主启动类
代码语言:javascript
复制
package top.ljzstudy.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@EnableEurekaClient //本服务启动后会自动注册进eureka服务中
public class HystrixPaymentMain8001{
    public static void main(String[] args){
        SpringApplication.run(HystrixPaymentMain8001.class,args);
    }
}
  • 编写业务逻辑
    • Service层
代码语言:javascript
复制
package top.ljzstudy.springcloud.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.concurrent.TimeUnit;

@Service
public class PaymentService
{
    /**
     * 正常访问,一切OK
     * @param id
     * @return
     */
    public String paymentInfo_OK(Integer id){
        return "线程池:"+Thread.currentThread().getName()+"paymentInfo_OK,id: "+id+"\t"+"O(∩_∩)O";
    }

    /**
     * 超时访问,演示降级
     * @param id
     * @return
     */
    public String paymentInfo_TimeOut(Integer id){
        try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); }
        return "线程池:"+Thread.currentThread().getName()+"paymentInfo_TimeOut,id: "+id+"\t"+"O(∩_∩)O,耗费3秒";
    }
}
  • controller
代码语言:javascript
复制
import top.ljzstudy.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class PaymentController{
    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;


    @GetMapping("/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id){
        String result = paymentService.paymentInfo_OK(id);
        log.info("****result: "+result);
        return result;
    }

    @GetMapping("/payment/hystrix/timeout/{id}")
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id) throws InterruptedException{
        String result = paymentService.paymentInfo_TimeOut(id);
        log.info("****result: "+result);
        return result;
    }
}
代码语言:javascript
复制
GET http://localhost:8003/payment/hystrix/ok/1

HTTP/1.1 200 
Content-Type: text/plain;charset=UTF-8
Content-Length: 62
Date: Sat, 16 Sep 2023 16:29:19 GMT
Keep-Alive: timeout=60
Connection: keep-alive

线程池:http-nio-8003-exec-1paymentInfo_OK,id: 1	O(∩_∩)O

Response code: 200; Time: 234ms; Content length: 52 bytes
代码语言:javascript
复制
GET http://localhost:8003/payment/hystrix/timeout/1

HTTP/1.1 200 
Content-Type: text/plain;charset=UTF-8
Content-Length: 86
Date: Sat, 16 Sep 2023 16:30:34 GMT
Keep-Alive: timeout=60
Connection: keep-alive

线程池:hystrix-PaymentService-1paymentInfo_TimeOut,id: 1	O(∩_∩)O,耗费秒: 3

Response code: 200; Time: 3438ms; Content length: 68 bytes
  • 访问结果均正常,以上述为根基平台,从正确->错误->降级熔断->恢复
  • 压力测试
    • Jmeter压力测试
    • 开启Jmeter,来20000个并发压死8001,20000个请求都去访问paymentInfo_TimeOut服务
    • 此时,收到访问paymentInfo_OK服务
  • 故障现象
    • 两个服务均出现500服务内部异常(转圈圈)
  • 原因
    • tomcat的默认的工作线程数被打满 了,没有多余的线程来分解压力和处理。
  • 结论
    • 上面还是服务提供者8001自己测试,假如此时外部的消费者80也来访问,那消费者只能干等,最终导致消费端80不满意,服务端8001直接被拖死

  • 新增消费者模块cloud-consumer-feign-hystrix-order80
    • pom文件
代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <parent>
    <artifactId>mscloud03</artifactId>
    <groupId>com.atguigu.springcloud</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>

  <artifactId>cloud-consumer-feign-hystrix-order80</artifactId>

  <dependencies>
    <!--openfeign-->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
    <!--hystrix-->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
    </dependency>
    <!--eureka client-->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency><!-- 引入自己定义的api通用包,可以使用Payment支付Entity -->
      <groupId>top.ljzstudy.springcloud</groupId>
      <artifactId>cloud-api-commons</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <!--web-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <!--一般基础通用配置-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <scope>runtime</scope>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>
  • 配置文件application.yml
代码语言:javascript
复制
server:
  port: 80

eureka:
  client:
    register-with-eureka: false
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka/
  • 编写主启动类
代码语言:javascript
复制
package top.ljzstudy.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableFeignClients
public class HystrixOrderMain80{
    public static void main(String[] args){
        SpringApplication.run(HystrixOrderMain80.class,args);
    }
}
  • service层
代码语言:javascript
复制
package top.ljzstudy.springcloud.service;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Component
@FeignClient(value = "CLOUD-PROVIDER-HYSTRIX-PAYMENT")
public interface HystrixPaymentService{
    @GetMapping("/payment/hystrix/ok/{id}")
    String paymentInfo_OK(@PathVariable("id") Integer id);

    @GetMapping("/payment/hystrix/timeout/{id}")
    String paymentInfo_TimeOut(@PathVariable("id") Integer id);
}
  • controller控制器
代码语言:javascript
复制
package top.ljzstudy.springcloud.controller;

import com.atguigu.springcloud.service.PaymentHystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class HystirxOrderController{
    @Resource
    private HystrixPaymentService hystrixPaymentService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id){
        String result = hystrixPaymentService.paymentInfo_OK(id);
        return result;
    }

    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
        String result = hystrixPaymentService.paymentInfo_TimeOut(id);
        return result;
    }
}
代码语言:javascript
复制
GET http://localhost/consumer/payment/hystrix/ok/1

HTTP/1.1 200 
Content-Type: text/plain;charset=UTF-8
Content-Length: 64
Date: Sat, 16 Sep 2023 17:09:02 GMT
Keep-Alive: timeout=60
Connection: keep-alive

线程池:http-nio-8003-exec-520paymentInfo_OK,id: 1	O(∩_∩)O

Response code: 200; Time: 751ms; Content length: 54 bytes
image.png
image.png
代码语言:javascript
复制
GET http://localhost/consumer/payment/hystrix/ok/1

HTTP/1.1 200 
Content-Type: text/plain;charset=UTF-8
Content-Length: 66
Date: Sat, 16 Sep 2023 17:15:07 GMT
Keep-Alive: timeout=60
Connection: keep-alive

-----FallbackPaymentService fall back paymentInfo_OK /(ㄒoㄒ)/~~

Response code: 200; Time: 2587ms; Content length: 62 bytes
  • 结果,消费者80,o(╥﹏╥)o
    • 要么转圈圈等待
    • 要么消费端报超时错误
  • 故障现象
    • 8001同一层次的其它接口服务被困死
  • 原因
    • tomcat线程池里面的工作线程已经被挤占完毕,80此时调用8001,客户端访问响应缓慢,转圈圈
  • 结论
    • 正因为有上述故障或不佳表现才有我们的降级/容错/限流等技术诞生

Hystrix解决故障的原理

  • 超时导致服务器变慢(转圈)
    • 超时不再等待
  • 出错(宕机或程序运行出错)
    • 出错要有兜底
  • 解决
    • 对方服务(8001)超时了,调用者(80)不能一直卡死等待,必须有服务降级
    • 对方服务(8001)down机了,调用者(80)不能一直卡死等待,必须有服务降级
    • 对方服务(8001)OK,调用者(80)自己出故障或有自我要求(自己的等待时间小于服务提供者),自己处理降级

服务降级

降级配置
  • @HystrixCommand
服务提供者
  • 8001运行时的问题
    • 设置自身调用超时时间的峰值,峰值内可以正常运行,超过了需要有兜底的方法处理,作服务降级fallback
  • 8001实现服务降级fallback
    • 服务降级改造前后比较
代码语言:javascript
复制
package top.ljzstudy.springcloud.service;

import cn.hutool.core.util.IdUtil;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.concurrent.TimeUnit;
/*
	改造前
*/

@Service
public class PaymentService {

    ......
    public String paymentInfo_TimeOut(Integer id) {
        int second = 3;//3秒以内有效
        //int number =  10/0;
        try {
            TimeUnit.SECONDS.sleep(second);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "线程池:" + Thread.currentThread().getName() + "paymentInfo_TimeOut,id: " + id + "\t" + "O(∩_∩)O,耗费秒: " + second;
    }

   ......
}
代码语言:javascript
复制
package top.ljzstudy.springcloud.service;

import cn.hutool.core.util.IdUtil;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.concurrent.TimeUnit;
/*
	改造后
*/

@Service
public class PaymentService {
    /**
     * 超时访问,演示降级
     * Hystrix服务降级fallback 既可以用于服务端又可以用于客户端,就一般情况而言,客户端居多
     *
     * @param id
     * @return
     */
    @HystrixCommand(
        //兜底的方法
        fallbackMethod = "paymentInfo_TimeOutHandler",
        //设定异常发生条件
        commandProperties = {
            @HystrixProperty(
                name = "execution.isolation.thread.timeoutInMilliseconds",
                value = "5000" //线程超时时间5sec
            )
        })
    public String paymentInfo_TimeOut(Integer id) {
        int second = 3;//3秒以内有效
        //int number =  10/0;
        try {
            TimeUnit.SECONDS.sleep(second);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "线程池:" + Thread.currentThread().getName() + "paymentInfo_TimeOut,id: " + id + "\t" + "O(∩_∩)O,耗费秒: " + second;
    }

    //服务降级fallback 调用的方法
    public String paymentInfo_TimeOutHandler(Integer id) {
        return "/(ㄒoㄒ)/调用支付接口超时或异常:\t" + "\t当前线程池名字" + Thread.currentThread().getName();
    }
}
  • @HystrixCommand报异常后如何处理
  • 一旦调用服务方法失败并抛出了错误信息后,会自动调用@HystrixCommand标注好的fallbackMethod调用类中的指定方法
image.png
image.png
  • 上图故意制造两个异常:
    • int number = 10/0; 计算异常
    • 我们能接受3秒钟,它运行5秒钟,超时异常。
  • 当前服务不可用了,做服务降级,兜底的方案都是paymentInfo_TimeOutHandler
  • 主启动类添加新注解@EnableCircuitBreaker
代码语言:javascript
复制
package top.ljzstudy.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;


@SpringBootApplication
@EnableEurekaClient //本服务启动后会自动注册进eureka服务中
@EnableCircuitBreaker//激活熔断器
public class PaymentHystrixMain8003{
    public static void main(String[] args){
        SpringApplication.run(PaymentHystrixMain8003.class,args);
    }
}
服务消费者
  • 修改yaml文件
代码语言:javascript
复制
# 用于服务降级 在注解@FeignClient中添加fallbackFactory属性值
feign:
  hystrix:
    enabled: true #在Feign中开启Hystrix
  • 主启动类新增注解@EnableHystrix
代码语言:javascript
复制
package top.ljzstudy.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;


@SpringBootApplication
@EnableFeignClients //开启Feign客户端
@EnableHystrix //开启服务降级
public class HystrixOrderMain80 {
    public static void main(String[] args) {
        SpringApplication.run(HystrixOrderMain80.class, args);
    }
}
  • 控制层修改前后
代码语言:javascript
复制
package top.ljzstudy.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import top.ljzstudy.springcloud.service.HystrixPaymentService;

import javax.annotation.Resource;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
public class HystrixPaymentController {
    ....
    @Resource
    private HystrixPaymentService hystrixPaymentService;

    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id) {
        int number = 10 / 0;
        return hystrixPaymentService.paymentInfo_TimeOut(id);
    }

    .....
}
  • 修改后
代码语言:javascript
复制
package top.ljzstudy.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import top.ljzstudy.springcloud.service.HystrixPaymentService;

import javax.annotation.Resource;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
public class HystrixPaymentController {

    ....
    @Resource
    private HystrixPaymentService hystrixPaymentService;

    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    @HystrixCommand(fallbackMethod = "paymentTimeOutFallbackMethod", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1500")
    })
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id) {
        int number = 10 / 0;
        return hystrixPaymentService.paymentInfo_TimeOut(id);
    }
    //一个方法对应一个服务降级的方法
    public String paymentTimeOutFallbackMethod(@PathVariable("id") Integer id) {
        return "我是消费者80,对方支付系统繁忙请10秒钟后再试或者自己运行出错请检查自己,o(╥﹏╥)o";
    }
    .....

}
代码膨胀问题与解决方案
  • 问题引入

一个服务降级对应一个降级响应方法,当出现大量访问被服务降级时,降级响应方法太多会导致代码冗余量大,从而导致代码臃肿膨胀问题

  • 解决方案
    • 统一和自定义的分开
  • 每个方法配置一个会导致代码膨胀
    • feign接口系列,修改HystrixPaymentController
    • @DefaultProperties(defaultFallback = “”)
image.png
image.png

@DefaultProperties(defaultFallback = “”) 1:1 每个方法配置一个服务降级方法,技术上可以,实际上傻X 1:N 除了个别重要核心业务有专属,其它普通的可以通过@DefaultProperties(defaultFallback = “”) 统一跳转到统一处理结果页面 通用的和独享的各自分开,避免了代码膨胀,合理减少了代码量

  • 全局熔断器的作用
    • 解耦==>直接在调用服务端的接口中进行服务降级处理
将熔断响应从业务代码中抽取出去
  • 熔断响应代码与业务逻辑混到一起容易导致代码混乱,可阅读性较差
  • 服务降级,客户端去调用服务端,碰上服务端宕机或关闭
  • 本次案例服务降级处理是在客户端80实现完成的,与服务端8001没有关系 只需要为Feign客户端定义的接口添加一个服务降级处理的实现类即可实现解耦
  • 未来我们要面对的异常 运行 超时 宕机
  • 再看我们的业务类PaymentController
image.png
image.png
  • 修改cloud-consumer-feign-hystrix-order80
    • 根据cloud-consumer-feign-hystrix-order80已经有的PaymentHystrixService接口, 重新新建一个类(PaymentFallbackService)实现该接口,统一为接口里面的方法进行异常处理
    • PaymentFeignClientService接口
代码语言:javascript
复制
package top.ljzstudy.springcloud.service;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Component
@FeignClient(value = "CLOUD-PROVIDER-HYSTRIX-PAYMENT",fallback = FallbackPaymentService.class)
public interface HystrixPaymentService {
    @GetMapping("/payment/hystrix/ok/{id}")
    String paymentInfo_OK(@PathVariable("id") Integer id);

    @GetMapping("/payment/hystrix/timeout/{id}")
    String paymentInfo_TimeOut(@PathVariable("id") Integer id);
}
  • PaymentFallbackService类实现PaymentFeignClientService接口
代码语言:javascript
复制
package top.ljzstudy.springcloud.service;

import org.springframework.stereotype.Component;

@Component
public class FallbackPaymentService implements HystrixPaymentService{
    @Override
    public String paymentInfo_OK(Integer id) {
        return "-----FallbackPaymentService fall back paymentInfo_OK /(ㄒoㄒ)/~~";
    }

    @Override
    public String paymentInfo_TimeOut(Integer id) {
        return "========FallbackPaymentService fall back paymentInfo_TimeOut /(ㄒoㄒ)/~~";
    }
}
  • YML
代码语言:javascript
复制
# 用于服务降级 在注解@FeignClient中添加fallbackFactory属性值
feign:
  hystrix:
    enabled: true #在Feign中开启Hystrix
  • 测试

单个eureka先启动7001 PaymentHystrixMain8003启动

image.png
image.png

正常访问测试 http://localhost:8003/payment/hystrix/ok/1

代码语言:javascript
复制
GET http://localhost:8003/payment/hystrix/ok/1

HTTP/1.1 200 
Content-Type: text/plain;charset=UTF-8
Content-Length: 62
Date: Sun, 17 Sep 2023 07:18:39 GMT
Keep-Alive: timeout=60
Connection: keep-alive

线程池:http-nio-8003-exec-2paymentInfo_OK,id: 1	O(∩_∩)O

Response code: 200; Time: 297ms; Content length: 52 bytes

启动客户端故意关闭微服务8001 客户端自己调用提示http://localhost/consumer/payment/hystrix/ok/1

代码语言:javascript
复制
GET http://localhost/consumer/payment/hystrix/ok/1

HTTP/1.1 200 
Content-Type: text/plain;charset=UTF-8
Content-Length: 66
Date: Sun, 17 Sep 2023 07:20:36 GMT
Keep-Alive: timeout=60
Connection: keep-alive

-----FallbackPaymentService fall back paymentInfo_OK /(ㄒoㄒ)/~~

Response code: 200; Time: 1016ms; Content length: 62 bytes
  • 此时服务端provider已经down了,但是我们做了服务降级处理,让客户端在服务端不可用时也会获得提示信息而不会挂起耗死服务器

服务熔断

服务熔断理论
  • 断路器是什么?
    • 一句话就是家里的保险丝
  • 熔断是什么?

熔断机制概述 熔断机制是应对雪崩效应的一种微服务链路保护机制。当扇出链路的某个微服务出错不可用或者响应时间太长时, 会进行服务的降级,进而熔断该节点微服务的调用,快速返回错误的响应信息。 当检测到该节点微服务调用响应正常后,恢复调用链路。 在Spring Cloud框架里,熔断机制通过Hystrix实现。Hystrix会监控微服务间调用的状况, 当失败的调用到一定阈值,缺省是5秒内20次调用失败,就会启动熔断机制。熔断机制的注解是@HystrixCommand。

image.png
image.png

摘自论文中的一段描述就行翻译

image.png
image.png
构建实例
  • 修改cloud-provider-hystrix-payment8003
  • 修改PaymentService
代码语言:javascript
复制
package top.ljzstudy.springcloud.service;

import cn.hutool.core.util.IdUtil;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.concurrent.TimeUnit;

@Service
public class PaymentService {
 
	......
    //=========服务熔断
    @HystrixCommand(fallbackMethod = "paymentCircuitBreaker_fallback", commandProperties = {
        //是否开启断路器
        @HystrixProperty(name = "circuitBreaker.enabled", value = "true"),
        //请求次数
        @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
        //时间窗口期
        @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "10000"),
        //失败率触发熔断上限
        @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "60"),
    })
    public String paymentCircuitBreaker(@PathVariable("id") Integer id) {
        if (id < 0) {
            throw new RuntimeException("******id 不能负数");
        }
        String serialNumber = IdUtil.simpleUUID();//等价于 ==>UUID.randomUUID().toString()

        return Thread.currentThread().getName() + "\t" + "调用成功,流水号: " + serialNumber;
    }

    public String paymentCircuitBreaker_fallback(@PathVariable("id") Integer id) {
        return "id 不能负数,请稍后再试,/(ㄒoㄒ)/~~   id: " + id;
    }
    ......
}
  • 关于配置熔断的几个参数
HystrixCircuitConfigargument.png
HystrixCircuitConfigargument.png
  • 修改PaymentContoller
代码语言:javascript
复制
@GetMapping("/payment/circuit/{id}")
public String paymentCircuitBreaker(@PathVariable("id") Integer id){
    String result = paymentService.paymentCircuitBreaker(id);
    log.info("****result: "+result);
    return result;
}
  • 测试
  • 自测cloud-provider-hystrix-payment8003
    • 正确用例
代码语言:javascript
复制
GET http://localhost:8003/payment/circuit/1

HTTP/1.1 200 
Content-Type: text/plain;charset=UTF-8
Content-Length: 83
Date: Sun, 17 Sep 2023 08:57:46 GMT
Keep-Alive: timeout=60
Connection: keep-alive

hystrix-PaymentService-1	调用成功,流水号: d1b8e8fb81fe4d87be98e636bc7c4a11

Response code: 200; Time: 375ms; Content length: 67 bytes
  • 错误用例
代码语言:javascript
复制
GET http://localhost:8003/payment/circuit/-1

HTTP/1.1 200 
Content-Type: text/plain;charset=UTF-8
Content-Length: 58
Date: Sun, 17 Sep 2023 08:59:23 GMT
Keep-Alive: timeout=60
Connection: keep-alive

id 不能负数,请稍后再试,/(ㄒoㄒ)/~~   id: -1

Response code: 200; Time: 78ms; Content length: 32 bytes
  • 模拟大量错误用例请求使服务发生熔断
image.png
image.png
  • 熔断之后发起正确用例请求
image.png
image.png
  • 服务熔断后正确用例请求也同样收到失败的结果
  • 之后继续访问断路器恢复正常服务
image.png
image.png
  • 多次错误,然后慢慢正确,发现刚开始不满足条件,就算是正确的访问地址也不能进行
结论
  • martinflower关于断路器原理的描述
image.png
image.png
  • 熔断类型
    • 熔断打开
      • 请求不再进行调用当前服务,内部设置时钟一般为MTTR(平均故障处理时间),当打开时长达到所设时钟则进入半熔断状态
    • 熔断关闭
      • 熔断关闭不会对服务进行熔断
    • 熔断半开
      • 部分请求根据规则调用当前服务,如果请求成功且符合规则则认为当前服务恢复正常,关闭熔断
  • 官网断路器流程图
image.png
image.png
  • 官方推荐步骤
image.png
image.png
  • 断路器触发的条件
image.png
image.png

涉及到断路器的三个重要参数:快照时间窗、请求总数阀值、错误百分比阀值。 1:快照时间窗:断路器确定是否打开需要统计一些请求和错误数据,而统计的时间范围就是快照时间窗,默认为最近的10秒。 2:请求总数阀值:在快照时间窗内,必须满足请求总数阀值才有资格熔断。 默认为20,意味着在10秒内,如果该hystrix命令的调用次数不足20次,即使所有的请求都超时或其他原因失败,断路器都不会打开。 3:错误百分比阀值:当请求总数在快照时间窗内超过了阀值,比如发生了30次调用,如果在这30次调用中,有15次发生了超时异常,也就是超过50%的错误百分比,在默认设定50%阀值情况下,这时候就会将断路器打开。

  • 断路器开启或者关闭的条件
    • 当满足一定的阀值的时候(默认10秒内超过20个请求次数)
    • 当失败率达到一定的时候(默认10秒内超过50%的请求失败)
    • 到达以上阀值,断路器将会开启
    • 当开启的时候,所有请求都不会进行转发
    • 一段时间之后(默认是5秒),这个时候断路器是半开状态,会让其中一个请求进行转发。 如果成功,断路器会关闭,若失败,继续开启。重复4和5
  • 熔断器打开后的两种待触发状态
    • 1:再有请求调用的时候,将不会调用主逻辑,而是直接调用降级fallback。通过断路器,实现了自动地发现错误并将降级逻辑切换为主逻辑,减少响应延迟的效果。
    • 2:原来的主逻辑要如何恢复呢?
      • 对于这一问题,hystrix也为我们实现了自动恢复功能。
      • 当断路器打开,对主逻辑进行熔断之后,hystrix会启动一个休眠时间窗,在这个时间窗内,降级逻辑是临时的成为主逻辑,
      • 当休眠时间窗到期,断路器将进入半开状态,释放一次请求到原来的主逻辑上,如果此次请求正常返回,那么断路器将继续闭合,
      • 主逻辑恢复,如果这次请求依然有问题,断路器继续进入打开状态,休眠时间窗重新计时。
代码语言:javascript
复制
//========================All
@HystrixCommand(fallbackMethod = "str_fallbackMethod",
                groupKey = "strGroupCommand",
                commandKey = "strCommand",
                threadPoolKey = "strThreadPool",

                commandProperties = {
                    // 设置隔离策略,THREAD 表示线程池 SEMAPHORE:信号池隔离
                    @HystrixProperty(name = "execution.isolation.strategy", value = "THREAD"),
                    // 当隔离策略选择信号池隔离的时候,用来设置信号池的大小(最大并发数)
                    @HystrixProperty(name = "execution.isolation.semaphore.maxConcurrentRequests", value = "10"),
                    // 配置命令执行的超时时间
                    @HystrixProperty(name = "execution.isolation.thread.timeoutinMilliseconds", value = "10"),
                    // 是否启用超时时间
                    @HystrixProperty(name = "execution.timeout.enabled", value = "true"),
                    // 执行超时的时候是否中断
                    @HystrixProperty(name = "execution.isolation.thread.interruptOnTimeout", value = "true"),
                    // 执行被取消的时候是否中断
                    @HystrixProperty(name = "execution.isolation.thread.interruptOnCancel", value = "true"),
                    // 允许回调方法执行的最大并发数
                    @HystrixProperty(name = "fallback.isolation.semaphore.maxConcurrentRequests", value = "10"),
                    // 服务降级是否启用,是否执行回调函数
                    @HystrixProperty(name = "fallback.enabled", value = "true"),
                    // 是否启用断路器
                    @HystrixProperty(name = "circuitBreaker.enabled", value = "true"),
                    // 该属性用来设置在滚动时间窗中,断路器熔断的最小请求数。例如,默认该值为 20 的时候,
                    // 如果滚动时间窗(默认10秒)内仅收到了19个请求, 即使这19个请求都失败了,断路器也不会打开。
                    @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "20"),
                    // 该属性用来设置在滚动时间窗中,表示在滚动时间窗中,在请求数量超过
                    // circuitBreaker.requestVolumeThreshold 的情况下,如果错误请求数的百分比超过50,
                    // 就把断路器设置为 "打开" 状态,否则就设置为 "关闭" 状态。
                    @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "50"),
                    // 该属性用来设置当断路器打开之后的休眠时间窗。 休眠时间窗结束之后,
                    // 会将断路器置为 "半开" 状态,尝试熔断的请求命令,如果依然失败就将断路器继续设置为 "打开" 状态,
                    // 如果成功就设置为 "关闭" 状态。
                    @HystrixProperty(name = "circuitBreaker.sleepWindowinMilliseconds", value = "5000"),
                    // 断路器强制打开
                    @HystrixProperty(name = "circuitBreaker.forceOpen", value = "false"),
                    // 断路器强制关闭
                    @HystrixProperty(name = "circuitBreaker.forceClosed", value = "false"),
                    // 滚动时间窗设置,该时间用于断路器判断健康度时需要收集信息的持续时间
                    @HystrixProperty(name = "metrics.rollingStats.timeinMilliseconds", value = "10000"),
                    // 该属性用来设置滚动时间窗统计指标信息时划分"桶"的数量,断路器在收集指标信息的时候会根据
                    // 设置的时间窗长度拆分成多个 "桶" 来累计各度量值,每个"桶"记录了一段时间内的采集指标。
                    // 比如 10 秒内拆分成 10 个"桶"收集这样,所以 timeinMilliseconds 必须能被 numBuckets 整除。否则会抛异常
                    @HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "10"),
                    // 该属性用来设置对命令执行的延迟是否使用百分位数来跟踪和计算。如果设置为 false, 那么所有的概要统计都将返回 -1。
                    @HystrixProperty(name = "metrics.rollingPercentile.enabled", value = "false"),
                    // 该属性用来设置百分位统计的滚动窗口的持续时间,单位为毫秒。
                    @HystrixProperty(name = "metrics.rollingPercentile.timeInMilliseconds", value = "60000"),
                    // 该属性用来设置百分位统计滚动窗口中使用 “ 桶 ”的数量。
                    @HystrixProperty(name = "metrics.rollingPercentile.numBuckets", value = "60000"),
                    // 该属性用来设置在执行过程中每个 “桶” 中保留的最大执行次数。如果在滚动时间窗内发生超过该设定值的执行次数,
                    // 就从最初的位置开始重写。例如,将该值设置为100, 滚动窗口为10秒,若在10秒内一个 “桶 ”中发生了500次执行,
                    // 那么该 “桶” 中只保留 最后的100次执行的统计。另外,增加该值的大小将会增加内存量的消耗,并增加排序百分位数所需的计算时间。
                    @HystrixProperty(name = "metrics.rollingPercentile.bucketSize", value = "100"),
                    // 该属性用来设置采集影响断路器状态的健康快照(请求的成功、 错误百分比)的间隔等待时间。
                    @HystrixProperty(name = "metrics.healthSnapshot.intervalinMilliseconds", value = "500"),
                    // 是否开启请求缓存
                    @HystrixProperty(name = "requestCache.enabled", value = "true"),
                    // HystrixCommand的执行和事件是否打印日志到 HystrixRequestLog 中
                    @HystrixProperty(name = "requestLog.enabled", value = "true"),
                    },
                    threadPoolProperties = {
                    // 该参数用来设置执行命令线程池的核心线程数,该值也就是命令执行的最大并发量
                    @HystrixProperty(name = "coreSize", value = "10"),
                    // 该参数用来设置线程池的最大队列大小。当设置为 -1 时,线程池将使用 SynchronousQueue 实现的队列,
                    // 否则将使用 LinkedBlockingQueue 实现的队列。
                    @HystrixProperty(name = "maxQueueSize", value = "-1"),
                    // 该参数用来为队列设置拒绝阈值。 通过该参数, 即使队列没有达到最大值也能拒绝请求。
                    // 该参数主要是对 LinkedBlockingQueue 队列的补充,因为 LinkedBlockingQueue
                    // 队列不能动态修改它的对象大小,而通过该属性就可以调整拒绝请求的队列大小了。
                    @HystrixProperty(name = "queueSizeRejectionThreshold", value = "5"),
                    }
                    )
                    public String strConsumer() {
                    return "hello 2020";
                    }
                    public String str_fallbackMethod()
                    {
                    return "*****fall back str_fallbackMethod";
                    }

服务限流(后续见sentinel)

Hystrix工作流程

参考官网

Hystrix工作流程

官网图例
image.png
image.png
步骤说明
image.png
image.png
  • tips:如果我们没有为命令实现降级逻辑或者在降级处理逻辑中抛出了异常,Hystrix 依然会返回一个 Observable 对象, 但是它不会发射任何结果数据, 而是通过onError 方法通知命令立即中断请求,并通过onError()方法将引起命令失败的异常发送给调用者。

服务监控hystrixDashboard

概述


除了隔离依赖服务的调用以外,Hystrix还提供了准实时的调用监控(Hystrix Dashboard), Hystrix会持续地记录所有通过Hystrix发起的请求的执行信息,并以统计报表和图形的形式展示给用户,包括每秒执行多少请求多少成功,多少失败等。 Netflix通过hystrix-metrics-event-stream项目实现了对以上指标的监控。 Spring Cloud也提供了Hystrix Dashboard的整合,对监控内容转化成可视化界面。

构建HystrixDashboard仪表盘模块9001

  • 新建cloud-consumer-hystrix-dashboard9001
  • 搭建环境
    • pom文件
代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>cloud2023</artifactId>
        <groupId>top.ljzstudy.springcloud</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>cloud-consumer-hystrix-dashboard9001</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
  • yaml配置文件
代码语言:javascript
复制
server:
  port: 9001
  • 启动类配置

HystrixDashboardMain9001+新注解@EnableHystrixDashboard

代码语言:javascript
复制
package top.ljzstudy.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardMain9001 {
    public static void main(String[] args) {
        SpringApplication.run(HystrixDashboardMain9001.class,args);
    }
}
  • 所有Provider微服务提供类(8001/8002/8003)都需要监控依赖配置
代码语言:javascript
复制
   <!-- actuator监控信息完善 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
image.png
image.png
  • 使用HystrixDashBoard监控服务断路器
    • 修改Payment8003启动类
代码语言:javascript
复制
package top.ljzstudy.springcloud;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableEurekaClient //本服务启动后会自动注册进eureka服务中
@EnableCircuitBreaker//激活熔断器
public class PaymentHystrixMain8003 {
    public static void main(String[] args) {
        SpringApplication.run(PaymentHystrixMain8003.class, args);
    }

    @Bean
    public ServletRegistrationBean getServlet() {
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }
}
  • 依次启动注册中心Eureka7001,服务提供者Payment8003,和DashBoard监控9001
image.png
image.png
1694965198053.png
1694965198053.png
代码语言:javascript
复制
GET http://localhost:8003/payment/circuit/1

HTTP/1.1 200 
Content-Type: text/plain;charset=UTF-8
Content-Length: 84
Date: Sun, 17 Sep 2023 15:42:20 GMT
Keep-Alive: timeout=60
Connection: keep-alive

hystrix-PaymentService-10	调用成功,流水号: ad3fce47dc1b46e0975ae256cc12380b

Response code: 200; Time: 94ms; Content length: 68 bytes
代码语言:javascript
复制
GET http://localhost:8003/payment/circuit/-1

HTTP/1.1 200 
Content-Type: text/plain;charset=UTF-8
Content-Length: 58
Date: Sun, 17 Sep 2023 15:44:03 GMT
Keep-Alive: timeout=60
Connection: keep-alive

id 不能负数,请稍后再试,/(ㄒoㄒ)/~~   id: -1

Response code: 200; Time: 94ms; Content length: 32 bytes
  • 先访问正确地址,再访问错误地址,再正确地址,会发现图示断路器都是慢慢放开的。
  • 查看监控
1694965544823.png
1694965544823.png
  • 此时Circuit状态为Close,说明熔断器处于关闭状态
  • 对其进行多次触发服务降级访问
1694965801301.png
1694965801301.png
  • 触发服务熔断,正常访问,出现服务降级
1694965792161.png
1694965792161.png

Hystrix-DashBoard仪表盘数据

  • 如何读懂?
    • 7种颜色
  • 1圈

实心圆:共有两种含义。它通过颜色的变化代表了实例的健康程度,它的健康度从绿色<黄色<橙色<红色递减。 该实心圆除了颜色的变化之外,它的大小也会根据实例的请求流量发生变化,流量越大该实心圆就越大。所以通过该实心圆的展示,就可以在大量的实例中快速的发现故障实例和高压力实例。

  • 1线

曲线:用来记录2分钟内流量的相对变化,可以通过它来观察到流量的上升和下降趋势。

  • 整图说明

image.png
image.png
image.png
image.png
  • 复杂情况下的仪表盘数据图表

image.png
image.png
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-10-24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 概述
    • 业务场景
      • Hystrix的作用
        • Hystrix有特点
          • 关于Hystrix
          • Hystrix的重要概念
            • 服务降级fallback
              • 服务熔断break
                • 服务限流flowlimit
                • Hystrix案例
                  • 构建模块
                    • Hystrix解决故障的原理
                      • 服务降级
                        • 降级配置
                        • 服务提供者
                        • 服务消费者
                        • 代码膨胀问题与解决方案
                        • 将熔断响应从业务代码中抽取出去
                      • 服务熔断
                        • 服务熔断理论
                        • 构建实例
                        • 结论
                      • 服务限流(后续见sentinel)
                      • Hystrix工作流程
                        • Hystrix工作流程
                          • 官网图例
                          • 步骤说明
                      • 服务监控hystrixDashboard
                        • 概述
                          • 构建HystrixDashboard仪表盘模块9001
                            • Hystrix-DashBoard仪表盘数据
                            相关产品与服务
                            微服务引擎 TSE
                            微服务引擎(Tencent Cloud Service Engine)提供开箱即用的云上全场景微服务解决方案。支持开源增强的云原生注册配置中心(Zookeeper、Nacos 和 Apollo),北极星网格(腾讯自研并开源的 PolarisMesh)、云原生 API 网关(Kong)以及微服务应用托管的弹性微服务平台。微服务引擎完全兼容开源版本的使用方式,在功能、可用性和可运维性等多个方面进行增强。
                            领券
                            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档