feat(perf): benchmark and load-test tooling with real FIO game data - #49
Merged
Merged
Conversation
Each import_all_* now fetches from FIO and hands the validated data to a save_* function (materials, buildings, recipes, planets, exchanges), and the CXPC task builds its rows with cxpc_objects. Behaviour is unchanged; the split lets the perf seed load a saved FIO snapshot through the same field mapping. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
perf/run.sh seeds a throwaway Postgres + Redis in Docker, benchmarks the main endpoints in-process (query counts, cold and warm latency, size), optionally load-tests gunicorn with Locust, and reports regressions against the previous run of the same scale, mode and game data source. - perf_snapshot downloads the public FIO game data once (sequential, validated with the FIO schemas) into perf/snapshot/gamedata.json.gz; --cxpc-sample adds real price history for a few tickers. - seed_perf --source auto|snapshot|fake loads the snapshot through the FIO importers; fake users, plans and empires use real planets, buildings and recipe ids, and the analytics aggregations run after seeding so the analytics endpoints serve real data. - run.sh downloads the snapshot when missing (--no-snapshot for fake data) and records the source; report.py only compares like with like. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Security | 10 medium 4 high |
🟢 Metrics 284 complexity · 0 duplication
Metric Results Complexity 284 Duplication 0
🟢 Coverage 97.13% diff coverage · +3.38% coverage variation
Metric Results Coverage variation ✅ +3.38% coverage variation (-1.00%) Diff coverage ✅ 97.13% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (a0333a9) 3322 3008 90.55% Head commit (3dbd1b2) 3836 (+514) 3603 (+595) 93.93% (+3.38%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#49) 522 507 97.13% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
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.
Summary
Adds a perf suite for the backend and seeds it with real game data from FIO.
perf/run.shstarts a throwaway Postgres + Redis in Docker (in memory, own ports), migrates and seeds it, then:manage.py perf_bench): in-process requests to the main endpoints as a power user, recording SQL query count, response size, and cold/warm latency.perf/report.py):report.mdplus regressions against the previous run of the same scale, mode and game data source.Game data comes from a FIO snapshot (
manage.py perf_snapshot, gitignored atperf/snapshot/), downloaded once with sequential requests and validated with the FIO schemas.seed_perf --source auto|snapshot|fakeloads it through the FIO importers. The fake users, plans and empires use real planet ids, building tickers and recipe ids. After seeding, the analytics aggregations run, so the planet insight and material insight endpoints return real data.--no-snapshotforces fake game data. Docs are inperf/README.md.Review focus:
refactor(gamedata)commitThis commit touches production code. Each
import_all_*ingamedata/fio/importers.pyis split into a fetch plus asave_*function, and the CXPC task now builds its rows withcxpc_objects. Behaviour should be unchanged. Please review this commit on its own; the rest is perf-only code undercore/management/commands/andperf/.First results (small scale, real data, local machine)
No N+1 queries: every endpoint runs 1 to 4 queries. One finding to follow up separately, with no change in this PR:
GET /data/planets/takes 2.3 s uncached / 36 ms cached for 6.0 MB with the 4,576 real planets. It still runs 4 queries, so the time is Python-side. The likely cause is serializing 205,920 production-fee rows (45 per planet); it hasn't been profiled yet.Checks
uv run ruff check,uv run ruff format --check: passuv run ty check --exclude "**/migrations/*.py": passuv run pytest: 317 passed. 24 of them are new perf tests; none hit the network (pytest-httpx and a small fixture snapshot)typing.Anyperf/run.sh --mode quickran end to end locally with the FIO snapshot;--mode fulllast ran before the snapshot changes (fake data, 0 failures)No frontend change and no API change.
🤖 Generated with Claude Code