UBERF-10412: Make rate limit less aggressive (#8765)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2025-04-29 21:40:12 +07:00
committed by GitHub
parent 42db4c3389
commit 5c0ea43eda
2 changed files with 4 additions and 7 deletions
+3 -5
View File
@@ -40,15 +40,13 @@ export class SlidingWindowRateLimitter {
// Update reset time
rateLimit.resetTime = now + this.rateLimitWindow
rateLimit.requests.push(now + (rateLimit.rejectedRequests > this.rateLimitMax * 2 ? this.rateLimitWindow * 5 : 0))
if (rateLimit.requests.length <= this.rateLimitMax) {
rateLimit.requests.push(now + (rateLimit.rejectedRequests > this.rateLimitMax * 2 ? this.rateLimitWindow * 5 : 0))
}
if (rateLimit.requests.length > this.rateLimitMax) {
rateLimit.rejectedRequests++
if (rateLimit.requests.length > this.rateLimitMax * 2) {
// Keep only last requests
rateLimit.requests.splice(0, rateLimit.requests.length - this.rateLimitMax)
}
// Find when the oldest request will exit the window
const someRequest = Math.round(Math.random() * rateLimit.requests.length)
const nextAvailableTime = rateLimit.requests[someRequest] + this.rateLimitWindow
+1 -2
View File
@@ -123,7 +123,6 @@ describe('SlidingWindowRateLimitter', () => {
clock += 10000
const r2 = limiter.checkRateLimit('user1')
expect(r2.remaining).toBe(0)
expect(r2.retryAfter).toBeDefined()
expect(r2.remaining).toBe(9)
})
})