当前位置:网站首页>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
边栏推荐
- How to unify the use of package manager in a project?
- Programmers with a monthly salary of less than 30K must recite the interview stereotype. I will eat it first!
- Developers, why does the maturity of container technology herald the arrival of cloud native era?
- Understand the module function of MES management system
- Outsourcing for 3 years is a waste
- shell 规范日期格式
- Video to image -cv2 Videocapture() usage
- 81. search rotation sort array II
- [proteus simulation] 8-bit port detection 8 independent keys
- [mrctf2020]ezpop-1 | PHP serialization
猜你喜欢
如何查看一个文件夹下所有文件的大小?
MySQL installation steps (detailed)
latex如何输入一个矩阵
[concurrent programming] if you use channel to solve concurrency problems?
Sfdp 超级表单开发平台 V6.0.4 正式发布
STC89C52 single chip microcomputer simple calculator design and code demonstration
I learned database at station B (V): DQL exercise
数字垃圾是什么?跟随世界第一位AI艺术家,探索元碳艺术
Practical application of information security
Online text digit recognition list summation tool
随机推荐
2022 6 月25 日交易总结
MES管理系统功能模块之质量管理
c语言期末不挂科(上)
如何在IDEA中自定義模板、快速生成完整的代碼?
VIM编辑器常用指令
Birds in the corn field
Simple pages
Time does not spare
浅析现代Web端im即时通讯开发技术
Quality management of functional modules of MES management system
How to customize templates and quickly generate complete code in idea?
Online sql to CSV tool
Mechanical --nx2007 (UG) -- gap analysis (interference inspection)
Resizekit2.net size and resolution independent
latex如何输入一个矩阵
2020-12-03
Seata 与三大平台携手编程之夏,百万奖金等你来拿
英伟达Jetson Nano的初步了解
Solution to webkitformboundaryk in post request
Text classification using huggingface