当前位置:网站首页>[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. ~
边栏推荐
- 图书管理系统
- 请求一下子太多了,数据库危
- JVM parameter setting and analysis
- How to use 200 lines of code to implement Scala's Object Converter
- 实现WordPress上传图片自动重命名的方法
- CMOS level circuit analysis
- 【mysql进阶】MTS主从同步原理及实操指南(七)
- Daily 3 questions (1): find the nearest point with the same X or Y coordinate
- CCID Consulting released the database Market Research Report on key application fields during the "14th five year plan" (attached with download)
- 外部存储器
猜你喜欢

深入理解位运算

赛迪顾问发布《“十四五” 关键应用领域之数据库市场研究报告》(附下载)

【微服务|Sentinel】热点规则|授权规则|集群流控|机器列表

【业务安全03】密码找回业务安全以及接口参数账号修改实例(基于metinfov4.0平台)

AcWing 第57 场周赛

Pytorch learning 3 (test training model)

Cesium realizes satellite orbit detour

Deep understanding of bit operations

【PHP代码注入】PHP语言常见可注入函数以及PHP代码注入漏洞的利用实例

IJCAI 2022 | greatly improve the effect of zero sample learning method with one line of code. Nanjing Institute of Technology & Oxford proposed the plug and play classifier module
随机推荐
Using FRP tool to realize intranet penetration
每日3题(1):找到最近的有相同 X 或 Y 坐标的点
Quickly set up a website to visit foreign countries, set up SS and start BBR to quickly surf the Internet
Prometheus 2.26.0 new features
awk 简明教程
Infiltration learning diary day20
机械硬盘和ssd固态硬盘的原理对比分析
现在开户有优惠吗?网上开户是否安全么?
Naacl 2022 | TAMT: search the transportable Bert subnet through downstream task independent mask training
剑指 Offer II 039. 直方图最大矩形面积 单调栈
命令行编辑器 sed 基础用法总结
ENSP cloud configuration
scrapy
事务的四大特性
[problem solving] which nodes are run in tensorflow?
Shell 简明教程
线程同步之信号量
High efficiency exponentiation
CCID Consulting released the database Market Research Report on key application fields during the "14th five year plan" (attached with download)
【业务安全03】密码找回业务安全以及接口参数账号修改实例(基于metinfov4.0平台)