alibaba / alibaba/Sentinel

Duplicate inbound QPS in some adapters | 入口QPS 重复统计问题

Open
#2,931 2 comments 0 reactions 0 assignees View on GitHub
area/metrics help wanted
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

## Issue Description
我这边使用的sentinel 的版本是:1.8.1

系统规则里面有一个入口QPS 统计,并可以对它进行限流。
对于我使用的版本 中如果我有多个资源在API 中定义,这些定义的资源名称对某一个相同的API 的匹配结果都为TRUE的时候。
全局统计(`Constants.ENTRY_NODE`) 将对该API 的一次请求重复计数。最终导致的结果是这一次请求被认为是多次QPS,与正常逻辑相违背。

Type: *bug report* or *feature request*
我认为它是一个BUG。我们应该将这些去重,但感觉这个问题似乎不是那么好处理。
除了http 请求的API 以外,其他的资源(使用注解定义的)应该也有这种重复的问题,这种重复就更难处理了吧。
参考:`com.alibaba.csp.sentinel.Constants#ENTRY_NODE`

关键代码片段

```java
@Spi(order = Constants.ORDER_STATISTIC_SLOT)
public class StatisticSlot extends AbstractLinkedProcessorSlot {

@Override
public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count,
boolean prioritized, Object... args) throws Throwable {
...
if (resourceWrapper.getEntryType() == EntryType.IN) {
// Add count for global inbound entry node for global statistics.
Constants.ENTRY_NODE.increaseThreadNum();
Constants.ENTRY_NODE.addPassRequest(count);
}
...
}
}
```

`com.alibaba.csp.sentinel.slots.system.SystemRuleManager#checkSystem`
```java

public final class SystemRuleManager {

public static void checkSystem(ResourceWrapper resourceWrapper) throws BlockException {
...

// total qps
double currentQps = Constants.ENTRY_NODE == null ? 0.0 : Constants.ENTRY_NODE.successQps();
if (currentQps > qps) {
throw new SystemBlockException(resourceWrapper.getName(), "qps");
}

...
}
}

```

### Describe what happened (or what feature you want)

### Describe what you expected to happen

### How to reproduce it (as minimally and precisely as possible)

1.
2.
3.

### Tell us your environment

### Anything else we need to know?

Contributor guide

Open the contributing guide

Research direction

Start with StatisticSlot.entry and SystemRuleManager.checkSystem, focusing on updates and reads of Constants.ENTRY_NODE. Reproduce the case with multiple resources matching one API, then trace whether other annotated or adapter-defined resources follow the same path. Done means a single inbound request is counted once for global QPS, with regression coverage for the affected cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, performance
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.