令牌桶 java_bucket4j - 基于令牌桶算法的Java速率限制库

Bucket4j - is Java rate-limiting library based on token-bucket algorithm.

625332134c6f4d4600884b99daebf603.png625332134c6f4d4600884b99daebf603.png625332134c6f4d4600884b99daebf603.png625332134c6f4d4600884b99daebf603.png

Advantages of Bucket4j

Implemented on top of ideas of well known algorithm, which are by de-facto standard for rate limiting in the IT industry.

Effective lock-free implementation, Bucket4j is good scalable for multi-threading case.

Absolutely non-compromise precision, Bucket4j does not operate with floats or doubles, all calculation are performed in the integer arithmetic, this feature protects end users from calculation errors involved by rounding.

Ability to switch from one JVM to cluster in two lines of code. Using Bucket4j you are able to limiting something in the cluster of JVMs. Since release 1.2 the Bucket4j supports any GRID solution which compatible with JCache API (JSR 107) specification. Just use your favorite grid including Hazelcast, Ignite, Coherence, Infinispan or any other.

Ability to specify multiple bandwidths per bucket. For example you can limit 1000 events per hours but not often then 100 events per minute.

Both synchronous and asynchronous API.

Pluggable listener API that allows to implement monitoring and logging.

Ability to use bucket as as scheduler, see examples.

Supported back-ends

As mentioned above in addition to local in-memory buckets, the Bucket4j supports clustered usage scenario on top of following back-ends:

Back-end

Documentation page

Async supported

General documentation

Basics:

Token bucket wikipedia - wikipedia page describes the token-bucket algorithm in classical form.

Non-formal overview of token-bucket algorithm - the brief overview of token-bucket algorithm.

Examples:

Basic-usage - examples of basic usage.

Advanced-usage - examples of advanced usage.

Asynchronous-usage - examples of asynchronous usage.

Production checklist

Common production checklist - Mandatory points that need to be understood before using the Bucket4j in production, independently of local or clustered usage scenarios.

JCache production checklist - Mandatory points that need to be understood before using the Bucket4j over JCache cluster.

Archive:

Third-party integrations:

Third-party Demos:

Get Bucket4j library

You can add Bucket4j to your project as maven dependency

The Bucket4j is distributed through both JCenter and Maven Central, use any of them:

com.github.vladimir-bukhtoyarov

bucket4j-core

4.1.1

Warning: do not use 4.1.0 version, it was released with mistake.

You can build Bucket4j from sources

git clone https://github.com/vladimir-bukhtoyarov/bucket4j.git

cd bucket4j

mvn clean install

Have a question?

Feel free to ask in the gitter chat

License

Copyright 2015-2018 Vladimir Bukhtoyarov Licensed under the Apache Software License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0.

Give beer to author

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值