如何实现分布式限速器? [英] How to implement distributed rate limiter?

查看:133
本文介绍了如何实现分布式限速器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我有P个进程在N台物理机上运行一些业务逻辑.例如,这些过程调用某些Web服务S.我想确保所有组合的P个进程每秒对服务S进行的调用不超过X个.

Let's say, I have P processes running some business logic on N physical machines. These processes call some web service S, say. I want to ensure that not more than X calls are made to the service S per second by all the P processes combined.

如何实施这种解决方案?

How can such a solution be implemented?

Google Guava的Rate Limiter非常适合在单个设备上运行的进程,但不适用于分布式设置.

Google Guava's Rate Limiter works well for processes running on single box, but not in distributed setup.

JAVA是否有可用的标准解决方案? [可能基于动物园管理员]

Are there any standard, ready to use, solutions available for JAVA? [may be based on zookeeper]

谢谢!

推荐答案

Bucket4j 是Java实现令牌桶"速率限制算法.它既可以在本地工作,也可以在分布式工作(在JCache之上).对于分布式用例,您可以自由选择任何JCache实现,例如Hazelcast或Apache Ignite.参见

Bucket4j is java implementation of "token-bucket" rate limiting algorithm. It works both locally and distributed(on top of JCache). For distributed use case you are free to choose any JCache implementation like Hazelcast or Apache Ignite. See this example of using Bucket4j in cluster.

这篇关于如何实现分布式限速器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆