go-redis / redis_rate

Rate limiting for go-redis
https://redis.uptrace.dev/guide/go-redis-rate-limiting.html
BSD 2-Clause "Simplified" License
844 stars 101 forks source link

Can you support token bucket in next version? #48

Open zhaowujin opened 3 years ago

zhaowujin commented 3 years ago

Sometimes, token bucket is more suitable.

jeepli commented 1 year ago

I found it works as token bucket but NOT leaky bucket, I wonder if I miss understand the leaky bucket algorithm

whongki commented 1 year ago

I found it works as token bucket but NOT leaky bucket, I wonder if I miss understand the leaky bucket algorithm

According to the code, it has burst which proves it's a token bucket where you can have burst because you didn't use all the tokens. For a leaky packet, it will slows down the coming traffic until the gate opens, it surely not the same thing.

kevin19930919 commented 2 months ago

@whongki Thanks for the clarification! I spent the whole day wondering why it was a leaky bucket rate limiter, this tool looks more like a token bucket.

kevin19930919 commented 2 months ago

@whongki Thanks for the clarification! I spent the whole day wondering why it was a leaky bucket rate limiter, this tool looks more like a token bucket.

hmm... After more research on my part, it seems that GRCA is not a traditional leaky bucket, but an algorithm based on time windows but belonging to the leaky bucket type I don’t quite understand the difference between GRCA and token bucket, nor why GRCA is a leaky bucket algorithm as mention

kevin19930919 commented 2 months ago

It seems like there are 2 version of leaky bucket

  1. as a meter
  2. as a queue

In case of took it as a meter, leaky bucket actually the same as token bucket.

 In fact both are effectively the same, i.e. implementations of both the leaky bucket and token bucket, as these are the same basic algorithm described differently.