Flow rule does not take effect in first invocation | 第一次流控不生效吗?
- Dominant language
- Java
- Stars
- 23.1k
- Forks
- 8.1k
- PR merge metrics
- No merged PRs in 30d
Description
我尝试本机使用,
```java
private static final AtomicInteger atomicInteger = new AtomicInteger();
@GetMapping("/kill")
public String kill() throws InterruptedException {
helloWorld();
return "OK";
}
public void helloWorld() throws InterruptedException {
try (Entry entry = SphU.entry("helloWorld")) {
// 被保护的逻辑
System.out.println(TimeUtils.nowLocal() + " -> " + atomicInteger.getAndIncrement());
} catch (BlockException ex) {
}
}
```
这是我的配置代码
```java
private static void initFlowRules(){
List rules = new ArrayList<>();
FlowRule rule = new FlowRule();
rule.setResource("helloWorld");
rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
rule.setCount(1);
rules.add(rule);
FlowRuleManager.loadRules(rules);
}
public static void main(String[] args) {
initFlowRules();
SpringApplication.run(DideApplication.class, args);
}
```
使用Jmeter1000个线程测试,第一次测试,会打印出很多请求,第二次在测试,就流控正常了,请问是我配置有问题?
Contributor guide
Research direction
Start with the SphU.entry("helloWorld") call and FlowRuleManager.loadRules(rules) in initFlowRules(), then reproduce the first and second JMeter runs described in the issue. Trace when the rule becomes effective relative to SpringApplication.run and determine whether the first invocation is expected to be limited; document the confirmed cause and configuration guidance.
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
- Needs clarification
- Newbie friendliness
- 25/100