当前位置:网站首页>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
边栏推荐
- VIM编辑器常用指令
- 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
- Visual Studio 2017 无法打开包括文件: “QOpenGLFunctions_3_3_Core”: No such file or directory
- 数据中台咋就从“小甜甜”变成了“牛夫人”?
- Solution to webkitformboundaryk in post request
- Cloud, IPv6 and all-optical network
- Analysis of IM instant messaging development technology on modern web
- Solve the problem of repairing Visual Basic exceptions with excel/wps plug-in of choice financial terminal
- 数字垃圾是什么?跟随世界第一位AI艺术家,探索元碳艺术
- 【深度学习编译】算子编译 IR 转换
猜你喜欢

Online sql to CSV tool

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

Solving plane stress problem with MATLAB

【Games101】Transformation

Live broadcast configuration of crmeb knowledge payment system program configuration (method 2)

How to view the size of all files in a folder?

Is the numpy index the same as the image index?

Wechat applet - requestsubscribemessage:fail can only be invoked by user tap gesture

xshell中怎么切换到root用户

CSV文件格式——方便好用个头最小的数据传递方式
随机推荐
R language linear regression model fitting diagnosis outliers analysis of domestic gas consumption and calorie examples with self-test questions
阅读,是最廉价的高贵
Some thoughts on life
[concurrent programming] if you use channel to solve concurrency problems?
Kwai reached out to the "supply side" to find the "source" of live broadcast e-commerce?
Antd - tree structure: default deployment node attribute failure - Basic promotion
A Si's mood swings
Good test / development programmers vs. average programmers
传统微服务框架如何无缝过渡到服务网格 ASM
测试用例设计方法之等价类划分方法
If the amount exceeds 6 digits after the decimal point, only 6 digits will be reserved, and if it is less than 6 digits, it will remain the same - Basic accumulation
Clean, talk, bring children, and get rid of the label of "artificial mental retardation" for the sweeper
What is digital garbage? Follow the world's first AI artist to explore meta carbon Art
[proteus simulation] 8-bit port detection 8 independent keys
[three.js] Web3D first experience
【three.js】WEB3D初次体验
存储引擎分析
【Proteus仿真】8比特端口檢測8獨立按鍵
英伟达Jetson Nano的初步了解
Stimulsoft Reports报告工具,Stimulsoft创建和构建报告