当前位置:网站首页>Sentinel simple current limiting and degradation demo problem record
Sentinel simple current limiting and degradation demo problem record
2022-07-25 19:44:00 【Hurry up to Friday】
The problem record
- download sentinel-dashboard, After starting with the command line , The console page can be accessed normally , But I add configuration to the project configuration file :
spring.cloud.sentinel.transport.port=8719
spring.cloud.sentinel.transport.dashboard=localhost:9090
Then keep refreshing the console page , There is no service I registered .
resolvent :sentinel-dashboard The default is lazy loading mode , Need to add sentinel-dashboard After the configuration , Visit the registered service , Refresh the console page again .
- In the test sentinel When the number of concurrent threads is controlled , What I set in the rules is 4 individual :
List<FlowRule> rules = new ArrayList<>();
FlowRule rule = new FlowRule();
rule.setResource(RESOURCE_KEY);
rule.setCount(4);
rule.setGrade(RuleConstant.FLOW_GRADE_THREAD);
rule.setLimitApp("default");
rules.add(rule);
FlowRuleManager.loadRules(rules);
Originally, I thought I could only make 4 Threads through , But the printing result is not like this , But sometimes :

resolvent :sentinel It is to limit the number of threads accessing resources at that time , That is, when the number of runtime threads accessing resources exceeds the set threshold , Will adopt the set strategy , Directly refuse or something else , The default is to reject directly ; But when the life cycle of a thread that accesses resources ends , New requests can be released , Because my resource method didn't have time-consuming operations or sleep waiting operations, it ended soon , So new threads can access resources .

When writing the case of concurrent thread control number , At first, I wrote as above , But the printing result was unexpected , Because the threshold I set is 4, however thread Variables and set The length of is significantly larger than 4 Of .
Solution : Put the red box below , That is to say testSleep The following three lines , Put it in entry != null Of if After judging the inside , The print result is right . Because normally, after a thread accessing resources passes , Walk the finally block , Go again testSleep The following three lines , Because at this time, this thread has accessed resources , So the next thread can continue to access , But because this thread is sleep Medium 500 In milliseconds , other 9 Threads are accessible , And soon , therefore set Many times add operation ,500 Milliseconds later remove operation , therefore set.size() The value of 500 Within milliseconds, it approaches 10, Then subtract another .thread It's the same thing .
- When writing a cold start test case , The rules are set as follows :
List<FlowRule> rules = new ArrayList<>();
FlowRule warmUpRule = new FlowRule();
warmUpRule.setResource(RESOURCE_KEY);
warmUpRule.setCount(3);
warmUpRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
warmUpRule.setLimitApp("default");
warmUpRule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_WARM_UP);
warmUpRule.setWarmUpPeriodSec(10);
rules.add(warmUpRule);
FlowRuleManager.loadRules(rules);
And the thread that I access resources only creates 3 individual , Originally I expected , There should be no current limit , But the printing result is not like this :

block It's always worth it , Sometimes it's 1 Sometimes it's 2, I have been unable to understand , The threshold I set is 3, It should all be accessible .
resolvent : Then I thought of what I set warmUpRule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_WARM_UP) This code , It should be set to cold start , The explanation of cold start in the official document is :
This method is mainly used when the system is at low water level for a long time , When the flow suddenly increases , Directly raising the system to high water level may crush the system in an instant . adopt " Cold start ", Let the flow slowly increase , Gradually increase to the upper limit of the threshold within a certain period of time , Give the cooling system a warm-up time , Avoid crushing the cold system .
So I wonder if : Although only 3 Threads accessing resources , But the flow increased every time of cold start is 1, So every time there is a finite flow .
After changing the code , It makes sense to find the print result :

The flow per second is generally increased ( I don't know why it came out 4), Up to the threshold I set (10), It's stable .
How to increase is not important , It is important to be sure that the traffic is slowly increasing towards the threshold .
- As if setStrategy and setControlBehavior It can't be used together , After I configured it together, there was a problem :

The threshold I set is 10, however pass The value of is greater than 10 Of .
resolvent : Not configured together .
- In writing, the abnormal proportion is degraded demo When , At first, my code was like this :

resolvent : I didn't catch BlockException Out of the exception , I found that the result printed by the console showed that an exception occurred , In a degraded state , But I set the fuse duration to 10s, should 10s Then release one , But until the end ,total,pass,block All are 0;
Later, I tried to catch exceptions , Just find the result .
边栏推荐
- University of California | feasible confrontation robust reinforcement learning for unspecified environments
- 加州大学|用于未指定环境的可行对抗鲁棒强化学习
- C语言学习日记3——realloc函数
- 485 current acquisition module dam-8041
- Network data request for wechat applet development
- Selenium 设置元素等待的三种方式详解
- Network design and planning of a company
- [artifact] screenshot + mapping tool snipaste
- Creative drop-down multi choice JS plug-in download
- 随机梯度下降法、牛顿法、冲量法、AdaGrad、RMSprop以及Adam优化过程和理解
猜你喜欢

Scala基础【集合01】

When the V100 of mindpole 8 card is trained to 101 epochs, an error of reading data timeout is reported

Small program completion work wechat campus maintenance application small program graduation design finished product (2) small program function

哪吒 D1-H 测试 microbench

Deeplobv1 and V2

YOLOv7论文部分解读【含自己的理解】

03-树1 树的同构

tiktok如何破零播放?

Code sharing of social chat platform developed by dating website (III)

网络数据包多层传输演示
随机推荐
Solve the problem that the win10 account has no administrator rights
[good book recommendation] - authoritative guide to Ethernet (2nd Edition)
创意下拉多选js插件下载
Selenium runs slowly - speed up by setting selenium load policy
[server data recovery] a data recovery case of a brand ProLiant server raid paralysis, database file loss, and database file backup damage
什么是唯心主义
阿姆利塔工程学院|用于情感分析的方面术语提取中优化采样的强化主动学习方法
C merge set
[hdlbits questions] Verilog language (3) modules: hierarchy section
Selenium运行慢 - 通过设置selenium加载策略加快运行速度
Website construction of information exchange platform for China Africa South South cooperation based on PHP
Old wine in new bottles -- sample analysis of recent apt32 (sea Lotus) organizational attacks
Split very long line of words into separate lines of max length
VMware 虚拟机下载、安装和使用教程
Nezha d1-h test microbench
Network packet multi-layer transmission demonstration
Selenium 设置元素等待的三种方式详解
[wp]ctfshow-web入门-爆破
某公司网络设计与规划
国内常见php的CMS建站系统情况分析