SpringCloud 尚硅谷 周阳教程学习 -- 第四部分高级 02 -- Sentinel分为流量控制,服务降级,服务熔断 三大类

本教程详细介绍阿里巴巴Sentinel实现服务限流、降级与熔断的方法。涵盖Sentinel的安装配置、流控规则设定及各类场景的应用,如QPS限制、RT熔断等。适合希望保障系统稳定性的开发者。

https://github.com/leelovejava/cloud2020

https://github.com/alibaba/spring-cloud-alibaba/wiki/Sentinel

Sentinel分为流量控制,服务降级,服务熔断 三大类
https://www.bilibili.com/video/BV18E411x7eT?p=111

P111_Sentinel是什么 07:03
P112_Sentinel下载安装运行 06:13
P113_Sentinel初始化监控 07:54

P114_Sentinel流控规则简介 03:04
P115_Sentinel流控-QPS直接失败 06:27
P116_Sentinel流控-线程数直接失败 06:07
P117_Sentinel流控-关联 07:14
P118_Sentinel流控-预热 08:14
P119_Sentinel流控-排队等待 05:32

P120_Sentinel降级简介 04:48
P121_Sentinel降级-RT 07:29
P122_Sentinel降级-异常比例 07:19
P123_Sentinel降级-异常数 04:16

P124_Sentinel热点key(上) 17:13
P125_Sentinel热点key(下) 10:59
P126_Sentinel系统规则 07:38
P127_SentinelResource配置(上) 10:47
P128_SentinelResource配置(中) 07:47
P129_SentinelResource配置(下) 04:16

P130_Sentinel服务熔断Ribbon环境预说 08:58
P131_Sentinel服务熔断无配置 04:22
P132_Sentinel服务熔断只配置fallback 04:12
P133_Sentinel服务熔断只配置blockHandler 04:10
P134_Sentinel服务熔断fallback和blockHandler都配置 04:47
P135_Sentinel服务熔断exceptionsToIgnore 02:34
P136_Sentinel服务熔断OpenFeign 09:50

P137_Sentinel持久化规则 10:31

P111_Sentinel是什么

服务降级,服务熔断,服务限流,服务雪崩 — Sentinel 可以防止

sentinel 官网:
sentinel git 地址:https://github.com/alibaba/sentinel
sentinel 中文文档: https://github.com/alibaba/Sentinel/wiki/%E4%BB%8B%E7%BB%8D

hystrix git 使用手册地址 : https://github.com/netflix/hystrix/wiki/How-To-Use

sentinel 下载地址:https://github.com/alibaba/Sentinel/releases
最新 1.8.0 ,阳哥使用 1.7.0

P112_Sentinel下载安装运行

Java8 运行环境
8080 端口不能被占用

C:******\sentinel\sentinel-1.7.0>java -jar sentinel-dashboard-1.7.0.jar
java -jar sentinel-dashboard-1.7.0.jar
localhost:8080/
sentinel
sentinel

P113_Sentinel初始化监控

运行 nacos 服务监控服务进程
C:******\nacos-server-1.1.4\nacos\bin>startup.cmd
http://localhost:8848/nacos
nacos / nacos

新建8401 工程

启动工程后,http://localhost:8080/ sentinel 中看 实时监控 簇点链路 两项

http://localhost:8401/testA

http://localhost:8401/testB

P114_Sentinel流控规则简介

流控模式: 直接 ,关联, 链路
流控效果: 快速失败,Warm Up, 排队等待

P115_Sentinel流控-QPS直接失败

默认,直接 快速失败模式
返回 Blocked by Sentinel(flow limiting)
在这里插入图片描述

P116_Sentinel流控-线程数直接失败

在这里插入图片描述

P117_Sentinel流控-关联

流控模式之关联
B惹事,A挂了
当与A关联的资源B达到阈值后,就限流自己
在这里插入图片描述A 是 B 的前一环节
B --------------------------------- A
支付接口达到阈值后---------限流订单接口

在这里插入图片描述

在这里插入图片描述在这里插入图片描述http://localhost:8401/testA
http://localhost:8401/testB

P118_Sentinel流控-预热

预热冷启动公式说明
https://github.com/alibaba/Sentinel/wiki/%E9%99%90%E6%B5%81—%E5%86%B7%E5%90%AF%E5%8A%A8
在这里插入图片描述在这里插入图片描述应用场景如:秒杀系统在开启瞬间,会有很多流量上来,很可能把系统打死,预热方式就是为了保护系统,可慢慢的把流量放进来,慢慢的把阈值增长到设置的阈值。

P119_Sentinel流控-排队等待

postman 设置访问testB, 循环30次,每次间隔200毫秒,
如果没有流控,直接就按照200毫秒的间隔访问了,
如果对testB 进行流控配置,表示单次访问间隔1秒钟,这样会按照1000毫秒的方式访问 testB
在这里插入图片描述

在这里插入图片描述

P120_Sentinel降级简介

熔断降级官方说明

https://github.com/alibaba/Sentinel/wiki/%E7%86%94%E6%96%AD%E9%99%8D%E7%BA%A7

RT 异常比例 异常数
在这里插入图片描述

P121_Sentinel降级-RT

RT: 平均响应时间 (1秒钟内的5个请求,响应市场超过阈值,<在未来一段时间内>就熔断 )
在这里插入图片描述在这里插入图片描述

P122_Sentinel降级-异常比例

在这里插入图片描述

P123_Sentinel降级-异常数

在这里插入图片描述
在这里插入图片描述

P124_Sentinel热点key(上)

官网介绍
https://github.com/alibaba/Sentinel/wiki/%E7%83%AD%E7%82%B9%E5%8F%82%E6%95%B0%E9%99%90%E6%B5%81

在这里插入图片描述
http://localhost:8401/testHotKey
http://localhost:8401/testHotKey?p1=1&p2=2

P125_Sentinel热点key(下)

P126_Sentinel系统规则

系统自适应限流
https://github.com/alibaba/Sentinel/wiki/%E7%B3%BB%E7%BB%9F%E8%87%AA%E9%80%82%E5%BA%94%E9%99%90%E6%B5%81

Sentinel 系统自适应限流从整体维度对应用入口流量进行控制

5种方式

Load 自适应(仅对 Linux/Unix-like 机器生效):系统的 load1 作为启发指标,进行自适应系统保护。当系统 load1 超过设定的启发值,且系统当前的并发线程数超过估算的系统容量时才会触发系统保护(BBR 阶段)。系统容量由系统的 maxQps * minRt 估算得出。设定参考值一般是 CPU cores * 2.5。
CPU usage(1.5.0+ 版本):当系统 CPU 使用率超过阈值即触发系统保护(取值范围 0.0-1.0),比较灵敏。
平均 RT:当单台机器上所有入口流量的平均 RT 达到阈值即触发系统保护,单位是毫秒。
并发线程数:当单台机器上所有入口流量的并发线程数达到阈值即触发系统保护。
入口 QPS:当单台机器上所有入口流量的 QPS 达到阈值即触发系统保护。

P127_SentinelResource配置(上)

http://localhost:8401/byResource

http://localhost:8401/RateLimit/byUrl

P128_SentinelResource配置(中)

在这里插入图片描述在这里插入图片描述

P129_SentinelResource配置(下)

有代码方式 进行 流量控制,不推荐
还是使用注解方式处理,比较好
在这里插入图片描述

P130_Sentinel服务熔断Ribbon环境预说 在这里插入图片描述在这里插入图片描述在这里插入图片描述

P131_Sentinel服务熔断无配置

http://localhost:9003/paymentSQL/2
http://localhost:9004/paymentSQL/2

localhost:84/consumer/fallback/1
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

P132_Sentinel服务熔断只配置fallback

fallback 处理异常,让异常不再像上面一样直接给用户而是,抛给handlerFallback

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

P133_Sentinel服务熔断只配置blockHandler

在这里插入图片描述

P134_Sentinel服务熔断fallback和blockHandler都配置

两个异常都报,因为sentinel 异常在外边,所以先进入 blockHandler 异常

P135_Sentinel服务熔断exceptionsToIgnore

在这里插入图片描述在这里插入图片描述

在这里插入图片描述

P136_Sentinel服务熔断OpenFeign 在这里插入图片描述

激活sentinel 对 feign 的支持

feign:
sentinel:
enabled: true
在这里插入图片描述在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

P137_Sentinel持久化规则

搞了两个小时没有搞好 sentinel 注册到nacos
估计是版本问题吧
在这里插入图片描述

http://localhost:8401/rateLimit/byUrl

在这里插入图片描述


com.alibaba.csp
sentinel-datasource-nacos

在这里插入图片描述

在这里插入图片描述localhost:8401/rateLimit/byUrl

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值