vault backup: 2026-06-01 10:06:16

This commit is contained in:
2026-06-01 10:06:16 +08:00
parent f67dbcbc15
commit 65da199749
6 changed files with 254 additions and 158 deletions
+7 -7
View File
@@ -16,8 +16,8 @@ create time: 2026-06-01 10:30
假设总窗口是 1 秒,切成 N=10 个子窗口(每个 100ms):
```mermaid
flowchart TD["滑动窗口计数器 - N=10 子窗口"]
subgraph Window["1 秒总窗口"]
flowchart TD
subgraph Window["1 秒总窗口(N=10 子窗口)"]
direction LR
W1["W1<br/>已过期的部分 × 占比"]
W2["W2<br/>已过期的部分 × 占比"]
@@ -62,11 +62,11 @@ flowchart TD["滑动窗口计数器 - N=10 子窗口"]
滑动窗口范围:t ∈ [7.5 - 10, 7.5] = [-2.5, 7.5]
各个窗口在当前窗口内的存活时间:
W8 (7~8s) : 存活 0.5s → 占比 5%/10s = 0.05
W7 (6~7s) : 存活 1.0s → 占比 1.0s/10s = 0.10
W6 (5~6s) : 存活 1.0s → 占比 0.10
W8 (7~8s) : 存活 0.5s → 占比 0.5/10 = 0.05
W7 (6~7s) : 存活 1.0s → 占比 1.0/10 = 0.10
W6 (5~6s) : 存活 1.0s → 占比 1.0/10 = 0.10
...(中间同理)...
W-1(-2~-1s): 存活 0.5s → 占比 0.05
W₋₁(-2~-1s): 存活 0.5s → 占比 0.5/10 = 0.05
```
在这个场景中,`total = W8.count × 0.05 + W7.count × 0.10 + ... + W-1.count × 0.05`
@@ -118,7 +118,7 @@ slot[i] 的贡献度 = count[i] × weight[i]
举例(N=10,当前在第 8 个槽):
- slot[7](上一个完整窗口): weight = (10-1)/10 = 0.9
- slot[6]: weight = (10-2)/10 = 0.8
- slot[0](最早的那个): weight = (10-8)/10 = 0.2
- slot[0](距当前最远的那个): weight = (10-8)/10 = 0.2
> [!note]- 两种实现的等价性
>