问题描述
比方说,我有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.参见 这篇关于如何实现分布式限速器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!