Throttle
API to throttle/rate-limit requests
Install / Use
/learn @sudohippie/ThrottleREADME
Throttling API 
Overview
API to throttle/rate-limit requests
This API implements two popular throttling strategies, namely:
- Fixed token bucket
- Leaky token bucket
Fixed token bucket
Details for this implementation can be found at: Token Bucket
Leaky token bucket
Details for this implementation can be found at: Leaky Bucket With in the API, Leaky buckets have been implemented as two types
- StepDownLeakyTokenBucketStrategy
- StepUpLeakyTokenBucketStrategy
StepDownLeakyTokenBucketStrategy resembles a bucket which has been filled with tokens at the beginning but subsequently leaks tokens at a fixed interval. StepUpLeakyTokenBucketStrategy resemembles an empty bucket at the beginning but get filled will tokens over a fixed interval.
Examples
Fixed Bucket Example
// construct strategy
ThrottleStrategy strategy = new FixedTokenBucketStrategy(100, 1, TimeUnit.MINUTES);
// provide the strategy to the throttler
Throttle throttle = new Throttle(strategy);
// throttle :)
boolean isThrottled = throttle.canProceed();
if(!isThrottled){
// your logic
}
Step Up Leaky Bucket Example
// construct strategy
ThrottleStrategy strategy = new StepUpLeakyTokenBucketStrategy(100, 1, TimeUnit.MINUTES, 25, 15, TimeUnit.SECONDS);
// provide the strategy to the throttler
Throttle throttle = new Throttle(strategy);
// throttle :)
boolean isThrottled = throttle.canProceed();
if(!isThrottled){
// your logic
}
Step Down Leaky Bucket Example
// construct strategy
ThrottleStrategy strategy = new StepDownLeakyTokenBucketStrategy(100, 1, TimeUnit.MINUTES, 25, 15, TimeUnit.SECONDS);
// provide the strategy to the throttler
Throttle throttle = new Throttle(strategy);
// throttle :)
boolean isThrottled = throttle.canProceed();
if(!isThrottled){
// your logic
}
Wait For Token Availability Example
// construct strategy
ThrottleStrategy strategy = new FixedTokenBucketStrategy(100, 1, TimeUnit.MINUTES);
// provide the strategy to the throttler
Throttle throttle = new Throttle(strategy);
while(!throttle.canProceed()){
Thread.sleep(throttle.waitTime(TimeUnit.MILLISECONDS));
}
// your logic
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
