Sentinel Flow rule does not take effect in first invocation | 第一次流控不生效吗?

nzrxty8p  于 2021-11-29  发布在  Java
关注(0)|答案(2)|浏览(256)

我尝试本机使用,

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) {
    }
  }

这是我的配置代码

private static void initFlowRules(){
  List<FlowRule> 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个线程测试,第一次测试,会打印出很多请求,第二次在测试,就流控正常了,请问是我配置有问题?

w8ntj3qf

w8ntj3qf2#

初次访问的时候 确实有这个问题,而且与线程数有关,社区可以一起来排查和完善一下。

相关问题