Skip to content

axel-n/limiter-sliding-window

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rate limiter with sliding window algorithm

Java CI with Maven Maven Central License: Apache 2.0 javadoc

Why need another rate limiter?

  • this rate limiter is based on the algorithm sliding window
  • not found any solution in popular libraries (bucket4j, resilience4j, guava)

Briefly about the problem

Some resources (example1 , example2) has some limits for accept user requests.

So application need to know (fast, without sent packets to any additional system) - can they send request or wait or skip

How to use

add dependency for Maven

<dependency>
    <groupId>io.github.axel-n</groupId>
    <artifactId>limiter-sliding-window</artifactId>
    <version>0.3</version>
</dependency>

add dependency for Gradle

compile "io.github.axel-n:limiter-sliding-window:0.3"

Usage

examples availble in another repository

with annotation

@LimiterConfig(
        instanceName = "common", // name of limiter config. you can use several limiters
        maxTimeWait = @TimeConfig(value = 10, interval = TimeUnit.SECONDS), // optional
        limitType = ExecutionLimitType.EXECUTE_OR_WAIT // also available EXECUTE_OR_THROW_EXCEPTION
)
public void limiterWrapperService() {
  // call some your service
}

manual check limiter and execute

// use executeOrWait or executeOrThrowException
limiter.executeOrWait(() -> { 
  // run runnable or callable
});

How it works sliding window algorithm

image info

Plans

  • integrate deploy to maven repository
  • add example without spring boot
  • add methods for run something with limiter wrapper
  • add tests in concurrency execution
  • add example with spring boot
  • add usage with annotation
  • increase code coverage
  • load values from values in specific environments (like slow github runner)
  • add ability setup several limiters (for example 30 requests per 1 minute and 5 requests per second)
  • add integration with monitoring
  • add normal logging

About

rate limiter with sliding window with 1 dependency

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages