当前位置:网站首页>【微服务~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);
}关闭服务提供者,测试
注意:需重启服务

边栏推荐
- Scott+Scott律所计划对Yuga Labs提起集体诉讼,或将确认NFT是否属于证券产品
- 【无标题】
- [USB device design] - composite device, dual hid high-speed (64BYTE and 1024byte)
- Functions in JS
- Meta learning (meta learning and small sample learning)
- [GCN multimodal RS] pre training representations of multi modal multi query e-commerce search KDD 2022
- 阿里云技术专家秦隆:可靠性保障必备——云上如何进行混沌工程
- LeetCode 50. Pow(x,n)
- [comparative learning] understanding the behavior of contractual loss (CVPR '21)
- Brpc source code analysis (VIII) -- detailed explanation of the basic class eventdispatcher
猜你喜欢

Zero-Shot Image Retrieval(零样本跨模态检索)

Figure neural network for recommending system problems (imp-gcn, lr-gcn)

'C:\xampp\php\ext\php_ zip. Dll'-%1 is not a valid Win32 Application Solution

【AI4Code】《Pythia: AI-assisted Code Completion System》(KDD 2019)

浅谈低代码技术在物流管理中的应用与创新

【AI4Code】《CoSQA: 20,000+ Web Queries for Code Search and Question Answering》 ACL 2021

【AI4Code】《GraphCodeBERT: Pre-Training Code Representations With DataFlow》 ICLR 2021

brpc源码解析(七)—— worker基于ParkingLot的bthread调度

OSPF综合实验

【多模态】《HiT: Hierarchical Transformer with Momentum Contrast for Video-Text Retrieval》ICCV 2021
随机推荐
【云驻共创】AI在数学界有哪些作用?未来对数学界会有哪些颠覆性影响?
Mirror Grid
【CTR】《Towards Universal Sequence Representation Learning for Recommender Systems》 (KDD‘22)
图神经网络用于推荐系统问题(IMP-GCN,LR-GCN)
【GCN-RS】Towards Representation Alignment and Uniformity in Collaborative Filtering (KDD‘22)
selenium使用———xpath和模拟输入和模拟点击协作
PHP 上传ftp路径文件到外网服务器上 curl base64图片
【GCN-RS】Are Graph Augmentations Necessary? Simple Graph Contrastive Learning for RS (SIGIR‘22)
LeetCode 50. Pow(x,n)
Management of software defects
从云原生到智能化,深度解读行业首个「视频直播技术最佳实践图谱」
JS operator
Scott+Scott律所计划对Yuga Labs提起集体诉讼,或将确认NFT是否属于证券产品
JS 面试题:手写节流(throttle)函数
Multi-Label Image Classification(多标签图像分类)
【AI4Code】《Contrastive Code Representation Learning》 (EMNLP 2021)
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)
php curl post Length Required 错误设置header头
Brpc source code analysis (VI) -- detailed explanation of basic socket
【AI4Code】《IntelliCode Compose: Code Generation using Transformer》 ESEC/FSE 2020