java.lang.Object
com.alibaba.csp.sentinel.slots.block.flow.controller.WarmUpController
所有已实现的接口:
TrafficShapingController
直接已知子类:
WarmUpRateLimiterController

public class WarmUpController extends Object implements TrafficShapingController

The principle idea comes from Guava. However, the calculation of Guava is rate-based, which means that we need to translate rate to QPS.

Requests arriving at the pulse may drag down long idle systems even though it has a much larger handling capability in stable period. It usually happens in scenarios that require extra time for initialization, e.g. DB establishes a connection, connects to a remote service, and so on. That’s why we need “warm up”.

Sentinel's "warm-up" implementation is based on the Guava's algorithm. However, Guava’s implementation focuses on adjusting the request interval, which is similar to leaky bucket. Sentinel pays more attention to controlling the count of incoming requests per second without calculating its interval, which resembles token bucket algorithm.

The remaining tokens in the bucket is used to measure the system utility. Suppose a system can handle b requests per second. Every second b tokens will be added into the bucket until the bucket is full. And when system processes a request, it takes a token from the bucket. The more tokens left in the bucket, the lower the utilization of the system; when the token in the token bucket is above a certain threshold, we call it in a "saturation" state.

Base on Guava’s theory, there is a linear equation we can write this in the form y = m * x + b where y (a.k.a y(x)), or qps(q)), is our expected QPS given a saturated period (e.g. 3 minutes in), m is the rate of change from our cold (minimum) rate to our stable (maximum) rate, x (or q) is the occupied token.

作者:
jialiang.linjl
  • 字段详细资料

    • count

      protected double count
    • warningToken

      protected int warningToken
    • slope

      protected double slope
    • storedTokens

      protected AtomicLong storedTokens
    • lastFilledTime

      protected AtomicLong lastFilledTime
  • 构造器详细资料

    • WarmUpController

      public WarmUpController(double count, int warmUpPeriodInSec, int coldFactor)
    • WarmUpController

      public WarmUpController(double count, int warmUpPeriodInSec)
  • 方法详细资料

    • canPass

      public boolean canPass(Node node, int acquireCount)
      从接口复制的说明: TrafficShapingController
      Check whether given resource entry can pass with provided count.
      指定者:
      canPass 在接口中 TrafficShapingController
      参数:
      node - resource node
      acquireCount - count to acquire
      返回:
      true if the resource entry can pass; false if it should be blocked
    • canPass

      public boolean canPass(Node node, int acquireCount, boolean prioritized)
      从接口复制的说明: TrafficShapingController
      Check whether given resource entry can pass with provided count.
      指定者:
      canPass 在接口中 TrafficShapingController
      参数:
      node - resource node
      acquireCount - count to acquire
      prioritized - whether the request is prioritized
      返回:
      true if the resource entry can pass; false if it should be blocked
    • syncToken

      protected void syncToken(long passQps)