当前位置:网站首页>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 "系统繁忙";
}
}

第六步,测试我们的方法
如果我们正常调用:
如果我们一次点击超过一秒内两次:
仓库地址:
边栏推荐
- Flume theory
- What is a database? Database detailed notes! Take you into the database ~ you want to know everything here!
- Flutter calls Baidu map app to realize location search and route planning
- 【剑指Offer】51. 数组中的逆序对
- 从众伤害的是自己
- 数据链路层
- A keepalived high availability accident made me learn it again!
- Notepad++ -- macro (record operation process)
- proxmox集群节点崩溃处理
- Etcd database source code analysis - put process of server
猜你喜欢

Etcd database source code analysis - put process of server
![[observation] softcom power liutianwen: embrace change and](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[observation] softcom power liutianwen: embrace change and "follow the trend" to become an "enabler" of China's digital economy

【Try to Hack】vulnhub narak

雲服務器的安全設置常識

Real time tracking of bug handling progress of the project through metersphere and dataease

罗清启:高端家电已成红海?卡萨帝率先破局
![[network orientation training] - Enterprise Park Network Design - [had done]](/img/12/17f95378fcc6d0fef15feb99cc4f49.png)
[network orientation training] - Enterprise Park Network Design - [had done]

ASP.Net Core创建Razor页面上传多个文件(缓冲方式)(续)

Linux安装MySQL5

Tiger painter mengxiangshun's digital collection is on sale in limited quantities and comes with Maotai in the year of the tiger
随机推荐
Dynamics crm: among locally deployed servers, sandbox, unzip, VSS, asynchronous and monitor services
proxmox集群节点崩溃处理
idea中方法上没有小绿色三角
雪花id,分布式唯一id
File contains vulnerability
使用Gunicorn部署web.py应用
Union find
JMeter BeanShell explanation and thread calling
数据链路层
Configuration du Flume 4 - source personnalisée + sink
JVM (4) bytecode technology + runtime optimization
Flume理论
In 2022, the financial interest rate has dropped, so how to choose financial products?
Spark存储体系底层架构剖析-Spark商业环境实战
Startservice() procedure
[boutique] detailed explanation of Pinia
2022年深圳市福田区支持先进制造业发展若干措施
data link layer
npm ERR! fatal: early EOF npm ERR! fatal: index-pack failed
云服务器的安全设置常识