alibaba / alibaba/Sentinel

sentinel限流 在高并发调用下。可能会限流不准

Open
#1,592 1 comment 0 reactions 0 assignees View on GitHub
area/flow-control kind/discussion
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

我看源码里是否要限流。如下代码判断:

StatisticSlot.entry方法:
fireEntry(context, resourceWrapper, node, count, prioritized, args);

// Request passed, add thread count and pass count.
node.increaseThreadNum();
node.addPassRequest(count);

这里是先进行了 限流判断。再决定是否累加qps数。

DefaultController.canPass方法:
int curCount = avgUsedTokens(node); //获取当前的流量统计
if (curCount + acquireCount > count) {
if (prioritized && grade == RuleConstant.FLOW_GRADE_QPS) {
long currentTime;
long waitInMs;
currentTime = TimeUtil.currentTimeMillis();
waitInMs = node.tryOccupyNext(currentTime, acquireCount, count);
if (waitInMs < OccupyTimeoutProperty.getOccupyTimeout()) {
node.addWaitingRequest(currentTime + waitInMs, acquireCount);
node.addOccupiedPass(acquireCount);
sleep(waitInMs);

// PriorityWaitException indicates that the request will pass after waiting for {@link @waitInMs}.
throw new PriorityWaitException(waitInMs);
}
}
return false;
}
return true;

假设限流设置1000个。假如进来2000个请求 同时执行到 canpass方法的 if (curCount + acquireCount > count)。那么这两千个请求 都能通过。

Contributor guide

Open the contributing guide

Research direction

Start with StatisticSlot.entry and DefaultController.canPass, focusing on the ordering of the limit check and the subsequent request-count updates. Reproduce the reported case with a limit of 1000 and 2000 concurrent requests, then inspect the existing flow-control tests. Done means the concurrency case enforces the configured limit and has regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.