Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Source Code Analysis of slot implementation in Sentinel

Shulou Source: shulou.com Published: 2022-06-02 02:03:13 09月17日 Update

Today, I will talk to you about the source code analysis of slot implementation in Sentinel. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

In the CtSph.entryWithPriority method, an instance of ProcessorSlotChain is assigned to each resource. By default, the corresponding slot chain is created through the DefaultSlotChainBuilder class. The construction process is as follows:

Public ProcessorSlotChain build () {ProcessorSlotChain chain = new DefaultProcessorSlotChain (); chain.addLast (new NodeSelectorSlot ()); chain.addLast (new ClusterBuilderSlot ()); chain.addLast (new LogSlot ()); chain.addLast (new StatisticSlot ()); chain.addLast (new SystemSlot ()); chain.addLast (new AuthoritySlot ()); chain.addLast (new FlowSlot ()); chain.addLast (new DegradeSlot ()); return chain;}

It contains 8 slot by default, as follows.

NodeSelectorSlot

Create different DefaultNode for different context of the same resource and store them in a slot-level map to store statistical data.

ClusterBuilderSlot

Maintain a separate ClusterNode instance for the same resource to hold statistics. At the same time, according to the different origin, create the corresponding StatisticNode.

StatisticSlot

The counter of default & cluster & statistic node is added to the entry/exit method to realize data statistics.

SystemSlot

Achieve global (java process level) flow control through the SystemRuleManager.checkSystem method, including: total number of qps; threads; total average response time; system average load (obtained through OperatingSystemMXBean); CPU utilization (obtained through OperatingSystemMXBean).

AuthoritySlot

Manage all AuthorityRule through AuthorityRuleManager, and implement blacklist and whitelist detection on resource-origin granularity.

FlowSlow

The core logic of flow control implementation relies on FlowRuleManager to manage all FlowRule collections and test whether rule is effective on the resource dimension. FlowRule inspection is divided into local check and cluster check, which relies on centralized services to manage resources to access token.

In local check mode, it is mainly divided into two steps: selecting the correct counting node (origin/cluster/default node); TrafficShapingController determines whether to release the current call by counting node statistics.

DegradeSlot

The DegradeRuleManager.checkDegrade method detects whether the DegradeRule is valid on the resource dimension. Currently, there are three downgrade strategies: average response time, anomaly rate, and number of exceptions.

After reading the above, do you have any further understanding of the source code analysis of the slot implementation in Sentinel? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Data method resource statistics difference content statistics management source code analysis instance time level dimension node detection two utilization global at the same time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Tech Info Linux vpn Redmi