Sentinel Console page
Sentinel core architecture diagram
The top part is doing statistics and the bottom part is using statistics to do validation of rules and the whole process is a chain Sentinel and the core skeleton is ProcessorSlotChain and it links the different slots together sequentially (chain of responsibility mode) To combine unavailable functions (such as traffic limiting, degradation, and system protection), the system creates a SlotChain for each resourceCopy the code
SPI (Service Processing Interface) mechanism
The order of execution of slots in the Sentinel Slot chain is fixed but not absolutely immutable. Sentinel extends ProcessorSlot as an SPI interface, enabling SlotChain to be extended. Users can customize slots and arrange the order between slotsCopy the code
Custom slots can be inserted anywhere in the chainCopy the code
NodeSelectorSlot
Collect the paths of resources, and store the call paths of these resources in a tree structure, which is used to limit traffic degradation according to the call pathsCopy the code
ClusterBuilderSlot
Statistics resource information and caller information such as RT, QPS, Thread Count, Block Count, Exception Count of the resource are used for multi-dimensional traffic limiting and are degraded based on ClusterNode constructionCopy the code
StatisticSlot
The sliding time window algorithm used at the bottom layer to record and collect statistics of runtime indicator monitoring information of different dimensionsCopy the code
ParamFlowSlot
Corresponding to "Hot spot flow control"Copy the code
FlowSlot
"Flow control Rule" controls traffic according to preset traffic limiting rules and slot statisticsCopy the code
AuthoritySlot
Make blacklist and whitelist control based on configured blacklist and whitelist and call source information corresponding to "Authorization Rule"Copy the code
DegradeSlot
Fuse downgrades using statistics and preset rules corresponding to "fuse rules."Copy the code
SystemSlot
Corresponding "system rules" control the total incoming traffic by system states such as LOADCopy the code
Next, analyze the architecture diagram
Call tree
Call tree Root node created by NodeSelectorSlot: an application belongs to a Root nodeCopy the code
Every request from the same application is going to go through SlotChain and see if there's a Root node when the first request comes in and if there's no Root node it's going to be created and then it's not going to be createdCopy the code
View the relationship between ClusterNode, DefaultNode, EntranceNode, Node, and StatisticNode
EntranceNode, DefaultNode, and ClusterNode are all inherited StatisticNodes. Statisticnodes are all used for statistics. To understand the differences between these nodes, take a look at ContextCopy the code
Context
Context is the Context in which operations are performed on the resource. Each operation must belong to a Context. If no Context is specified in the code, a default Context whose name is sentinel_default_context is created A Context lifecycle can contain multiple resource operations. When the last resource in the Context lifecycle is cleaned up by exit(), it means that the lifetime of the Context is overCopy the code
A Context lifecycle can contain multiple resource operations
This is the operation that contains two resources in one contextCopy the code
An application contains two contexts each containing access to two resources and the overlapped resources accessed by both contexts are resource2 accessedCopy the code
It's time for the code to explain the call tree in the schema diagram
- Node
Used to complete data statisticsCopy the code
- StatisticNode
Statistics Node, is the implementation class of the Node interface, used to complete data statisticsCopy the code
- EntranceNode
Entry node: A Context Context has an entry node that counts the total traffic of the current ContextCopy the code
- DefaultNode
The default node is used to count the traffic of a resource in the current ContextCopy the code
- ClusterNode
The cluster node is used to count the total traffic of a resource in all contexts. DefaultNode2 in the two contexts above is aggregated by ClusterNode2, which is created by the ClusterBuilderSlot processor slotCopy the code