Coder Social home page Coder Social logo

koenpunt / bucket4j Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bucket4j/bucket4j

0.0 1.0 0.0 29.11 MB

Java rate limiting library based on token-bucket algorithm.

Home Page: https://bucket4j.com

License: Apache License 2.0

Java 81.76% Lua 0.91% Groovy 17.09% Kotlin 0.21% HTML 0.03%

bucket4j's Introduction

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

Licence

Bucket4j basic features

  • 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.
  • Effective implementation in terms of concurrency:
    • Bucket4j is good scalable for multi-threading case it by defaults uses lock-free implementation.
    • In same time, library provides different concurrency strategies that can be chosen when default lock-free strategy is not desired.
  • Effective API in terms of garbage collector footprint: Bucket4j API tries to use primitive types as much as it is possible in order to avoid boxing and other types of floating garbage.
  • Pluggable listener API that allows to implement monitoring and logging.
  • Rich diagnostic API that allows to investigate internal state.
  • Rich configuration management - configuration of the bucket can be changed on fly

Bucket4j distributed features

In additional to basic features described above, Bucket4j provides ability to implement rate-limiting in cluster of JVMs:

  • Bucket4j out of the box supports any GRID solution which compatible with JCache API (JSR 107) specification.
  • Bucket4j provides the framework that allows to quickly build integration with your own persistent technology like RDMS or a key-value storage.
  • For clustered usage scenarios Bucket4j supports asynchronous API that extremely matters when going to distribute world, because asynchronous API allows avoiding blocking your application threads each time when you need to execute Network request.

Supported JCache compatible(or similar) back-ends

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

Back-end Async supported Optimized serialization Thin-client support Documentation link
JCache API (JSR 107) No No No bucket4j-jcache
Hazelcast Yes Yes Planned bucket4j-hazelcast
Apache Ignite Yes n/a Yes bucket4j-ignite
Inifinispan Yes Yes No bucket4j-infinispan
Oracle Coherence Yes Yes No bucket4j-coherence

Non-JVM back-ends

Bucket4j authors strongly recommends to use JVM based back-ends when possible, but for cases where it is not possible Bucket4j provides following integrations with non-JVM based storages:

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

Back-end Async supported Documentation link
Redis/Redisson Yes bucket4j-redis/Redisson
Redis/Jedis No bucket4j-redis/Jedis
Redis/Lettuce Yes bucket4j-redis/Lettuce
MySQL No bucket4j-mysql
PostgreSQL No bucket4j-postgresql
DynamoDb No bucket4j-dynamodb

Local caches support

Sometimes you are having deal with bucket per key scenarios but distributed synchronization is unnecessary, for example where request stickiness is provided by a load balancer, or other use-cases where stickiness can be achieved by the application itself, for example, Kafka consumer. For such scenarios Bucket4j provides support for following list of local caching libraries:

Back-end Documentation link
Caffeine bucket4j-caffeine

Get Bucket4j library

You can add Bucket4j to your project as maven dependency

The Bucket4j is distributed through Maven Central:

<!-- For java 11+ -->
<dependency>
    <groupId>com.bucket4j</groupId>
    <artifactId>bucket4j-core</artifactId>
    <version>8.2.0</version>
</dependency>

<!-- For java 8 -->
<dependency>
    <groupId>com.bucket4j</groupId>
    <artifactId>bucket4j_jdk8-core</artifactId>
    <version>8.2.0</version>
</dependency>

You can build Bucket4j from sources

git clone https://github.com/bucket4j/bucket4j.git
cd bucket4j
mvn clean install

Have a question?

Feel free to ask via:

License

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

Java compatibility matrix

Since July 2022(release 8.0.0) it was decided to migrate Bucket4j to Java 11. It can be bad news for all who get stuck on Java 8 by different reasons. We understand your pain and will provide special builds with dedicated artifacts for java 8 for intermediate period, but keep in mind then probably access to fresh releases of Bucket4j for Java 8 can be moved to a commercial model in the future.

Bellow the compatibility matrix of Bucket4j's maven artefact with different java versions

JAVA 11 maven artifact JAVA 8 maven artifact Comments
com.bucket4j:bucket4j-core com.bucket4j:bucket4j_jdk8-core
com.bucket4j:bucket4j-jcache com.bucket4j:bucket4j_jdk8-jcache
com.bucket4j:bucket4j-coherence com.bucket4j:bucket4j_jdk8-coherence
com.bucket4j:bucket4j-hazelcast com.bucket4j:bucket4j_jdk8-hazelcast
com.bucket4j:bucket4j-hazelcast com.bucket4j:bucket4j_jdk8-hazelcast
com.bucket4j:bucket4j-infinispan com.bucket4j:bucket4j_jdk8-infinispan
Not supported com.bucket4j:bucket4j_jdk8-infinispan-8 Infinispan-8 is not compatible with Java 11
com.bucket4j:bucket4j-redis com.bucket4j:bucket4j_jdk8-redis
com.bucket4j:bucket4j-mysql com.bucket4j:bucket4j_jdk8-mysql
com.bucket4j:bucket4j-postgresql com.bucket4j:bucket4j_jdk8-postgresql
com.bucket4j:bucket4j-caffeine com.bucket4j:bucket4j_jdk8-caffeine
com.bucket4j:bucket4j-bucket4j-dynamodb-sdk-v1 com.bucket4j:bucket4j_jdk8-dynamodb-sdk-v1

bucket4j's People

Contributors

abelsromero avatar akhomchenko avatar alek-sys avatar alex-plekhanov avatar bbeck avatar cesartl avatar chipkillmar avatar dependabot[bot] avatar fairjm avatar gitter-badger avatar intricate avatar ioanngolovko avatar ivvve avatar jerrinot avatar luankevinferreira avatar mariachi89 avatar maxbartkov avatar misterchangray avatar namhptran avatar r331 avatar schnapster avatar simpleusr avatar skarpushin avatar sschepens avatar sullis avatar tetsukamen avatar troley avatar ttulka avatar vikinghawk avatar vladimir-bukhtoyarov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.