Skip to content

perf(armory): fetch /p armory pages in parallel with an automatic brake - #15

Merged
joaquinmuzzi merged 1 commit into
masterfrom
claude/project-thread-0acif4
Nov 22, 2026
Merged

joaquinmuzzi merged 1 commit into
masterfrom
claude/project-thread-0acif4

Conversation

@joaquinmuzzi

Copy link
Copy Markdown
Owner

Requested by Joaquín · project thread

Why

Warmane removed the per-IP rate limit on the armory pages. A single probe run from Joaquín's PC on 2026-11-22 (42 requests) got:

  • 12/12 OK at 1 request every 3 s (it used to hit Cloudflare 1015 at request 12)
  • 20/20 OK at 1 request per second
  • ~7 req/s with 3 in parallel, no 429 and no 1015 on HTML pages

The JSON API kept a limit of its own: a /api/.../summary sent 0.5 s after another one answered HTTP 200 with {"error": "Too many requests."}, while the HTML pages kept working. Requests 5 s or more apart all passed.

The bot was still pacing everything at 1 request every 2 s and fetching the achievement categories one by one with extra sleeps, so an uncached /p spent ~16 s waiting on its own throttle.

What

  • AdaptiveTokenBucket (src/functions/rate_limit.py): fast mode (1.5 req/s, burst 6) that drops back to the old pace (0.5 req/s, burst 3) for 10 min on any 429, 5xx or 1015; every new rate limit extends it. ARMORY_FAST_RATE=0 turns fast mode off without a code change.
  • Separate bucket for /api/... (1 every 3 s). An API "Too many requests" slows only that bucket; /p already falls back to the profile HTML for the summary.
  • Achievements in parallel: the 4 categories (and the Ruby Sanctum rescue pass) run on their own pool, without the fixed sleep(1-2 s) and extra tokens.
  • Guild rank prefetch: /p asks for it together with the other pages, so _compute_personaje_base (shared with the cron, unchanged) reads it from cache.
  • EXECUTOR 6 → 8 workers, HTTP pool 10 → 20 connections.
  • README updated (rate limit section and new optional env vars).

Expected impact

Simulated /p armory phase with 330 ms per request (the latency the probe measured):

before after
character with Halion 16.3 s 1.7 s
character without Halion 24.3 s 3.0 s

The "before" number matches the ~17 s median seen in prod. UwU Logs time comes on top, as today.

Not verified: 6 requests in parallel, Railway's IP, and the exact API spacing (1 every 3 s is inferred from how the cron ran).

Tests

python -m pytest -q: 194 passed. ruff check, ruff format --check and mypy clean.

  • tests/test_rate_limit.py: adaptive bucket (burst, slow down, back to fast, extension, invalid params).
  • tests/test_armory_throttle.py (new): every rate-limit signal triggers the brake; the probe's API "Too many requests" slows only the API bucket.
  • tests/test_achievements.py: categories fetched in parallel (thread barrier), failed category marks the payload incomplete.
  • tests/test_personaje.py: guild rank prefetch, and /p still ends when the prefetch fails.

Generated by Claude Code

Warmane removed the per-IP rate limit on the armory pages. A probe from
Joaquín's PC on 2026-11-22 got 12/12 at 1 request every 3 s (it used to
hit Cloudflare 1015 at request 12), 20/20 at 1 per second and ~7 req/s
with 3 in parallel, with no 429 or 1015. The JSON API kept a limit of
its own: a /summary 0.5 s after another one answered HTTP 200 with
{"error": "Too many requests."}, while HTML pages kept working.

The bot was still pacing everything at 1 request every 2 s and fetching
the achievement categories one by one with extra sleeps, so an uncached
/p spent ~16 s waiting on its own throttle (simulated: 16.3 s with
Halion, 24.3 s without, matching the ~17 s median seen in prod).

- AdaptiveTokenBucket: fast mode (1.5 req/s, burst 6) that drops back
  to the old slow pace (0.5 req/s, burst 3) for 10 min on any 429, 5xx
  or 1015, extended by every new rate limit. ARMORY_FAST_RATE=0 turns
  fast mode off without a code change.
- Separate bucket for /api/... (1 every 3 s). An API "Too many
  requests" slows only that bucket; /p already falls back to the
  profile HTML for the summary.
- Achievement categories (and the Ruby Sanctum rescue pass) are fetched
  in parallel on their own pool, without the fixed sleeps.
- /p prefetches the guild rank together with the other pages, so the
  shared profile logic reads it from cache instead of asking for it
  last.
- EXECUTOR goes from 6 to 8 workers and the HTTP pool from 10 to 20.

Simulated /p armory phase (330 ms per request): 1.7 s with Halion,
3.0 s without, down from 16.3 s and 24.3 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017rjiQZE4L2JDiCVi1AKSoB
@joaquinmuzzi joaquinmuzzi self-assigned this Nov 22, 2026
@joaquinmuzzi
joaquinmuzzi merged commit 7ba5b51 into master Nov 22, 2026
2 checks passed
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.

2 participants