咨询RateLimiterController线程安全争议的问题

long currentTime = TimeUtil.currentTimeMillis(); // Calculate the interval between every two requests. long costTime = Math.round(1.0 * (acquireCount) / count * 1000);

// Expected pass time of this request.
long expectedTime = costTime + latestPassedTime.get();

if (expectedTime <= currentTime) {
    // Contention may exist here, but it's okay.
    latestPassedTime.set(currentTime);
    return true;
} 

    // Contention may exist here, but it's okay.
    latestPassedTime.set(currentTime);

咨询下:这里写着有争议, 但是确实出现了线程安全的问题,为啥是okay的?

原提问者GitHub用户fg546300040

展开
收起
码字王 2023-05-19 18:59:48 114 发布于北京 分享
分享
版权
举报
1 条回答
写回答
取消 提交回答
  • 至于RateLimiterController,它被设计为一种非严格线程安全的性能实现(以及在其他流量控制器中)。在Sentinel中,我们需要同时考虑正确性和性能。

    原回答者GitHub用户sczyh30

    2023-05-19 21:28:09 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
问答分类:
问答地址:

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

还有其他疑问?
咨询AI助理
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等