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

第六步,测试我们的方法
如果我们正常调用:
如果我们一次点击超过一秒内两次:
仓库地址:
边栏推荐
- 测试方法学习
- Connaissance générale des paramètres de sécurité du serveur Cloud
- 通过MeterSphere和DataEase实现项目Bug处理进展实时跟进
- The era of data security solutions
- 【Try to Hack】vulnhub narak
- 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?
- File contains vulnerability
- 如何设置 Pod 到指定节点运行
- 【网络方向实训】-企业园区网络设计-【Had Done】
- 一个超赞的开源的图片去水印解决方案
猜你喜欢
随机推荐
Test method learning
2022年深圳市福田区支持招商引资若干政策
[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~
Sword finger offer 66 Building a product array
Foxit software was invited to appear at the 2022 advanced manufacturing digital intelligence development forum
Flume配置3——拦截器过滤
7.取消与关闭
Dynamics crm: among locally deployed servers, sandbox, unzip, VSS, asynchronous and monitor services
云服务器的安全设置常识
Game maker Foundation presents: Valley of belonging
苹果iPhone手机升级系统内存空间变小不够如何解决?
In 2022, the financial interest rate has dropped, so how to choose financial products?
1404万!四川省人社厅关系型数据库及中间件软件系统升级采购招标!
Physical verification LVS process and Technology (Part I)
Sword finger offer 41 Median in data stream
La collection numérique Meng xiangshun, artiste national du tigre peint, est disponible en quantité limitée et est offerte avec Maotai de l'année du tigre
网站压力测试工具——Webbench
proxmox集群节点崩溃处理
关于印发宝安区重点产业项目和总部项目遴选及用地保障实施细则(2022修订版)的通知
Nutch2.1在Windows平台上使用Eclipse debug 存储在MySQL的搭建过程









