当前位置:网站首页>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 |
边栏推荐
- Domain Driven practice summary (basic theory summary and analysis + Architecture Analysis and code design + specific application design analysis V) [easy to understand]
- Google cooperates with colleges and universities to develop a general model, proteogan, which can design and generate proteins with new functions
- ES6 question
- Segment tree--
- Mina framework introduction "suggestions collection"
- 分布式锁-Redission 原理分析
- Android uses JDBC to connect to a remote database
- Analysis of distributed lock redistribution principle
- Erlang studies abroad
- How to solve the problem of robot positioning and navigation in large indoor scenes with low-cost solutions?
猜你喜欢

Analysis of Kube proxy IPVS mode

图像处理:RGB565转RGB888

Simply use golang SQLC to generate MySQL query code

常量指针、指针常量

In depth analysis of common cross end technology stacks of app
![[electronic device note 3] capacitance parameters and type selection](/img/d2/1ddb309a8f3cfe5f65c71964052006.png)
[electronic device note 3] capacitance parameters and type selection

Association Rules -- July 10, 2022

Arduino + AD9833 waveform generator

Uniapp calendar component

MySQL - 多列索引
随机推荐
Golang migrate is easy to use
ES6 question
Add a love power logo to your website
Simply use golang SQLC to generate MySQL query code
Sentinel three flow control effects
图像处理:RGB565转RGB888
ECCV 2022 | Tsinghua proposes the first transformer to embed spectral sparsity
多表查询之子查询_单行单列情况
MySQL——锁
Set scrolling for the box
zoj-Swordfish-2022-5-6
【剑指 Offer II 115. 重建序列】
MySQL - 更新表中的数据记录
Configuration description and componentization development steps of various documents in the scaffold
协议圣经-谈端口和四元组
差分约束系统---1且2--2022年5月27日
MySQL - lock
New:Bryntum Grid 5.1.0 Crack
很佩服的一个Google大佬,离职了。。
Adobe substance 3D Designer 2021 software installation package download and installation tutorial