类 StatisticNode

java.lang.Object
com.alibaba.csp.sentinel.node.StatisticNode
所有已实现的接口:
Node, OccupySupport, DebugSupport
直接已知子类:
ClusterNode, DefaultNode

public class StatisticNode extends Object implements Node

The statistic node keep three kinds of real-time statistics metrics:

  1. metrics in second level (rollingCounterInSecond)
  2. metrics in minute level (rollingCounterInMinute)
  3. 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
  • 构造器详细资料

    • StatisticNode

      public StatisticNode()
  • 方法详细资料

    • metrics

      public Map<Long,MetricNode> metrics()
      从接口复制的说明: Node
      Fetch all valid metric nodes of resources.
      指定者:
      metrics 在接口中 Node
      返回:
      valid metric nodes of resources
    • rawMetricsInMin

      public List<MetricNode> rawMetricsInMin(Predicate<Long> timePredicate)
      从接口复制的说明: Node
      Fetch 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()
      从接口复制的说明: Node
      Reset the internal counter. Reset is needed when IntervalProperty.INTERVAL or SampleCountProperty.SAMPLE_COUNT is changed.
      指定者:
      reset 在接口中 Node
    • totalRequest

      public long totalRequest()
      从接口复制的说明: Node
      Get incoming request per minute (pass + block).
      指定者:
      totalRequest 在接口中 Node
      返回:
      total request count per minute
    • blockRequest

      public long blockRequest()
      从接口复制的说明: Node
      Get blocked request count per minute (totalBlockRequest).
      指定者:
      blockRequest 在接口中 Node
      返回:
      total blocked request count per minute
    • blockQps

      public double blockQps()
      从接口复制的说明: Node
      Get block request per second.
      指定者:
      blockQps 在接口中 Node
      返回:
      QPS of blocked requests
    • previousBlockQps

      public double previousBlockQps()
      从接口复制的说明: Node
      Get last second block QPS.
      指定者:
      previousBlockQps 在接口中 Node
    • previousPassQps

      public double previousPassQps()
      从接口复制的说明: Node
      Last window QPS.
      指定者:
      previousPassQps 在接口中 Node
    • totalQps

      public double totalQps()
      从接口复制的说明: Node
      Get Node.passQps() + Node.blockQps() request per second.
      指定者:
      totalQps 在接口中 Node
      返回:
      QPS of passed and blocked requests
    • totalSuccess

      public long totalSuccess()
      从接口复制的说明: Node
      Get Entry.exit() count per minute.
      指定者:
      totalSuccess 在接口中 Node
      返回:
      total completed request count per minute
    • exceptionQps

      public double exceptionQps()
      从接口复制的说明: Node
      Get exception count per second.
      指定者:
      exceptionQps 在接口中 Node
      返回:
      QPS of exception occurs
    • totalException

      public long totalException()
      从接口复制的说明: Node
      Get exception count per minute.
      指定者:
      totalException 在接口中 Node
      返回:
      total business exception count per minute
    • passQps

      public double passQps()
      从接口复制的说明: Node
      Get pass request per second.
      指定者:
      passQps 在接口中 Node
      返回:
      QPS of passed requests
    • totalPass

      public long totalPass()
      从接口复制的说明: Node
      Get pass count per minute.
      指定者:
      totalPass 在接口中 Node
      返回:
      total passed request count per minute
    • successQps

      public double successQps()
      从接口复制的说明: Node
      Get Entry.exit() request per second.
      指定者:
      successQps 在接口中 Node
      返回:
      QPS of completed requests
    • maxSuccessQps

      public double maxSuccessQps()
      从接口复制的说明: Node
      Get estimated max success QPS till now.
      指定者:
      maxSuccessQps 在接口中 Node
      返回:
      max completed QPS
    • occupiedPassQps

      public double occupiedPassQps()
      从接口复制的说明: OccupySupport
      Get current occupied pass QPS.
      指定者:
      occupiedPassQps 在接口中 OccupySupport
      返回:
      current occupied pass QPS
    • avgRt

      public double avgRt()
      从接口复制的说明: Node
      Get average rt per second.
      指定者:
      avgRt 在接口中 Node
      返回:
      average response time per second
    • minRt

      public double minRt()
      从接口复制的说明: Node
      Get minimal response time.
      指定者:
      minRt 在接口中 Node
      返回:
      recorded minimal response time
    • curThreadNum

      public int curThreadNum()
      从接口复制的说明: Node
      Get current active thread count.
      指定者:
      curThreadNum 在接口中 Node
      返回:
      current active thread count
    • addPassRequest

      public void addPassRequest(int count)
      从接口复制的说明: Node
      Add pass count.
      指定者:
      addPassRequest 在接口中 Node
      参数:
      count - count to add pass
    • addRtAndSuccess

      public void addRtAndSuccess(long rt, int successCount)
      从接口复制的说明: Node
      Add rt and success count.
      指定者:
      addRtAndSuccess 在接口中 Node
      参数:
      rt - response time
      successCount - success count to add
    • increaseBlockQps

      public void increaseBlockQps(int count)
      从接口复制的说明: Node
      Increase the block count.
      指定者:
      increaseBlockQps 在接口中 Node
      参数:
      count - count to add
    • increaseExceptionQps

      public void increaseExceptionQps(int count)
      从接口复制的说明: Node
      Add the biz exception count.
      指定者:
      increaseExceptionQps 在接口中 Node
      参数:
      count - count to add
    • increaseThreadNum

      public void increaseThreadNum()
      从接口复制的说明: Node
      Increase current thread count.
      指定者:
      increaseThreadNum 在接口中 Node
    • decreaseThreadNum

      public void decreaseThreadNum()
      从接口复制的说明: Node
      Decrease current thread count.
      指定者:
      decreaseThreadNum 在接口中 Node
    • debug

      public void debug()
      从接口复制的说明: DebugSupport
      For debug;
      指定者:
      debug 在接口中 DebugSupport
    • tryOccupyNext

      public long tryOccupyNext(long currentTime, int acquireCount, double threshold)
      从接口复制的说明: OccupySupport
      Try to occupy latter time windows' tokens. If occupy success, a value less than occupyTimeout 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 在接口中 OccupySupport
      参数:
      currentTime - current time millis.
      acquireCount - tokens count to acquire.
      threshold - qps threshold.
      返回:
      time should sleep. Time >= occupyTimeout in OccupyTimeoutProperty means occupy fail, in this case, the request should be rejected immediately.
    • waiting

      public long waiting()
      从接口复制的说明: OccupySupport
      Get current waiting amount. Useful for debug.
      指定者:
      waiting 在接口中 OccupySupport
      返回:
      current waiting amount
    • addWaitingRequest

      public void addWaitingRequest(long futureTime, int acquireCount)
      从接口复制的说明: OccupySupport
      Add request that occupied.
      指定者:
      addWaitingRequest 在接口中 OccupySupport
      参数:
      futureTime - future timestamp that the acquireCount should be added on.
      acquireCount - tokens count.
    • addOccupiedPass

      public void addOccupiedPass(int acquireCount)
      从接口复制的说明: OccupySupport
      Add occupied pass request, which represents pass requests that borrow the latter windows' token.
      指定者:
      addOccupiedPass 在接口中 OccupySupport
      参数:
      acquireCount - tokens count.