当前位置:网站首页>Sentinel source code analysis Chapter 9 - core process - lookprocesschain finding resource processing chain
Sentinel source code analysis Chapter 9 - core process - lookprocesschain finding resource processing chain
2022-06-30 01:11:00 【Age man】
List of articles
Source code analysis one lookProcessChain
- adopt chainMap obtain resource Corresponding chain
- Return directly if it exists
- SLOT_CHAIN Examples exceed 6000 Then return to null, No processing
- adopt SlotChainProvider structure chain
- Join in chainMap
ProcessorSlot<Object> lookProcessChain(ResourceWrapper resourceWrapper) {
chainMap cache resourceWrapper Corresponding Slot
ProcessorSlotChain chain = chainMap.get(resourceWrapper);
if (chain == null) {
synchronized (LOCK) {
chain = chainMap.get(resourceWrapper);
if (chain == null) {
If the number of resources is too large, it directly returns null No current limiting treatment
if (chainMap.size() >= Constants.MAX_SLOT_CHAIN_SIZE) {
return null;
}
Create a new ProcessorSlotChain
chain = SlotChainProvider.newSlotChain();
Build new resource and processor chain pools
Map<ResourceWrapper, ProcessorSlotChain> newMap = new HashMap<ResourceWrapper, ProcessorSlotChain>(
chainMap.size() + 1);
newMap.putAll(chainMap);
newMap.put(resourceWrapper, chain);
chainMap = newMap;
}
}
}
return chain;
}
Source code analysis one SlotChainProvider structure slotChain
- adopt spi Get the builder DefaultSlotChainBuilder
public final class SlotChainProvider {
private static volatile SlotChainBuilder slotChainBuilder = null;
public static ProcessorSlotChain newSlotChain() {
step-1: slotChain When the builder exists, he builds
if (slotChainBuilder != null) {
return slotChainBuilder.build();
}
step-2: spi==spi And the default is :DefaultSlotChainBuilder
slotChainBuilder = SpiLoader.loadFirstInstanceOrDefault(SlotChainBuilder.class, DefaultSlotChainBuilder.class);
step-3: The default policy
if (slotChainBuilder == null) {
slotChainBuilder = new DefaultSlotChainBuilder();
}
return slotChainBuilder.build();
}
}
Source code analysis one slotChainBuilder.build
- adopt spi load slotchain
public class DefaultSlotChainBuilder implements SlotChainBuilder {
@Override
public ProcessorSlotChain build() {
ProcessorSlotChain chain = new DefaultProcessorSlotChain();
// Note: the instances of ProcessorSlot should be different, since they are not stateless.
List<ProcessorSlot> sortedSlotList = SpiLoader.loadPrototypeInstanceListSorted(ProcessorSlot.class);
/** * * One way linked list * first end * DefaultProcessorSlotChain --> --> spi * spi result : * structure node Trees * com.alibaba.csp.sentinel.slots.nodeselector.NodeSelectorSlot * structure clusterNode * com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot * journal * com.alibaba.csp.sentinel.slots.logger.LogSlot * Statistics * com.alibaba.csp.sentinel.slots.statistic.StatisticSlot * to grant authorization White list The blacklist * com.alibaba.csp.sentinel.slots.block.authority.AuthoritySlot * System * com.alibaba.csp.sentinel.slots.system.SystemSlot * Current limiting * com.alibaba.csp.sentinel.slots.block.flow.FlowSlot * Downgrade * com.alibaba.csp.sentinel.slots.block.degrade.DegradeSlot */
for (ProcessorSlot slot : sortedSlotList) {
if (!(slot instanceof AbstractLinkedProcessorSlot)) {
RecordLog.warn("The ProcessorSlot(" + slot.getClass().getCanonicalName() + ") is not an instance of AbstractLinkedProcessorSlot, can't be added into ProcessorSlotChain");
continue;
}
chain.addLast((AbstractLinkedProcessorSlot<?>) slot);
}
return chain;
}
}
summary
- lookProcessChain adopt spi complete Slot Chain loading of
- slot The chain is responsible for the core work of current limiting
- slot An instance of each resource in the chain
- slot The number of chains cannot exceed 6000
边栏推荐
- Stimulsoft Reports报告工具,Stimulsoft创建和构建报告
- I learned database at station B (V): DQL exercise
- 【Proteus仿真】8比特端口檢測8獨立按鍵
- Outsourcing for 3 years is a waste
- 清洁、对话、带娃,扫地机摆脱“人工智障”标签
- Cloud, IPv6 and all-optical network
- Seata 与三大平台携手编程之夏,百万奖金等你来拿
- 【Games101】Transformation
- A Si's mood swings
- How did the data center change from "Britney Spears" to "Mrs. bull"?
猜你喜欢

R language linear regression model fitting diagnosis outliers analysis of domestic gas consumption and calorie examples with self-test questions

In 2022, the latest and most detailed idea associated database method and visual operation of database in idea (including graphic process)

MySQL installation steps (detailed)

2022 6 月25 日交易总结

英伟达Jetson Nano的初步了解

外包干了三年,废的一踏糊涂...

xshell中怎么切换到root用户

Seata et les trois plateformes travaillent main dans la main pour programmer Summer, un million de bonus vous attend

Nested call and chained access of functions in handwritten C language

作文总写不好怎么办?猿辅导:家长要注意这几点
随机推荐
Arlo felt lost
【深度学习编译】算子编译 IR 转换
Analysis of natural frequency and buckling load of cylinder by finite element method
How did the data center change from "Britney Spears" to "Mrs. bull"?
Command line Basics
数据中台咋就从“小甜甜”变成了“牛夫人”?
Too voluminous ~ eight part essay, the strongest king of interview!
R语言线性回归模型拟合诊断异常值分析家庭燃气消耗量和卡路里实例带自测题
C language final without failing (Part 1)
存储引擎分析
MySQL installation steps (detailed)
2022-06-29: x = {a, B, C, D}, y = {e, F, G, H}, the length of the two small arrays X and Y is 4. If yes: a + e = B + F = C + G = D + H
Cloud, IPv6 and all-optical network
清洁、对话、带娃,扫地机摆脱“人工智障”标签
C language selection, loop overview
2020-12-03
如何拒绝期末复习无用功?猿辅导:找准适合自己的复习方法很重要
Quick Pow: 如何快速求幂
Visual Studio 2017 无法打开包括文件: “QOpenGLFunctions_3_3_Core”: No such file or directory
Unity编辑器随机生成物体,更换场景之后物体丢失问题解决