Repository navigation
perf(armory): fetch /p armory pages in parallel with an automatic brake - #15
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
The JSON API kept a limit of its own: a
/api/.../summarysent 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
/pspent ~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=0turns fast mode off without a code change./api/...(1 every 3 s). An API "Too many requests" slows only that bucket;/palready falls back to the profile HTML for the summary.sleep(1-2 s)and extra tokens./pasks for it together with the other pages, so_compute_personaje_base(shared with the cron, unchanged) reads it from cache.EXECUTOR6 → 8 workers, HTTP pool 10 → 20 connections.Expected impact
Simulated
/parmory phase with 330 ms per request (the latency the probe measured):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 --checkandmypyclean.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/pstill ends when the prefetch fails.Generated by Claude Code