知识卡片
限流读改写会竞争
两个并发请求都读到旧计数,再分别写回相同的新值,会少记一次请求并放过超额流量。共享 Redis 只解决状态集中,不会自动消除多步读改写竞态;检查与变更需要合适的原子执行机制。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
- · 第04章 限流器
原书出处 · 1 处
- 限流器 · 查看原书依据
Race condition As discussed earlier, rate limiter works as follows at the high-level: •Read the counter value from Redis. •Check if (counter + 1) exceeds the threshold. •If not, increment the counter value by 1 in Redis. Race conditions can happen in a highly concurrent environment as shown in Figure 4-14. Assume the counter value in Redis is 3. If two requests concurrently read the
参考来源
- 位置:《System Design Interview – An insiders guide, Second Edition》第04章《限流器》(来源项目 book-sources;源文件:extracted/System Design Interview – An insiders guide, Second Edition/_epub-src/text/part0010_split_000.html)
- 结论依据:原文在该位置给出所述对象、机制或比较,支持本卡的解释;原书未展开的实现不作为已证明结论,算式与一致性边界在正文明确限定。
- 原始内容:Race condition As discussed earlier, rate limiter works as follows at the high-level: •Read the counter value from Redis. •Check if (counter + 1) exceeds the threshold. •If not, increment the counter value by 1 in Redis. Race conditions can happen in a highly concurrent environment as shown in Figure 4-14. Assume the counter value in Redis is 3. If two requests concurrently read the