public class StatisticNode extends Object implements Node
The statistic node keep three kinds of real-time statistics metrics:
rollingCounterInSecond)rollingCounterInMinute)
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
| Constructor and Description |
|---|
StatisticNode() |
| Modifier and Type | Method and Description |
|---|---|
void |
addOccupiedPass(int acquireCount)
Add occupied pass request, which represents pass requests that borrow the latter windows' token.
|
void |
addPassRequest(int count)
Add pass count.
|
void |
addRtAndSuccess(long rt,
int successCount)
Add rt and success count.
|
void |
addWaitingRequest(long futureTime,
int acquireCount)
Add request that occupied.
|
double |
avgRt()
Get average rt per second.
|
double |
blockQps()
Get block request per second.
|
long |
blockRequest()
Get blocked request count per minute (totalBlockRequest).
|
int |
curThreadNum()
Get current active thread count.
|
void |
debug()
For debug;
|
void |
decreaseThreadNum()
Decrease current thread count.
|
double |
exceptionQps()
Get exception count per second.
|
void |
increaseBlockQps(int count)
Increase the block count.
|
void |
increaseExceptionQps(int count)
Add the biz exception count.
|
void |
increaseThreadNum()
Increase current thread count.
|
double |
maxSuccessQps()
Get estimated max success QPS till now.
|
Map<Long,MetricNode> |
metrics()
Fetch all valid metric nodes of resources.
|
double |
minRt()
Get minimal response time.
|
double |
occupiedPassQps()
Get current occupied pass QPS.
|
double |
passQps()
Get pass request per second.
|
double |
previousBlockQps()
Get last second block QPS.
|
double |
previousPassQps()
Last window QPS.
|
List<MetricNode> |
rawMetricsInMin(Predicate<Long> timePredicate)
Fetch all raw metric items that satisfies the time predicate.
|
void |
reset()
Reset the internal counter.
|
double |
successQps()
Get
Entry.exit() request per second. |
long |
totalException()
Get exception count per minute.
|
long |
totalPass()
Get pass count per minute.
|
double |
totalQps()
Get
Node.passQps() + Node.blockQps() request per second. |
long |
totalRequest()
Get incoming request per minute (
pass + block). |
long |
totalSuccess()
Get
Entry.exit() count per minute. |
long |
tryOccupyNext(long currentTime,
int acquireCount,
double threshold)
Try to occupy latter time windows' tokens.
|
long |
waiting()
Get current waiting amount.
|
public Map<Long,MetricNode> metrics()
Nodepublic List<MetricNode> rawMetricsInMin(Predicate<Long> timePredicate)
NoderawMetricsInMin in interface NodetimePredicate - time predicatepublic void reset()
NodeIntervalProperty.INTERVAL or
SampleCountProperty.SAMPLE_COUNT is changed.public long totalRequest()
Nodepass + block).totalRequest in interface Nodepublic long blockRequest()
NodeblockRequest in interface Nodepublic double blockQps()
Nodepublic double previousBlockQps()
NodepreviousBlockQps in interface Nodepublic double previousPassQps()
NodepreviousPassQps in interface Nodepublic double totalQps()
NodeNode.passQps() + Node.blockQps() request per second.public long totalSuccess()
NodeEntry.exit() count per minute.totalSuccess in interface Nodepublic double exceptionQps()
NodeexceptionQps in interface Nodepublic long totalException()
NodetotalException in interface Nodepublic double passQps()
Nodepublic long totalPass()
Nodepublic double successQps()
NodeEntry.exit() request per second.successQps in interface Nodepublic double maxSuccessQps()
NodemaxSuccessQps in interface Nodepublic double occupiedPassQps()
OccupySupportoccupiedPassQps in interface OccupySupportpublic double avgRt()
Nodepublic double minRt()
Nodepublic int curThreadNum()
NodecurThreadNum in interface Nodepublic void addPassRequest(int count)
NodeaddPassRequest in interface Nodecount - count to add passpublic void addRtAndSuccess(long rt,
int successCount)
NodeaddRtAndSuccess in interface Nodert - response timesuccessCount - success count to addpublic void increaseBlockQps(int count)
NodeincreaseBlockQps in interface Nodecount - count to addpublic void increaseExceptionQps(int count)
NodeincreaseExceptionQps in interface Nodecount - count to addpublic void increaseThreadNum()
NodeincreaseThreadNum in interface Nodepublic void decreaseThreadNum()
NodedecreaseThreadNum in interface Nodepublic void debug()
DebugSupportdebug in interface DebugSupportpublic long tryOccupyNext(long currentTime,
int acquireCount,
double threshold)
OccupySupportoccupyTimeout in OccupyTimeoutProperty will 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 occupyTimeout in OccupyTimeoutProperty.
tryOccupyNext in interface OccupySupportcurrentTime - current time millis.acquireCount - tokens count to acquire.threshold - qps threshold.occupyTimeout in OccupyTimeoutProperty means
occupy fail, in this case, the request should be rejected immediately.public long waiting()
OccupySupportwaiting in interface OccupySupportpublic void addWaitingRequest(long futureTime,
int acquireCount)
OccupySupportaddWaitingRequest in interface OccupySupportfutureTime - future timestamp that the acquireCount should be added on.acquireCount - tokens count.public void addOccupiedPass(int acquireCount)
OccupySupportaddOccupiedPass in interface OccupySupportacquireCount - tokens count.Copyright © 2021 Alibaba Group. All rights reserved.