当前位置:网站首页>Sentinel的快速入门,三分钟带你体验流量控制
Sentinel的快速入门,三分钟带你体验流量控制
2022-06-29 19:58:00 【掉头发的王富贵】
什么是流量控制
流量控制在网络传输中是一个常用的概念,它用于调整网络包的发送数据。然而,从系统稳定性角度考虑,在处理请求的速度上,也有非常多的讲究。任意时间到来的请求往往是随机不可控的,而系统的处理能力是有限的。我们需要根据系统的处理能力对流量进行控制。Sentinel
作为一个调配器,可以根据需要把随机的请求调整成合适的形状,如下图所示:

流量控制设计理念
流量控制有以下几个角度:
资源的调用关系,例如资源的调用链路,资源和资源之间的关系;
运行指标,例如 QPS、线程池、系统负载等;
控制的效果,例如直接限流、冷启动、排队等。
Sentinel 的设计理念是让您自由选择控制的角度,并进行灵活组合,从而达到想要的效果。
上面介绍完了,下面带大家来快速体验一下sentinel,查看一下他的效果。
第一步,创建一个springboot工程

第二步,引入sentinel依赖
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-core</artifactId>
<version>1.7.2</version>
</dependency>

第三步,编写TestController类

第四步,编写sentinel的相关方法
@PostConstruct
public void initFlowRules() {
List<FlowRule> rules = new ArrayList<>();
FlowRule flowRule = new FlowRule();
flowRule.setResource("testSentinel");
flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
//限流一秒钟超过两次
flowRule.setCount(2);
rules.add(flowRule);
FlowRuleManager.loadRules(rules);
}

@PostConstruct这个注解的作用就是在这个TestController类被实例化的时候调用这个方法,
flowRule.setCount(2);
这里的意思就是控制一次请求在一秒内只能调用两次
第五步,编写测试方法
@GetMapping("/hello")
public String hello() {
try(Entry entry = SphU.entry("testSentinel")) {
return "hello sentinel";
} catch (BlockException e) {
e.printStackTrace();
return "系统繁忙";
}
}

第六步,测试我们的方法
如果我们正常调用:
如果我们一次点击超过一秒内两次:
仓库地址:
边栏推荐
- 【摸鱼神器】UI库秒变低代码工具——表单篇(一)设计
- Detailed description of gaussdb (DWS) complex and diverse resource load management methods
- How important is it to make a silver K-line chart?
- [sword finger offer] 51 Reverse pair in array
- 测试方法学习
- How to set a pod to run on a specified node
- XSS漏洞
- Nacos problem
- Union find
- 14.04 million! Sichuan provincial human resources and social security department relational database and middleware software system upgrade procurement bidding!
猜你喜欢

【精品】pinia详解

Linux安装MySQL8

mysql远程连接

There is no small green triangle on the method in idea

data link layer

There are more than 20 databases in a MySQL with 3306 ports. How can I backup more than 20 databases with one click and do system backup to prevent data from being deleted by mistake?
![[fishing artifact] code tool for lowering the seconds of UI Library -- form part (I) design](/img/ad/0efd744334bf648b149aa1841b58af.png)
[fishing artifact] code tool for lowering the seconds of UI Library -- form part (I) design

苹果iPhone手机升级系统内存空间变小不够如何解决?

一个超赞的开源的图片去水印解决方案

Real time tracking of bug handling progress of the project through metersphere and dataease
随机推荐
罗清启:高端家电已成红海?卡萨帝率先破局
【U盘检测】为了转移压箱底的资料,买了个2T U盘检测仅仅只有47G~
Linux安装MySQL8
Flume配置4——自定義Source+Sink
Static static member variables use @value injection
ASP.Net Core创建Razor页面上传多个文件(缓冲方式)(续)
[USB flash disk test] in order to transfer the data at the bottom of the pressure box, I bought a 2T USB flash disk, and the test result is only 47g~
JMeter BeanShell explanation and thread calling
剑指 Offer 59 - II. 队列的最大值
Canonical engineers are trying to solve the performance problem of Firefox snap
WPS和Excele
Nacos problem
Zotero journal automatic matching update influence factor
freemarker模板框架生成图片
Dynamics CRM: 本地部署的服务器中, Sandbox, Unzip, VSS, Asynchronous还有Monitor服务的作用
What is a database? Database detailed notes! Take you into the database ~ you want to know everything here!
[fishing artifact] code tool for lowering the seconds of UI Library -- form part (I) design
Dynamics crm: among locally deployed servers, sandbox, unzip, VSS, asynchronous and monitor services
In 2022, the financial interest rate has dropped, so how to choose financial products?
The concept and properties of mba-day26 number