当前位置:网站首页>[microservices sentinel] hotspot rules | authorization rules | cluster flow control | machine list
[microservices sentinel] hotspot rules | authorization rules | cluster flow control | machine list
2022-06-27 13:54:00 【Bulst】
List of articles
Hot spot rules
Hot spots are frequently accessed data . Most of the time, we want to count the most frequently visited data in a hotspot Top K data , And restrict their access . such as :
goods ID Is the parameter , Count the most frequently purchased items in a period of time ID And limit
user ID Is the parameter , For users who visit frequently over a period of time ID Limit
Hot spot parameter current limiting will count the hot spot parameters in the incoming parameters , And according to the configured current limiting threshold and mode , Restrict the flow of resource calls with hotspot parameters . Hot spot parameter current limiting can be regarded as a special flow control , Only valid for resource calls with hotspot parameters .
Sentinel utilize LRU Policy counts the most recently visited hotspot parameters , Combined with token bucket algorithm to carry out parameter level flow control .

at present Sentinel Self contained adapter only Dubbo The method embeds points with hot spot parameters , Other adaptation modules ( Such as Web) Hotspot rules are not supported by default , You can specify a new resource name and pass in the desired parameters by customizing the embedding point .
Note that the resource name of the user-defined embedding point should not duplicate the resource name generated by the adaptation module , Otherwise, it will cause repeated statistics .
adopt @SentinelResource The annotation makes the hotspot parameter current limiting effective .

System rules

The system protection rule is to control the inlet flow at the application level , From the whole of a single machine Load、RT、 entrance QPS And thread number four dimensions to monitor application data , Let the system run at the maximum throughput and ensure the overall stability of the system .
System protection rules apply the whole dimension , Not the resource dimension , And only effective for inlet flow . Inlet flow is the flow into the application (EntryType.IN), such as Web Service or Dubbo The request received by the server , All belong to the inlet flow .
System rules support the following threshold types :
- Load( Only on Linux/Unix-like The machine works ): When the system load1 Threshold exceeded , And the system will trigger system protection when the current number of concurrent threads exceeds the system capacity . The system capacity is determined by the maxQps * minRt calculated . The setting reference value is generally CPU cores * 2.5.
- CPU usage(1.5.0+ edition ): When the system CPU When the utilization rate exceeds the threshold, system protection will be triggered ( Value range 0.0-1.0).
- RT: When the average flow of all inlets on a single machine RT When the threshold value is reached, system protection is triggered , In milliseconds .
- Number of threads : When the number of concurrent threads of all the entrances on a single machine reaches the threshold, system protection will be triggered .
entrance QPS: When all the inlet flow on a single machine QPS When the threshold value is reached, system protection is triggered .
Authorization rules
The black and white list is based on the source of the resource request (origin) Restrict the passage of resources , If the whitelist is configured, it can only be passed if the request source is in the whitelist ; If the blacklist is configured, the request source will not pass when it is in the blacklist , The rest of the requests go through .
Caller information through ContextUtil.enter(resourceName, origin) Methods origin Parameters of the incoming .
Black and white list rules (AuthorityRule) It's simple , There are mainly the following configuration items :
- resource: Resource name , That is, the object of the current limiting rule
- limitApp: The corresponding blacklist / White list , Different origin use , Separate , Such as appA,appB
- strategy: Limit mode ,AUTHORITY_WHITE For whitelist mode ,AUTHORITY_BLACK For blacklist mode , Default to white list mode .

origin The introduction of , By rewriting API Interface rewriting origin How to get , Both request parameters and request headers are allowed .
Related codes :
Implementation class
import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
import javax.servlet.http.HttpServletRequest;
/** * @author issavior */
public class MyRequestOriginParser implements RequestOriginParser {
@Override
public String parseOrigin(HttpServletRequest httpServletRequest) {
// The request header key, according to key Values obtained value value , this value Values are assigned origin, Complete flow control rule verification
return httpServletRequest.getParameter("service-name");
}
}
Configuration class
import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.Filter;
/** * @author issavior */
@Configuration
public class SentinelConfig {
@Bean
public FilterRegistrationBean<Filter> webCallbackFilter() {
FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();
bean.setFilter(new CommonFilter());
bean.addUrlPatterns("/*");
bean.addInitParameter(CommonFilter.WEB_CONTEXT_UNIFY, "false");
bean.setName("sentinelFilter");
bean.setOrder(1);
WebCallbackManager.setRequestOriginParser(new MyRequestOriginParser());
return bean;
}
}
Finally, every time you send a request , Take the corresponding... On the request parameter or request header key And the corresponding value That's all right. ~
边栏推荐
- [weekly replay] the 81st biweekly match of leetcode
- awk 简明教程
- [a complete human-computer interface program framework]
- CMOS level circuit analysis
- 赛迪顾问发布《“十四五” 关键应用领域之数据库市场研究报告》(附下载)
- 实现WordPress上传图片自动重命名的方法
- AGCO AI frontier promotion (6.27)
- 【mysql进阶】MTS主从同步原理及实操指南(七)
- Can flush open an account for stock trading? Is it safe?
- Why must Oracle cloud customers self test after the release of Oracle cloud quarterly update?
猜你喜欢

EventLoop learning

How to set postman to Chinese? (Chinese)

Learning records of numpy Library

External memory

After 2 years of outsourcing, I finally landed! Record my ByteDance 3 rounds of interviews, hope to help you!

Openhgnn releases version 0.3

基于 Nebula Graph 构建百亿关系知识图谱实践

High efficiency exponentiation

Implementing springboard agent through SSH port forwarding configuration

AGCO AI frontier promotion (6.27)
随机推荐
一次性彻底解决 Web 工程中文乱码问题
[business security-04] universal user name and universal password experiment
请求一下子太多了,数据库危
ensp云朵配置
Step by step expansion of variable parameters in class templates
Bidding announcement: Oracle all-in-one machine software and hardware maintenance project of Shanghai R & D Public Service Platform Management Center
[WUSTCTF2020]girlfriend
AcWing 第57 场周赛
A method to realize automatic renaming of pictures uploaded by WordPress
enable_if
MySQL locking mechanism and four isolation levels
jvm 性能调优、监控工具 -- jps、jstack、jmap、jhat、jstat、hprof
【微服务|Sentinel】热点规则|授权规则|集群流控|机器列表
【问题解决】Tensorflow中run究竟运行了哪些节点?
【mysql进阶】MTS主从同步原理及实操指南(七)
AGCO AI frontier promotion (6.27)
Axi bus
快速搭建一个自己的访问国外网站,搭建ss并开启bbr快速上网
[weekly replay] the 81st biweekly match of leetcode
Quick news: Huawei launched the Hongmeng developer competition; Tencent conference released the "Wanshi Ruyi" plan