Enum Class RateLimitAlgorithm
- All Implemented Interfaces:
Serializable, Comparable<RateLimitAlgorithm>, Constable
限流算法枚举
定义支持的限流算法类型
算法对比: 1. TOKEN_BUCKET:令牌桶算法,允许突发流量,适合API限流 2. SLIDING_WINDOW:滑动窗口算法,平滑限流,适合精确控制 3. FIXED_WINDOW:固定窗口计数器,简单高效,适合粗粒度限流
- Author:
- Kerbores(kerbores@riemann.tech)
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionstatic RateLimitAlgorithmReturns the enum constant of this class with the specified name.static RateLimitAlgorithm[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
TOKEN_BUCKET
令牌桶算法核心思想: 1. 系统以恒定速率生成令牌 2. 请求需要获取令牌才能执行 3. 桶满时丢弃新令牌 4. 允许一定程度的突发流量
适用场景:API接口限流,允许短时间内的突发请求
-
SLIDING_WINDOW
滑动窗口算法核心思想: 1. 将时间划分为多个小窗口 2. 统计最近N个窗口内的请求数 3. 超过阈值则拒绝请求
适用场景:需要精确控制请求速率的场景
-
FIXED_WINDOW
固定窗口计数器核心思想: 1. 在固定时间窗口内计数 2. 超过阈值则拒绝请求 3. 窗口结束后重置计数
适用场景:简单限流,对精度要求不高的场景
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-