Files
mtusi2026lab2/openspec/changes/add-lab3-scaling-cost/tasks.md
T
ArtyomandClaude Opus 5.5 edc091dbc4 Choose a one-statement message write as the track 1 improvement
Series B located the bottleneck. At eight replicas the API has 40 % of
its CPU spare and the balancer 60 % of a core, yet three quarters of
the pool connections wait for a chat row lock: the locking SELECT of
the chat averages 14.2 ms and the lock holders sit idle in transaction
while the replica's event loop gets round to the next statement. The
critical section, three round trips long, is what more replicas
lengthen.

The design now records the choice: one CTE that locks the chat with
the membership check, stamps the message no earlier than the last one,
claims the idempotency key and inserts the message, committed by the
statement itself, so the lock never waits for the application. A taken
key is read back by a second statement outside the lock. The price is
that the chat aggregate no longer guards posting; the rules move into
the adapter's SQL and are held by integration tests. The rejected
alternatives and the before/after plan are listed, and the spec gains
the observable requirement of a short critical section.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V1d3RLHNBBMA6UqBLLJv27
2026-10-29 01:06:10 +03:00

2.4 KiB
Raw Blame History

1. Стенд под измерения

  • 1.1 compose.yaml: закрепление CPU каждого сервиса через *_CPUSET (пусто по умолчанию), .env.example
  • 1.2 Проверка группы: docker compose --profile bench config --quiet, make limits по-прежнему PASS

2. Сэмплеры и оркестратор

  • 2.1 scripts/docker-stats.sh, scripts/lb-stats.sh, scripts/pg-stats.sh (activity, statements, reset, размер базы)
  • 2.2 scripts/scaling.py: конфигурация RxC с воркерами, пулом, очередью LB на реплику и закреплением CPU; ожидание ровно R реплик в LB; поиск колена с повторами; варианты «до/после» с чередованием; summary.csv и сырьё шага
  • 2.3 tools/plot_track1.py и make plots; цели make track1-a, track1-b, track1-compare, track1
  • 2.4 Проверка группы: make lint, make check, пробный шаг scaling.py на одной интенсивности

3. Серии

  • 3.1 Снимок docker stats всего хоста, версии и лимиты → evidence/track1/
  • 3.2 Серия A: 1×4, 2×2, 4×1 при 4 CPU / 2 GiB, ≥3 повтора
  • 3.3 Серия B: 1×1, 2×1, 8×1 (4×1 — из серии A), ≥3 повтора
  • 3.4 Проверка группы: насыщенное звено названо по метрикам summary.csv и топу pg_stat_statements

4. Улучшение

  • 4.1 Выбор улучшения по узкому месту серии B, запись в design.md: запись сообщения одним оператором SQL
  • 4.2 Реализация улучшения
  • 4.3 make track1-compare: до и после на той же конфигурации и интенсивностях, ≥3 повтора
  • 4.4 Проверка группы: make lint, make student-test, make test

5. Отчёт

  • 5.1 make plots, evidence/track1/README.md с картой файлов
  • 5.2 REPORT.md: раздел трека 1 — гипотезы, методика, таблицы серий, насыщение, улучшение, ограничения, выводы
  • 5.3 Проверка группы: make check, make lint, make student-test, make test