当前位置:网站首页>【微服务~Sentinel】Sentinel降级、限流、熔断
【微服务~Sentinel】Sentinel降级、限流、熔断
2022-07-25 11:20:00 【陶然同学】

这里是【微服务~Sentinel】,关注我学习微服务不迷路
如果对你有帮助,给博主一个免费的点赞以示鼓励
欢迎各位点赞评论收藏️
专栏介绍
【微服务~Sentinel】 目前主要更新微服务,一起学习一起进步。
本期介绍
本期主要介绍Sentinel
文章目录
微服务常见概念
官网:quick-start
服务雪崩
服务雪崩:在整条链路的服务中,一个服务失败,导致整条链路的服务都失败的情形。
存在整条链路服务(Service A、Service B、Service C)
Service A 流量突然性增加,导致Service B 和Service C 流量也增加。
Service C 因为抗不住请求,变得不可用。导致Service B的请求变得阻塞。
当Service B的资源耗尽,Service B就会变得不可用。
最后 Service A 不可用。

服务熔断
服务熔断:当下游的服务因为某种原因突然变得不可用或响应过慢,上游服务为了保证自己整体服务的可用性,不再继续调用目标服务,直接返回,快速释放资源。如果目标服务情况好转则恢复调用。

最开始处于
closed状态,一旦检测到错误到达一定阈值,便转为open状态;这时候会有个 reset timeout,到了这个时间了,会转移到
half open状态;尝试放行一部分请求到后端,一旦检测成功便回归到
closed状态,即恢复服务;
服务降级
什么是服务降级呢?
当下游的服务因为某种原因响应过慢,下游服务主动停掉一些不太重要的业务,释放出服务器资源,增加响应速度!
当下游的服务因为某种原因不可用,上游主动调用本地的一些降级逻辑,避免卡顿,迅速返回给用户!
熔断和降级的区别
服务熔断和服务降级的区别?
服务降级有很多种降级方式!如开关降级、限流降级、熔断降级!
服务熔断属于降级方式的一种!
当发生下游服务不可用的情况,熔断和降级必定是一起出现。
服务降级大多是属于一种业务级别的处理,熔断属于框架层级的实现
开关降级
在配置中心配置一个开关(变量),在配置中心更改开关,决定哪些服务进行降级
Sentinel介绍
Sentinel :一个高可用的流量控制与防护组件,保障微服务的稳定性。
Sentinel分为两个部分,sentinel-core与sentinel-dashboard。
sentinel-core 部分能够支持在本地引入sentinel-core进行限流规则的整合与配置。
sentinel-dashboard 则在core之上能够支持在线的流控规则与熔断规则的维护与调整等。
core降级

现象1
提供者搭建集群(8170/8270),调用者调用,此时关闭提供者的一个服务(8270)
存在现象:访问8170成功访问,不能访问8270
略有卡顿,稍等片刻后,不再卡顿。
现象2
提供者搭建集群(8170/8270),调用者调用,此时关闭提供者的所有服务
现象:无法访问

降级操作
添加坐标

<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>修改yml文件,开启feign对sentinel的支持

feign:
sentinel:
enabled: true修改启动类,开启feign

package com.czxy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient //服务发现
@EnableFeignClients //远程调用
public class TestNacosConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(TestNacosConsumerApplication.class, args );
}
}修改Feign实现
package com.czxy.feign;
import org.springframework.stereotype.Component;
@Component
public class EchoFeignFallback implements EchoFeign {
@Override
public String echo(String string) {
return "降级处理:" + string;
}
}package com.czxy.feign;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
// @FeignClient(value = "服务名", path = "controller配置的路径" )
@FeignClient(value = "service-provider", fallback = EchoFeignFallback.class )
public interface EchoFeign {
// 与 nacos-provider-2.1>EchoController声明的方法的完全一致
@GetMapping("/echo/{string}")
public String echo(@PathVariable String string);
}关闭服务提供者,测试
注意:需重启服务

边栏推荐
- 苹果供应链十年浮沉:洋班主任和它的中国学生们
- [multimodal] transferrec: learning transferable recommendation from texture of modality feedback arXiv '22
- 【GCN-RS】Region or Global? A Principle for Negative Sampling in Graph-based Recommendation (TKDE‘22)
- The applet image cannot display Base64 pictures. The solution is valid
- Zero-Shot Image Retrieval(零样本跨模态检索)
- I advise those students who have just joined the work: if you want to enter the big factory, you must master these concurrent programming knowledge! Complete learning route!! (recommended Collection)
- R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化点状条带图、设置palette参数配置不同水平数据点的颜色、设置add参数在点状条带图中添加均值标准差竖线
- Learning to Pre-train Graph Neural Networks(图预训练与微调差异)
- Solved files' name is invalid or doors not exist (1205)
- brpc源码解析(四)—— Bthread机制
猜你喜欢
随机推荐
LeetCode 50. Pow(x,n)
brpc源码解析(八)—— 基础类EventDispatcher详解
Video Caption(跨模态视频摘要/字幕生成)
The bank's wealth management subsidiary accumulates power to distribute a shares; The rectification of cash management financial products was accelerated
Multi label image classification
【高并发】高并发场景下一种比读写锁更快的锁,看完我彻底折服了!!(建议收藏)
【CTR】《Towards Universal Sequence Representation Learning for Recommender Systems》 (KDD‘22)
微信公众号开发 入手
R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化点状条带图、设置palette参数配置不同水平数据点的颜色、设置add参数在点状条带图中添加均值标准差竖线
Transformer variants (spark transformer, longformer, switch transformer)
【多模态】《TransRec: Learning Transferable Recommendation from Mixture-of-Modality Feedback》 Arxiv‘22
投屏收费背后:爱奇艺季度盈利,优酷急了?
那些离开网易的年轻人
Functions in JS
【高并发】我用10张图总结出了这份并发编程最佳学习路线!!(建议收藏)
GPT plus money (OpenAI CLIP,DALL-E)
Heterogeneous graph neural network for recommendation system problems (ackrec, hfgn)
油猴脚本链接
马斯克的“灵魂永生”:一半炒作,一半忽悠
Zero shot image retrieval (zero sample cross modal retrieval)



![[comparative learning] understanding the behavior of contractual loss (CVPR '21)](/img/96/9b58936365af0ca61aa7a8e97089fe.png)




