Sending a message used to be BEGIN, a SELECT ... FOR UPDATE of the chat with its members, a lookup of the idempotency key, the insert CTE and COMMIT. Three of those round trips ran under the chat row lock, and each one waited for the replica's event loop, so under load the lock holders sat idle in transaction while everyone else queued behind them. The new MessageLog port has one PostgreSQL adapter that does it all in a single statement with an implicit transaction: lock the chat row joined with the sender's membership, stamp the message with the later of the replica clock and the last message plus one microsecond, claim the key (overwriting it only if it has expired), insert the message only when the key was claimed, and move last_message_at. The foreign key from the key to the message is checked at the end of the statement, so the key may be written first. When the key is already taken the adapter reads the stored result with a second statement outside the lock, which also covers a concurrent duplicate that waited for the first one; the handler then replays it or answers 409 as before. The chat aggregate no longer takes part in posting, so its post, membership and last_message_at members and their unit tests are gone; Message.posted() builds the event. An invalid text is still answered 404 for an outsider: only then the handler reads the membership. A new API test pins the clock rule against a real database: a lagging replica clock gets the last stamp plus one microsecond, a clock ahead is kept. The concurrency, same-key race, expiry and access tests pass unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V1d3RLHNBBMA6UqBLLJv27
2.4 KiB
2.4 KiB
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