-
Notifications
You must be signed in to change notification settings - Fork 252
CLDSRV-783: implement worker sync with Token Reservation System #6009
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
base: improvement/CLDSRV-766/bucket_rate_limiting
Are you sure you want to change the base?
CLDSRV-783: implement worker sync with Token Reservation System #6009
Conversation
lib/api/apiUtils/rateLimit/client.js
Outdated
| const { config } = require('../../../Config'); | ||
|
|
||
| const updateCounterScript = fs.readFileSync(`${__dirname }/updateCounter.lua`).toString(); | ||
| const reconcileCounterScript = fs.readFileSync(`${__dirname }/reconcileCounter.lua`).toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was removed in the latest commit
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (44.62%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files
... and 1 file with indirect coverage changes @@ Coverage Diff @@
## feature/CLDSRV-781-add-pre-and-post-MD-fetch-rate-limit #6009 +/- ##
===========================================================================================
- Coverage 84.23% 83.63% -0.60%
===========================================================================================
Files 203 205 +2
Lines 12648 12815 +167
===========================================================================================
+ Hits 10654 10718 +64
- Misses 1994 2097 +103
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
0251b1b to
fef2c04
Compare
Implement token reservation architecture where workers request capacity in advance from Redis. Workers maintain local token buffers and consume tokens in-memory (no Redis in hot path). Background refill job requests tokens every 100ms asynchronously. Redis enforces GCRA atomically at token grant time, ensuring strict quota enforcement across distributed workers. Components: - grantTokens.lua: Redis Lua script for atomic token granting - tokenBucket.js: WorkerTokenBucket class for local token management - refillJob.js: Background job for async token replenishment - client.js: Add grantTokens() method to Redis client
Switch from optimistic GCRA with reconciliation to token reservation. Workers consume tokens from local buffer instead of evaluating GCRA per request. This keeps Redis out of the hot path while enforcing strict quotas. Changes: - helpers.js: Use token consumption instead of GCRA evaluation - server.js: Start token refill job instead of sync job - cleanup.js: Add token bucket cleanup - gcra.js: Mark workers parameter unused (kept for compatibility)
Remove syncIntervalMs and reconciliationWeight fields that were used by the old reconciliation approach. Token reservation uses a fixed 100ms refill interval instead. What Each File Changes: - config.json - Removed syncIntervalMs: 1000 - config.js - Removed parsing for syncIntervalMs and reconciliationWeight - tokenBucket.js - Linting fixes (line length, return statements, braces) - cache.js - Updated comments - tests/config.js - Updated interval calculations for node-level quotas - tests/gcra.js - Updated tests showing workers are ignored - tests/helpers.js - Pre-populate token buckets, update assertions
79cee31 to
a8b289a
Compare
Architecture of Token Reservation System
Token Reservation Flow:
Key Benefits: