package
Version:
v0.10.1
Opens a new window with list of versions in this module.
Published: Nov 5, 2025
License: MIT
Opens a new window with license information.
Imports: 4
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
Documentation
¶
type RateState struct {
}
RateState 通过计数增长和时间间隔计算速率
NewRateState 创建速率计算器, 可选设置最小保护时间间隔, 默认 1 秒
Rate 计算并返回速率(每秒), 返回最近两次触达计算的请求时间间隔之间的计数增长平均速率
非实时计算, 可能返回上一轮速率结果
非精确计算, 当计数增长突发性很大或请求的时间间隔很长时, 速率结果与实际误差较大
若需要得到相对精准的结果, 按指定时间间隔调用 Rate 函数
-1 表示计数器被重置或无效, 0 表示无变化
Source Files
¶
Click to show internal directories.
Click to hide internal directories.