类 StatisticNode
- 所有已实现的接口:
Node,OccupySupport,DebugSupport
- 直接已知子类:
ClusterNode,DefaultNode
The statistic node keep three kinds of real-time statistics metrics:
- metrics in second level (
rollingCounterInSecond) - metrics in minute level (
rollingCounterInMinute) - thread count
Sentinel use sliding window to record and count the resource statistics in real-time.
The sliding window infrastructure behind the ArrayMetric is LeapArray.
case 1: When the first request comes in, Sentinel will create a new window bucket of a specified time-span to store running statics, such as total response time(rt), incoming request(QPS), block request(bq), etc. And the time-span is defined by sample count.
0 100ms
+-------+--→ Sliding Windows
^
|
request
Sentinel use the statics of the valid buckets to decide whether this request can be passed. For example, if a rule defines that only 100 requests can be passed, it will sum all qps in valid buckets, and compare it to the threshold defined in rule.
case 2: continuous requests
0 100ms 200ms 300ms
+-------+-------+-------+-----→ Sliding Windows
^
|
request
case 3: requests keeps coming, and previous buckets become invalid
0 100ms 200ms 800ms 900ms 1000ms 1300ms
+-------+-------+ ...... +-------+-------+ ...... +-------+-----→ Sliding Windows
^
|
request
The sliding window should become:
300ms 800ms 900ms 1000ms 1300ms
+ ...... +-------+ ...... +-------+-----→ Sliding Windows
^
|
request
- 作者:
- qinan.qn, jialiang.linjl
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidaddOccupiedPass(int acquireCount) Add occupied pass request, which represents pass requests that borrow the latter windows' token.voidaddPassRequest(int count) Add pass count.voidaddRtAndSuccess(long rt, int successCount) Add rt and success count.voidaddWaitingRequest(long futureTime, int acquireCount) Add request that occupied.doubleavgRt()Get average rt per second.doubleblockQps()Get block request per second.longGet blocked request count per minute (totalBlockRequest).intGet current active thread count.voiddebug()For debug;voidDecrease current thread count.doubleGet exception count per second.voidincreaseBlockQps(int count) Increase the block count.voidincreaseExceptionQps(int count) Add the biz exception count.voidIncrease current thread count.doubleGet estimated max success QPS till now.metrics()Fetch all valid metric nodes of resources.doubleminRt()Get minimal response time.doubleGet current occupied pass QPS.doublepassQps()Get pass request per second.doubleGet last second block QPS.doubleLast window QPS.rawMetricsInMin(Predicate<Long> timePredicate) Fetch all raw metric items that satisfies the time predicate.voidreset()Reset the internal counter.doubleGetEntry.exit()request per second.longGet exception count per minute.longGet pass count per minute.doubletotalQps()GetNode.passQps()+Node.blockQps()request per second.longGet incoming request per minute (pass + block).longGetEntry.exit()count per minute.longtryOccupyNext(long currentTime, int acquireCount, double threshold) Try to occupy latter time windows' tokens.longwaiting()Get current waiting amount.
-
构造器详细资料
-
StatisticNode
public StatisticNode()
-
-
方法详细资料
-
metrics
从接口复制的说明:NodeFetch all valid metric nodes of resources. -
rawMetricsInMin
从接口复制的说明:NodeFetch all raw metric items that satisfies the time predicate.- 指定者:
rawMetricsInMin在接口中Node- 参数:
timePredicate- time predicate- 返回:
- raw metric items that satisfies the time predicate
-
reset
public void reset()从接口复制的说明:NodeReset the internal counter. Reset is needed whenIntervalProperty.INTERVALorSampleCountProperty.SAMPLE_COUNTis changed. -
totalRequest
public long totalRequest()从接口复制的说明:NodeGet incoming request per minute (pass + block).- 指定者:
totalRequest在接口中Node- 返回:
- total request count per minute
-
blockRequest
public long blockRequest()从接口复制的说明:NodeGet blocked request count per minute (totalBlockRequest).- 指定者:
blockRequest在接口中Node- 返回:
- total blocked request count per minute
-
blockQps
public double blockQps()从接口复制的说明:NodeGet block request per second. -
previousBlockQps
public double previousBlockQps()从接口复制的说明:NodeGet last second block QPS.- 指定者:
previousBlockQps在接口中Node
-
previousPassQps
public double previousPassQps()从接口复制的说明:NodeLast window QPS.- 指定者:
previousPassQps在接口中Node
-
totalQps
public double totalQps()从接口复制的说明:NodeGetNode.passQps()+Node.blockQps()request per second. -
totalSuccess
public long totalSuccess()从接口复制的说明:NodeGetEntry.exit()count per minute.- 指定者:
totalSuccess在接口中Node- 返回:
- total completed request count per minute
-
exceptionQps
public double exceptionQps()从接口复制的说明:NodeGet exception count per second.- 指定者:
exceptionQps在接口中Node- 返回:
- QPS of exception occurs
-
totalException
public long totalException()从接口复制的说明:NodeGet exception count per minute.- 指定者:
totalException在接口中Node- 返回:
- total business exception count per minute
-
passQps
public double passQps()从接口复制的说明:NodeGet pass request per second. -
totalPass
public long totalPass()从接口复制的说明:NodeGet pass count per minute. -
successQps
public double successQps()从接口复制的说明:NodeGetEntry.exit()request per second.- 指定者:
successQps在接口中Node- 返回:
- QPS of completed requests
-
maxSuccessQps
public double maxSuccessQps()从接口复制的说明:NodeGet estimated max success QPS till now.- 指定者:
maxSuccessQps在接口中Node- 返回:
- max completed QPS
-
occupiedPassQps
public double occupiedPassQps()从接口复制的说明:OccupySupportGet current occupied pass QPS.- 指定者:
occupiedPassQps在接口中OccupySupport- 返回:
- current occupied pass QPS
-
avgRt
public double avgRt()从接口复制的说明:NodeGet average rt per second. -
minRt
public double minRt()从接口复制的说明:NodeGet minimal response time. -
curThreadNum
public int curThreadNum()从接口复制的说明:NodeGet current active thread count.- 指定者:
curThreadNum在接口中Node- 返回:
- current active thread count
-
addPassRequest
public void addPassRequest(int count) 从接口复制的说明:NodeAdd pass count.- 指定者:
addPassRequest在接口中Node- 参数:
count- count to add pass
-
addRtAndSuccess
public void addRtAndSuccess(long rt, int successCount) 从接口复制的说明:NodeAdd rt and success count.- 指定者:
addRtAndSuccess在接口中Node- 参数:
rt- response timesuccessCount- success count to add
-
increaseBlockQps
public void increaseBlockQps(int count) 从接口复制的说明:NodeIncrease the block count.- 指定者:
increaseBlockQps在接口中Node- 参数:
count- count to add
-
increaseExceptionQps
public void increaseExceptionQps(int count) 从接口复制的说明:NodeAdd the biz exception count.- 指定者:
increaseExceptionQps在接口中Node- 参数:
count- count to add
-
increaseThreadNum
public void increaseThreadNum()从接口复制的说明:NodeIncrease current thread count.- 指定者:
increaseThreadNum在接口中Node
-
decreaseThreadNum
public void decreaseThreadNum()从接口复制的说明:NodeDecrease current thread count.- 指定者:
decreaseThreadNum在接口中Node
-
debug
public void debug()从接口复制的说明:DebugSupportFor debug;- 指定者:
debug在接口中DebugSupport
-
tryOccupyNext
public long tryOccupyNext(long currentTime, int acquireCount, double threshold) 从接口复制的说明:OccupySupportTry to occupy latter time windows' tokens. If occupy success, a value less thanoccupyTimeoutinOccupyTimeoutPropertywill be return.Each time we occupy tokens of the future window, current thread should sleep for the corresponding time for smoothing QPS. We can't occupy tokens of the future with unlimited, the sleep time limit is
occupyTimeoutinOccupyTimeoutProperty.- 指定者:
tryOccupyNext在接口中OccupySupport- 参数:
currentTime- current time millis.acquireCount- tokens count to acquire.threshold- qps threshold.- 返回:
- time should sleep. Time >=
occupyTimeoutinOccupyTimeoutPropertymeans occupy fail, in this case, the request should be rejected immediately.
-
waiting
public long waiting()从接口复制的说明:OccupySupportGet current waiting amount. Useful for debug.- 指定者:
waiting在接口中OccupySupport- 返回:
- current waiting amount
-
addWaitingRequest
public void addWaitingRequest(long futureTime, int acquireCount) 从接口复制的说明:OccupySupportAdd request that occupied.- 指定者:
addWaitingRequest在接口中OccupySupport- 参数:
futureTime- future timestamp that the acquireCount should be added on.acquireCount- tokens count.
-
addOccupiedPass
public void addOccupiedPass(int acquireCount) 从接口复制的说明:OccupySupportAdd occupied pass request, which represents pass requests that borrow the latter windows' token.- 指定者:
addOccupiedPass在接口中OccupySupport- 参数:
acquireCount- tokens count.
-