Code Monkey home page Code Monkey logo

Comments (2)

jsocol avatar jsocol commented on May 14, 2024

Without higher precision in the log, this is what I believe is happening:

Your first request isn't at 00:34:38.000, so requests 1-5 are within one second. Then, since you're not waiting a full second after the 5th request, you're running into the second issue you describe.

There are two ways to deal with this. One is what happens right now: if requests keep coming in they keep getting blocked, because the TTL on the cache key is continuously pushed back.

The other is to treat the period as a window. So if the rate is 5/s, and someone is making 10 req/s, constantly, half of those will work, and half will get rate limited. If it's 60/m and they're making 10 req/s, they'll hit the limit after 6 seconds, but then 54 second later they can make another 60 requests.

I disliked that initially, but I've seen schemes like that used more in practice and have come around—or at least I'm more neutral now. The challenge is that you don't want all the windows to elapse at the same time, because then you get everyone who has been ratelimited free at the same time, which creates a thundering herd problem. So the scheme has to include some mechanism for staggering the windows.

from django-ratelimit.

jsocol avatar jsocol commented on May 14, 2024

Closing in favor of #48, which covers more specifics about how to do this.

from django-ratelimit.

Related Issues (20)

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.