Sentinel源码阅读:实时数据采集

Sentinel实时数据采集

要实现限流需要进行数据采集,这一篇文章将重点解析数据采集的实现原理。

0

由上图可知,Sentinel中负责数据采集StatisticSlot是在责任链靠前的位置,StatisticSlot组件负责收集调用信息为后面的Slot进行相应的限流、熔断提供支撑,可以说StatisticSlot是Sentinel中核心之一。

StatisticSlot类的注释,当进入这个Slot时我们需要分别计算以下各项:

    • 资源ID的集群节点的总统计信息
    • 来自不同调用者/来源的群集节点的统计信息
    • 特定上下文中特定资源名称的统计信息
    • 统计所有入口的总和

1. StatisticSlot源码分析

1.1 StatisticSlot entry 详解

@Override
public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count,
                  boolean prioritized, Object... args) throws Throwable {
    try {
        // Do some checking.
        fireEntry(context, resourceWrapper, node, count, prioritized, args);//@1

        // Request passed, add thread count and pass count.
        node.increaseThreadNum();//@2
        node.addPassRequest(count);

        if (context.getCurEntry().getOriginNode() != null) {//@3
            // Add count for origin node.
            context.getCurEntry().getOriginNode().increaseThreadNum();
            context.getCurEntry().getOriginNode().addPassRequest(count);
        }

        if (resourceWrapper.getEntryType() == EntryType.IN) {//@4
            // Add count for global inbound entry node for global statistics.
            Constants.ENTRY_NODE.increaseThreadNum();
            Constants.ENTRY_NODE.addPassRequest(count);
        }

        // Handle pass event with registered entry callback handlers.
        for (ProcessorSlotEntryCallback<DefaultNode> handler : StatisticSlotCallbackRegistry.getEntryCallbacks()) { //@5
            handler.onPass(context, resourceWrapper, node, count, args);
        }
    } catch (PriorityWaitException ex) {//@6
        node.increaseThreadNum();
        if (context.getCurEntry().getOriginNode() != null) {
            // Add count for origin node.
            context.getCurEntry().getOriginNode().increaseThreadNum();
        }

        if (resourceWrapper.getEntryType() == EntryType.IN) {
            // Add count for global inbound entry node for glob
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值