Add Token Bucket algorithm for Rate Limiting#14375
Closed
signore662-beep wants to merge 3 commits intoTheAlgorithms:masterfrom
Closed
Add Token Bucket algorithm for Rate Limiting#14375signore662-beep wants to merge 3 commits intoTheAlgorithms:masterfrom
signore662-beep wants to merge 3 commits intoTheAlgorithms:masterfrom
Conversation
Closing this pull request as invalid@signore662-beep, this pull request is being closed as the files submitted contains an invalid extension. This repository only accepts Python algorithms. Please read the Contributing guidelines first. Invalid files in this pull request: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change:
This PR adds the Token Bucket algorithm, a widely used traffic shaping and rate-limiting algorithm. It is essential for controlling the amount of data or requests sent to a network or an API.
Why this is useful:
The Token Bucket is a core concept in computer networking and system design. Adding it to the repository provides an educational reference for students learning about resource management and API throttling.
Implementation details:
time.time()for real-time simulation but allows an optionalcurrent_timeparameter for deterministicdoctestverification.networking/token_bucket.pyChecklist:
pytestordoctestimport time
class TokenBucket:
"""
A Token Bucket algorithm implementation for rate limiting.
The bucket has a maximum capacity. Tokens are added at a fixed rate.
Each request consumes a token. If the bucket is empty, the request is denied.
if name == "main":
import doctest