#rate package limiting window

11 messages ยท Page 1 of 1 (latest)

true plinth
#

never used it, but I was curious about this module ๐Ÿ™‚

#

if you add fmt.Println(limiter.Tokens()) above the current Println, you'll see what's happening

#

you start with a budget of 60 that refills at 1 every minute

#

so you get the initial 60 true, then false for a minute while it refills to 1, then the solo true and it starts to refill again

#

from fiddling I think you want to use time.Second rather than minute

#

doesn't look like it - the limit is defined as "events per second" in the docs, so you have to multiply out from that

#

yep, Tokens shows you how many events are left currently

#

then you want to set the limit to time.Second rather than Minute

#

yeah I think rate.NewLimiter(rate.Every(time.Second), 60) should do that? you're refilling 1 per second, with a maximum of 60 (also starting out at 60)

#

are you working on fixed time windows then? this is effectively a sliding window

true plinth
#

might be worth looking for 3rd party module then, looks like there's a bunch that simplify rate limiting