类 FlowSlot
- 所有已实现的接口:
ProcessorSlot<DefaultNode>
Combined the runtime statistics collected from the previous slots (NodeSelectorSlot, ClusterNodeBuilderSlot, and StatisticSlot), FlowSlot will use pre-set rules to decide whether the incoming requests should be blocked.
SphU.entry(resourceName) will throw FlowException if any rule is
triggered. Users can customize their own logic by catching FlowException.
One resource can have multiple flow rules. FlowSlot traverses these rules until one of them is triggered or all rules have been traversed.
Each FlowRule is mainly composed of these factors: grade, strategy, path. We
can combine these factors to achieve different effects.
The grade is defined by the grade field in FlowRule. Here, 0 for thread
isolation and 1 for request count shaping (QPS). Both thread count and request
count are collected in real runtime, and we can view these statistics by
following command:
curl http://localhost:8719/tree idx id thread pass blocked success total aRt 1m-pass 1m-block 1m-all exception 2 abc647 0 460 46 46 1 27 630 276 897 0
threadfor the count of threads that is currently processing the resourcepassfor the count of incoming request within one secondblockedfor the count of requests blocked within one secondsuccessfor the count of the requests successfully handled by Sentinel within one secondRTfor the average response time of the requests within a secondtotalfor the sum of incoming requests and blocked requests within one second1m-passis for the count of incoming requests within one minute1m-blockis for the count of a request blocked within one minute1m-allis the total of incoming and blocked requests within one minuteexceptionis for the count of business (customized) exceptions in one second
Traffic Shaping
When QPS exceeds the threshold, Sentinel will take actions to control the incoming request,
and is configured by controlBehavior field in flow rules.
- Immediately reject (
RuleConstant.CONTROL_BEHAVIOR_DEFAULT) - Warmup (
RuleConstant.CONTROL_BEHAVIOR_WARM_UP) - Uniform Rate Limiting (
RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER)
This is the default behavior. The exceeded request is rejected immediately and the FlowException is thrown
If the load of system has been low for a while, and a large amount of
requests comes, the system might not be able to handle all these requests at
once. However if we steady increase the incoming request, the system can warm
up and finally be able to handle all the requests.
This warmup period can be configured by setting the field warmUpPeriodSec in flow rules.
This strategy strictly controls the interval between requests. In other words, it allows requests to pass at a stable, uniform rate.
This strategy is an implement of leaky bucket. It is used to handle the request at a stable rate and is often used in burst traffic (e.g. message handling). When a large number of requests beyond the system’s capacity arrive at the same time, the system using this strategy will handle requests and its fixed rate until all the requests have been processed or time out.
- 作者:
- jialiang.linjl, Eric Zhao
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidentry(Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count, boolean prioritized, Object... args) Entrance of this slot.voidexit(Context context, ResourceWrapper resourceWrapper, int count, Object... args) Exit of this slot.从类继承的方法 com.alibaba.csp.sentinel.slotchain.AbstractLinkedProcessorSlot
fireEntry, fireExit, getNext, setNext
-
构造器详细资料
-
FlowSlot
public FlowSlot()
-
-
方法详细资料
-
entry
public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count, boolean prioritized, Object... args) throws Throwable 从接口复制的说明:ProcessorSlotEntrance of this slot. -
exit
从接口复制的说明:ProcessorSlotExit of this slot.- 参数:
context- currentContextresourceWrapper- current resourcecount- tokens neededargs- parameters of the original call
-