[CL-snapshots-parallel] parallelize performance snapshots (audit R6) #372

Merged
andrei merged 1 commit from feature/claude-snapshots-parallel into master 2026-06-18 09:37:16 +00:00
Owner

Что сделано

PerformanceSnapshotService.capture_snapshots (app/services/performance_snapshots.py, audit R6): per-strategy цикл (fetch trades + save) распараллелен — извлёк тело в _snapshot_one_strategy, fan-out asyncio.gather + Semaphore(8).

Зачем

Раньше юзер с N стратегиями платил N× per-strategy round-trip на 6-часовом snapshot-daemon тике (последовательные fetch+save). gather сохраняет порядок входа → результаты в том же порядке стратегий; per-strategy вычисление метрик не тронуто (работа независима).

План тестирования

  • TDD test_performance_snapshots_parallel: peak concurrency > 1 (было 1), order-preservation, semaphore-bound (max <= _SNAPSHOT_CONCURRENCY=8). 2 red→green.
  • Регрессия: perf-snapshot + rebalance сабсет 139 passed, 0 регрессий — fee-net snapshot-контракты зелёные byte-for-byte (метрики идентичны).

Где могу ошибаться

  • Happy-path результаты byte-identical (gather сохраняет порядок, compute неизменён). Fail-семантика сохранена (default gather = fail-all, как было; без return_exceptions чтобы не менять baseline).
  • Semaphore(8) ограничивает нагрузку на shared asyncpg-пул. Не money-path (read+aggregate). Прод-verify: daemon рестарт + health 200.
## Что сделано `PerformanceSnapshotService.capture_snapshots` (`app/services/performance_snapshots.py`, audit R6): per-strategy цикл (fetch trades + save) распараллелен — извлёк тело в `_snapshot_one_strategy`, fan-out `asyncio.gather` + `Semaphore(8)`. ## Зачем Раньше юзер с N стратегиями платил N× per-strategy round-trip на 6-часовом snapshot-daemon тике (последовательные fetch+save). `gather` сохраняет порядок входа → результаты в том же порядке стратегий; per-strategy вычисление метрик не тронуто (работа независима). ## План тестирования - TDD `test_performance_snapshots_parallel`: peak concurrency > 1 (было 1), order-preservation, semaphore-bound (`max <= _SNAPSHOT_CONCURRENCY=8`). 2 red→green. - Регрессия: perf-snapshot + rebalance сабсет **139 passed, 0 регрессий** — fee-net snapshot-контракты зелёные byte-for-byte (метрики идентичны). ## Где могу ошибаться - Happy-path результаты byte-identical (gather сохраняет порядок, compute неизменён). Fail-семантика сохранена (default gather = fail-all, как было; без return_exceptions чтобы не менять baseline). - Semaphore(8) ограничивает нагрузку на shared asyncpg-пул. Не money-path (read+aggregate). Прод-verify: daemon рестарт + health 200.
[CL-snapshots-parallel] capture performance snapshots concurrently (audit R6)
All checks were successful
Arnold Forgejo CI / backend-tests (pull_request) Successful in 4m41s
Arnold Forgejo CI / frontend-audit (pull_request) Successful in 14s
Arnold Forgejo CI / secret-scan (pull_request) Successful in 4s
Forgejo Smoke Test / Smoke (pull_request) Successful in 2s
beb7548153
PerformanceSnapshotService.capture_snapshots looped over a user's strategies one
at a time, doing a per-strategy trades fetch + save serially — a user with N
strategies paid N× the per-strategy round-trip on the 6-hourly snapshot daemon
tick.

Extract the per-strategy body into _snapshot_one_strategy and fan out with
asyncio.gather bounded by Semaphore(8). gather preserves input order so results
stay in the same strategy order, and each strategy's metric computation is
unchanged (the per-strategy work is independent) — the existing fee-net snapshot
contracts stay green byte-for-byte.

TDD: test_performance_snapshots_parallel pins peak concurrency > 1 (was 1),
order preservation, and the semaphore bound. 2 red->green; perf-snapshot +
rebalance suite 139 passed, 0 regressions. Not money-path.
andrei merged commit b4f56e7da8 into master 2026-06-18 09:37:16 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
europa-tech-srl/arnold-trader-app!372
No description provided.