Skip to content

Commit

Permalink
feat: step down rate limit more aggressively on 529s (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Dec 20, 2024
1 parent 83db16e commit 5f61d2f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions dank_mids/helpers/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async def post(self, endpoint: str, *args, loads: JSONDecoder = DEFAULT_JSON_DEC

async def handle_too_many_requests(self, endpoint: str, error: ClientResponseError) -> None:
limiter = limiters[endpoint]
if (now := time()) > getattr(limiter, "_last_updated_at", 0) + 60:
if (now := time()) > getattr(limiter, "_last_updated_at", 0) + 30:
current_rate = limiter._rate_per_sec
new_rate = current_rate * 0.97
limiter._rate_per_sec = new_rate
Expand All @@ -241,7 +241,7 @@ async def handle_too_many_requests(self, endpoint: str, error: ClientResponseErr
now = time()
self._last_rate_limited_at = now
secs_between_requests = 1 / limiter._rate_per_sec
retry_after = float(error.headers.get("Retry-After", secs_between_requests * 10))
retry_after = float(error.headers.get("Retry-After", secs_between_requests * 5))
resume_at = max(
self._continue_requests_at + retry_after,
self._last_rate_limited_at + retry_after,
Expand Down

0 comments on commit 5f61d2f

Please sign in to comment.