Files
mtusi2026lab4/evidence/attachments/slow-transfer.md
T
ricoromaandClaude Opus 5.5 8dc925e8ca docs: add attachments evidence and report
- re-capture coverage-exclusion evidence on the lab 4 stand: cache,
  auth storage, replay after API recreate, test-persistence,
  attachment-failover (stop, kill), attachment-storage
- green evidence/tests: student_test via LB, test_isolated,
  failure_checks; smoke, slow transfer, test-failover per replica
- bench_rollout label attachments: e1161f7 -> schema with attachments
  under load, no errors, messages = keys
- REPORT.md: attachments architecture, write order, defense answers,
  level 3/4 evidence rows, limitations; PLAN.md stage 2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 01:50:10 +03:00

46 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Медленные 10 MiB через LB: сессия БД не держится всю передачу
- Дата: 2026-10-20, 22:34:18–22:34:44 UTC.
- Commit: `d56b892` (код приложения — `116d8d3`, change `attachments`).
- Стенд: рабочий `mtusi-lab4` — HAProxy на `127.0.0.1:8080`
(`timeout client 30s`, `timeout server 10s`, `timeout http-request
10s` — `infra/haproxy/haproxy.cfg`), две реплики API, PostgreSQL,
Valkey, S3.
- Design change `attachments`, решение 5: срок запроса к БД
(`[database] request_timeout_seconds`, 6 с) раньше охватывал весь
запрос (зависимость с `yield` закрывается после отправки ответа), и
загрузка или отдача 10 MiB медленному клиенту оборвалась бы на 6-й
секунде с «Database is unavailable». Теперь вход — короткая сессия
(`CurrentUserBrief`), сервис открывает сессию на каждый шаг с БД.
Разовый скрипт `slow_transfer.py` (scratchpad, httpx): синтетический
пользователь и чат; PNG ровно 10 485 760 байт (64 × 64 и чанк `tEXt`);
загрузка 48 частями без `Content-Length` с паузами — ~12 с; затем
скачивание с чтением по 64 KiB и паузами — ~12 с.
```
$ uv run python -I slow_transfer.py http://127.0.0.1:8080 12
PNG 10485760 bytes, sha256 8dedb8f04881e4aba6be3e87badcf4a1c2dc91efb827046146140fb0feb98ee5
upload 10 MiB in 48 parts without Content-Length: 201 in 12.4 s, instance 847ad74efd7c
download 10 MiB read slowly: 200 in 13.1 s, instance 5f5d4ac50d9a, 10485760 bytes, sha256 match True
exit=0
$ docker compose logs --no-log-prefix --since 2m api | grep -c "Database is unavailable"
0
```
Записи журнала реплик об этих запросах (поля выбраны, `filename` не
пишется — только длина):
```
{'event': 'Uploaded attachment', 'instance_id': '847ad74efd7c', 'size_bytes': 10485760, 'content_type': "<ImageType.PNG: 'image/png'>", 'width': 64, 'height': 64, 'duration_ms': 12430, 'filename_length': 8}
{'event': 'HTTP request completed', 'instance_id': '5f5d4ac50d9a', 'method': 'GET', 'path': '/api/v1/attachments/{attachment_id}/content', 'status': 200, 'duration_ms': 4571.991}
```
- Загрузка в реплике шла 12,4 с — вдвое дольше срока сессии БД (6 с), и
закончилась 201: соединение пула занято только на короткие шаги
(членство, строка `pending`, `ready`), а не на чтение тела.
- Скачивание у клиента — 13,1 с, у реплики запрос закрыт через 4,6 с:
остаток 10 MiB держат буферы сокетов и HAProxy. Отдача потоком идёт
без сессии БД; SHA-256 полученного совпал.
- Записи «Database is unavailable» нет.