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

fix: improve rate limiter concurrency #2

Merged
merged 2 commits into from
Feb 8, 2025

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Improve Rate Limiter Concurrency

This PR improves the rate limiter's concurrency handling to ensure exactly 100 requests are processed before blocking additional requests.

Changes

  • Removed global mutex for better concurrency
  • Using atomic operations for accurate counting
  • Changed blocking logic to allow exactly MaxRequests
  • Added concurrent test cases
  • Improved window reset logic with atomic operations

Test Results

Load test with 150 concurrent requests shows proper rate limiting:

Status code distribution:
  [200] 100 responses  # First 100 requests processed successfully
  [429] 50 responses   # Additional requests blocked as expected

Implementation Details

  1. Storage Implementation:

    • Using sync.Map for thread-safe storage
    • Atomic operations for request counting
    • Thread-safe window reset logic
  2. Rate Limiter:

    • Removed unnecessary global mutex
    • Process exactly MaxRequests before blocking
    • Accurate request counting under high load
  3. Testing:

    • Added concurrent test cases
    • Verified with hey tool under high load
    • All tests passing

Link to Devin run: https://app.devin.ai/sessions/edf66e27ee6c4cbf8f70bafca9e24b04
Requested by: Wesley

devin-ai-integration bot and others added 2 commits February 8, 2025 18:15
Co-Authored-By: Wesley Willians <wesleywillians@gmail.com>
Co-Authored-By: Wesley Willians <wesleywillians@gmail.com>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add "(aside)" to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@wesleywillians wesleywillians merged commit 8add240 into main Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant