Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add leaky-bucket algorithm #205

Closed
jeroenvisser101 opened this issue Oct 25, 2016 · 5 comments
Closed

Add leaky-bucket algorithm #205

jeroenvisser101 opened this issue Oct 25, 2016 · 5 comments

Comments

@jeroenvisser101
Copy link

jeroenvisser101 commented Oct 25, 2016

The Leaky Bucket Algorithm seems like a more natural algorithm to throttle requests. I've integrated this in a PHP port of rack-attack and authored it as a individual plugin: jeroenvisser101/LeakyBucket. I'd love to contribute this, as Ruby code, to rack-attack. Is this something that would fit in the vision of rack-attack?

@jeroenvisser101
Copy link
Author

jeroenvisser101 commented Oct 25, 2016

(I would add this as an additional throttle, I'm not thinking about replacing the old one)

@ktheory
Copy link
Collaborator

ktheory commented Oct 26, 2016

That's an interesting possibility.

Do you think it's possible to implement a leaky bucket algorithm in memcached? It's not obvious to me. 😊

@jeroenvisser101
Copy link
Author

Yes, you'd save both the capacity and the last time it was updated, you set the TTL to the maximum time it would take to leak. Then, before you update a value, you can calculate how many seconds have passed, update the number to reflect what had leaked out, and then increase the 'drops'.

@jeroenvisser101
Copy link
Author

I'll see if I can build a PoC for this to show how it would work!

@jeroenvisser101
Copy link
Author

Hey @ktheory, I've created a PR (and it's green 🎉), let me know if you've got any questions or remarks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants