当前位置:网站首页>Sentinel three flow control modes
Sentinel three flow control modes
2022-07-24 10:31:00 【Liu Chu, Ge Nian】
List of articles
Flow control mode
When adding a current limit rule , Click on advanced options , There are three options Flow control mode :
| Flow control mode | explain |
|---|---|
| direct | Count the requests for the current resource , When the threshold is triggered, the current resource is directly limited , It's also the default mode |
| relation | Count another resource related to the current resource , When the threshold is triggered , Limit the current resource |
| link | Count the requests to access this resource from the specified link , When the threshold is triggered , Limit the current of the specified link |
For example, in the figure below, we are Sentinel View the cluster link in the console , Select any requested flow control , Choose advanced options , You can see the flow control mode :

1. Direct mode
You can refer to the case of quick start test , This is the direct mode :https://yangyongli.blog.csdn.net/article/details/125948236
2. Association patterns
Association patterns : Count another resource related to the current resource , When the threshold is triggered , Limit the current resource
Configuration rules :

Syntax description : When /write When the resource access triggers the threshold , Would be right. /read Resource limiting , Avoid impact /write resources .
Use scenarios : For example, the user needs to modify the order status when paying , At the same time, the user needs to query the order . Queries and modifications compete for database locks , Create competition . The business requirement is to give priority to paying and updating orders , Therefore, when modifying the order business trigger threshold , You need to limit the flow of the query order business .
Requirement specification :
stay OrderController Create two new endpoints :/order/query and /order/update, No need to implement business
Configure flow control rules , When /order/ update Resources are accessed QPS exceed 5 when , Yes /order/query Request current limiting
1) Definition /order/query Endpoint , Simulate order query
@GetMapping("/query")
public String queryOrder() {
return " Order query succeeded ";
}
2) Definition /order/update Endpoint , Simulate order update
@GetMapping("/update")
public String updateOrder() {
return " Update order succeeded ";
}
Restart the service , Access two requests
see sentinel Cluster point link of console :

3) Configure flow control rules
Which end point is current limited , Just click the button behind which endpoint . We are inquiring about orders /order/query Current limiting , So click the button behind it :

Fill in flow control rules in the form :

If there is one more rule in the flow control rules, it will succeed :

4) stay Jmeter test
Test flow control mode - relation :

You can see 1000 Users ,100 second , therefore QPS by 10, Exceeded the threshold we set :5
see http request :

The goal of the request is /order/update, This breakpoint will trigger the threshold .
But the goal of current limiting is /order/query, We visit... In the browser , It can be found that the current is limited :

When the update order request ends , We then visit the query request , succeed

5) summary
The association pattern can be used when the following conditions are met :
- Two competing resources , For example, query and update in the above , Give priority to the update operation
- A higher priority , A lower priority .
3. Link mode
Link mode : Statistics are only made for requests to access this resource from the specified link , Determine if the threshold is exceeded .
Configuration example :
For example, there are two request links :
/test1 --> /common
/test2 --> /common
If you only want statistics from /test2 Enter into /common Request , Then you can configure :

Practical cases
demand : There are businesses to query orders and create orders , Both need to query products . Statistics on requests from query orders to query goods , And set current limit .
step :
stay OrderService Add a queryGoods Method , No need to implement business
stay OrderController in , reform /order/query Endpoint , call OrderService Medium queryGoods Method
stay OrderController Add a /order/save The endpoint of , call OrderService Of queryGoods Method
to queryGoods Set current limiting rules , from /order/query Get into queryGoods Method limitations QPS Must be less than 2
Realization :
1) Add a method to query goods
stay order-service In service , to OrderService Class add a queryGoods Method :
public void queryGoods(){
System.err.println(" Query products ");
}
2) When inquiring about the order , Query products
stay order-service Of OrderController in , modify /order/query The business logic of the endpoint :
@GetMapping("/query")
public String queryOrder() {
// Query products
orderService.queryGoods();
// Query order
System.out.println(" Query order ");
return " Order query succeeded ";
}
3) New order , Query products
stay order-service Of OrderController in , modify /order/save Endpoint , Simulate new orders :
@GetMapping("/save")
public String saveOrder() {
// Query products
orderService.queryGoods();
// Query order
System.err.println(" New order ");
return " New order successfully ";
}
4) Add a resource tag to the query item
By default ,OrderService The method in is not to be Sentinel Monitored , We need our own annotations to mark the methods to be monitored .
to OrderService Of queryGoods Method add @SentinelResource annotation :
@SentinelResource("goods")
public void queryGoods(){
System.err.println(" Query products ");
}
In link mode , It monitors two links from different sources . however sentinel The default will be to enter SpringMVC Set the same... For all requests root resources , Will cause link mode failure .
We need to close this pair of SpringMVC Resource aggregation , modify order-service Service application.yml file :
spring:
cloud:
sentinel:
web-context-unify: false # close context Integrate
Restart the service , visit /order/query and /order/save, You can see that sentinel Cluster point link rules , New resources have emerged :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-unj0KVdU-1658562805502)(C:/Users/Yang/AppData/Roaming/Typora/typora-user-images/image-20220723154631294.png)]
5) Add flow control rules
Click on goods The flow control button behind the resource , Fill in the following information in the pop-up form :


Only statistics from /order/query Get into /goods Resources for ,QPS The threshold for 2, If it exceeds, it is limited by current .

6)Jmeter test

You can see here 200 Users ,50 Within seconds ,QPS( Query rate per second ) by 4, Exceeded the threshold we set 2
One http The request is to access /order/save:

Result of operation , Completely unaffected :

The other is to visit /order/query:

Running results , Every time only 2 through :

summary
What are the flow control modes ?
| Flow control mode | explain |
|---|---|
| direct | Count the requests for the current resource , When the threshold is triggered, the current resource is directly limited , It's also the default mode |
| relation | Count another resource related to the current resource , When the threshold is triggered , Limit the current resource |
| link | Count the requests to access this resource from the specified link , When the threshold is triggered , Limit the current of the specified link |
边栏推荐
- ZOJ 2770 differential restraint system -- 2 -- May 20, 2022
- Domain Driven practice summary (basic theory summary and analysis + Architecture Analysis and code design + specific application design analysis V) [easy to understand]
- Sentinel three flow control effects
- Mina framework introduction "suggestions collection"
- 每日三题 7.22
- Scan line, weight segment tree
- Volcanic engine: open ByteDance, the same AI infrastructure, a system to solve multiple training tasks
- Will not be rejected! Learn the distributed architecture notes sorted out by Alibaba Daniel in 35 days, with a salary increase of 20K
- 分布式锁-Redission 原理分析
- 2022: I feel like sleeping for the first time during the day
猜你喜欢

The concept and representation of a tree

Figure model 2-2022-5-13

MySQL - unique index

WEB安全基础 - - -文件上传(文件上传绕过)

Ffmpeg splash screen solution (modify the source code and discard incomplete frames)

Uniapp calendar component

机器学习小试(11)验证码识别测试-使用Qt与Tensorflow2进行深度学习实验

2022, enterprise informatization construction based on Unified Process Platform refers to thubierv0.1

数组元素移除问题

图模型2--2022-5-13
随机推荐
ES6 question
Create a vertical seekbar from scratch
DSP CCS software simulation
Nirvana rebirth! Byte Daniel recommends a large distributed manual, and the Phoenix architecture makes you become a God in fire
How does ribbon get the default zoneawareloadbalancer?
MySQL——锁
What did zoneawareloadbalancer of ribbon and its parent class do?
Pytorch common tricks summary
Ffmpeg splash screen solution (modify the source code and discard incomplete frames)
Notes on using setupproxy
2022, enterprise informatization construction based on Unified Process Platform refers to thubierv0.1
2022, our small goal
zoj1137+作业1--2022年5月28日
Sub query of multi table query_ Single row and single column
CMS vulnerability recurrence - ultra vires vulnerability
757. Set the intersection size to at least 2: greedy application question
Differential restraint system -- 1 and 2 -- May 27, 2022
Erlang learning 02
Arduino + AD9833 波形发生器
MySQL - 普通索引