当前位置:网站首页>Sentinel's quick start takes you through flow control in three minutes
Sentinel's quick start takes you through flow control in three minutes
2022-06-29 20:18:00 【Wangfugui who lost his hair】
What is flow control
Flow control is a common concept in network transmission , It is used to adjust the sending data of network packets . However , From the perspective of system stability , In terms of the speed of processing requests , There is also a lot of stress . Requests coming at any time are often random and uncontrollable , And the processing power of the system is limited . We need to control the flow according to the processing capacity of the system .Sentinel
As a tuner , You can adjust random requests to the right shape as needed , As shown in the figure below :

Flow control design concept
Flow control has the following angles :
Resource call relationship , For example, the call link of resources , The relationship between resources ;
Operation index , for example QPS、 Thread pool 、 System load, etc ;
The effect of control , For example, direct current limiting 、 Cold start 、 Line up, etc .
Sentinel The design concept is to let you freely choose the angle of control , And flexible combination , So as to achieve the desired effect .
That's all , Let's take you to a quick experience sentinel, Check his effect .
First step , Create a springboot engineering

The second step , introduce sentinel rely on
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-core</artifactId>
<version>1.7.2</version>
</dependency>

The third step , To write TestController class

Step four , To write sentinel Related methods
@PostConstruct
public void initFlowRules() {
List<FlowRule> rules = new ArrayList<>();
FlowRule flowRule = new FlowRule();
flowRule.setResource("testSentinel");
flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
// Limit the current more than twice a second
flowRule.setCount(2);
rules.add(flowRule);
FlowRuleManager.loadRules(rules);
}

@PostConstruct The purpose of this annotation is to TestController This method is called when the class is instantiated ,
flowRule.setCount(2);
This means that a request can only be called twice in a second
Step five , Write test methods
@GetMapping("/hello")
public String hello() {
try(Entry entry = SphU.entry("testSentinel")) {
return "hello sentinel";
} catch (BlockException e) {
e.printStackTrace();
return " The system is busy ";
}
}

Step six , Test our method
If we call normally :
If we click more than twice in a second :
Warehouse address :
边栏推荐
猜你喜欢

lock4j--分布式锁中间件--自定义获取锁失败的逻辑

CorelDRAW最新24.1.0.360版本更新介绍讲解

A keepalived high availability accident made me learn it again!

18. `bs对象.节点名.next_sibling` previous_sibling 获取兄弟节点

Three.js开发:粗线的画法

0/1 score planning topic

Flume配置4——自定義Source+Sink

liunx指令
![[network orientation training] - Enterprise Park Network Design - [had done]](/img/12/17f95378fcc6d0fef15feb99cc4f49.png)
[network orientation training] - Enterprise Park Network Design - [had done]

ETCD数据库源码分析——服务端PUT流程
随机推荐
Cmake development - Multi Directory Project
Nutch2.1在Windows平台上使用Eclipse debug 存储在MySQL的搭建过程
2021 CCPC 哈尔滨 J. Local Minimum (思维题)
Flume ng configuration
第二章(物理层)
Summary of swift optional values
How to set a pod to run on a specified node
Oracle11.2.0.4-rac cluster hang analysis record
Fastadmin background setting radio button
0/1分数规划专题
Hangfire详解
jfinal中如何使用过滤器监控Druid监听SQL执行?
[compilation principle] syntax analysis
Comparable comparator writing & ClassCastException class conversion exception
【Try to Hack】vulnhub narak
Understanding of software test logic coverage
PowerShell command outputs only a list of directories
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?
Linux安装MySQL5
NLP - giza++ implements word alignment