Evidence from 4e0cc4e: stand ports, limits and per-service env,
X-Instance-Id distribution and scaling, LB-generated errors,
test-persistence through the LB, test-failover for each replica in stop
and kill modes, stop-one refusals, test runs and bench self-checks.
REPORT.md gains the LB architecture, timeout chain, limits, criteria
rows and defence answers. Coverage exclusions for restart now point to
the lab 3 persistence evidence; stale lab 2 pointers go to
KNOWN_ISSUES.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7.3 KiB
7.3 KiB
Распределение одной сессии по репликам и масштабирование без правки LB
| Спеки | load-balancing «Распределение без привязки клиента» — «Распределение видно оператору»; «Взаимозаменяемые реплики» — «Масштабирование без правки балансировщика»; «Проверка готовности реплик» — «Вернувшаяся реплика включена»; «Статистика балансировщика внутри сети» — «Состояние реплик» |
| Change | replicas-lb, задача 6.1 |
| Дата | 2026-10-10 15:21:22–15:21:35 UTC |
| Commit | 4e0cc4e |
| Стенд | make run_docker: проект mtusi-lab3, HAProxy на 127.0.0.1:8080, api × 2 (API_REPLICAS по умолчанию) |
| Хост | Docker Desktop 29.8.1, macOS arm64; ВМ Docker: 12 CPU, 7,7 GiB RAM; ноутбук от батареи; лимиты — stand.md |
| Клиент | make instances (driver.py instances скилла run-mtusi-messenger): один синтетический пользователь, один вход по Basic, затем 12 × GET /api/v1/users/me с одним Bearer-токеном; токен не печатается |
Шаг 1 сценария защиты (README.md): ≥2 разных X-Instance-Id через LB
с одной сессией.
$ make instances
1 GET /api/v1/users/me 200 x-instance-id: 0a93eeb192b4
2 GET /api/v1/users/me 200 x-instance-id: 47a14cfd6cd7
3 GET /api/v1/users/me 200 x-instance-id: 0a93eeb192b4
4 GET /api/v1/users/me 200 x-instance-id: 47a14cfd6cd7
5 GET /api/v1/users/me 200 x-instance-id: 0a93eeb192b4
6 GET /api/v1/users/me 200 x-instance-id: 47a14cfd6cd7
7 GET /api/v1/users/me 200 x-instance-id: 0a93eeb192b4
8 GET /api/v1/users/me 200 x-instance-id: 47a14cfd6cd7
9 GET /api/v1/users/me 200 x-instance-id: 0a93eeb192b4
10 GET /api/v1/users/me 200 x-instance-id: 47a14cfd6cd7
11 GET /api/v1/users/me 200 x-instance-id: 0a93eeb192b4
12 GET /api/v1/users/me 200 x-instance-id: 47a14cfd6cd7
user lb_b1f070bf: one login, 12 requests with one token
0a93eeb192b4: 6
47a14cfd6cd7: 6
instances: 2
$ make lb_stats
svname addr status check_status scur stot econ wretr wredis hrsp_5xx
api-1 172.30.0.5:8080 UP L7OK 0 1062 0 0 9 0
api-2 172.30.0.4:8080 UP L7OK 0 949 0 0 8 0
BACKEND - UP - 0 1998 2 0 18 6
free slots: 6
- Один вход, 12 запросов с одним токеном: все 200 с этим пользователем, ответы чередуются между двумя репликами (round-robin, без sticky).
X-Instance-Id— первые 12 символов ID контейнера:0a93eeb192b4=mtusi-lab3-api-1,47a14cfd6cd7=mtusi-lab3-api-2(stand.md).make lb_stats— занятые слоты HAProxy с адресом и состоянием проверки (L7OK—GET /health/readyответил 200). Счётчики накопительные с последнего рестарта LB:wredis/econ/hrsp_5xx— от прогоновmake test-failoverи остановки всех реплик (../failover/,lb-errors.md). Слоты HAProxy не совпадают с именами контейнеров: слот получает адрес из DNS.
Третья реплика без правки конфигурации LB
$ make replicas API_REPLICAS=3
docker compose up -d --no-deps --no-recreate --wait --scale api=3 api
Container mtusi-lab3-api-1 Running
Container mtusi-lab3-api-2 Running
Container mtusi-lab3-api-3 Creating
Container mtusi-lab3-api-3 Created
Container mtusi-lab3-api-3 Starting
Container mtusi-lab3-api-3 Started
Container mtusi-lab3-api-3 Waiting
Container mtusi-lab3-api-2 Waiting
Container mtusi-lab3-api-1 Waiting
Container mtusi-lab3-api-3 Healthy
Container mtusi-lab3-api-2 Healthy
Container mtusi-lab3-api-1 Healthy
# 2 с после начала make replicas: instances: 3
$ docker compose ps api
mtusi-lab3-api-1 0a93eeb192b4 Up 9 minutes (healthy) 8080/tcp
mtusi-lab3-api-2 47a14cfd6cd7 Up 11 minutes (healthy) 8080/tcp
mtusi-lab3-api-3 d5c01841dba2 Up 1 second (healthy) 8080/tcp
$ make instances
user lb_e30ad3cc: one login, 12 requests with one token
47a14cfd6cd7: 4
d5c01841dba2: 4
0a93eeb192b4: 4
instances: 3
$ make lb_stats
svname addr status check_status scur stot econ wretr wredis hrsp_5xx
api-1 172.30.0.5:8080 UP L7OK 0 1070 0 0 9 0
api-2 172.30.0.4:8080 UP L7OK 0 956 0 0 8 0
api-3 172.30.0.7:8080 UP L7OK 0 10 0 0 1 0
BACKEND - UP - 0 2020 2 0 18 6
free slots: 5
$ docker compose logs haproxy # окно масштабирования
api/api-3: IP changed from '(none)' to '172.30.0.7' by 'DNS cache'.
Server api/api-3 ('api') is DOWN/READY (resolves again).
Server api/api-3 administratively READY thanks to valid DNS answer.
Server api/api-3 is UP, reason: Layer7 check passed, code: 200, check duration: 1ms. 3 active and 0 backup servers online. 0 sessions requeued, 0 total in queue.
- Новая реплика попала в свободный слот из DNS Docker без
перезагрузки и правки
haproxy.cfg. Слот начал вDOWN(init-state down) и получил трафик только после проверки/health/ready; через 2 с после начала команды ответы шли уже от трёх реплик (спек: не позже 10 с).
Обратно две реплики
$ make replicas
docker compose up -d --no-deps --no-recreate --wait --scale api=2 api
Container mtusi-lab3-api-1 Running
Container mtusi-lab3-api-2 Running
Container mtusi-lab3-api-3 Stopping
Container mtusi-lab3-api-3 Stopped
Container mtusi-lab3-api-3 Removing
Container mtusi-lab3-api-3 Removed
Container mtusi-lab3-api-2 Waiting
Container mtusi-lab3-api-1 Waiting
Container mtusi-lab3-api-2 Healthy
Container mtusi-lab3-api-1 Healthy
$ docker compose ps api
mtusi-lab3-api-1 0a93eeb192b4 Up 9 minutes (healthy) 8080/tcp
mtusi-lab3-api-2 47a14cfd6cd7 Up 11 minutes (healthy) 8080/tcp
$ make lb_stats
svname addr status check_status scur stot econ wretr wredis hrsp_5xx
api-1 172.30.0.5:8080 UP L7OK 0 1070 0 0 9 0
api-2 172.30.0.4:8080 UP L7OK 0 956 0 0 8 0
BACKEND - UP - 0 2020 2 0 18 6
free slots: 6
$ make instances
47a14cfd6cd7: 6
0a93eeb192b4: 6
instances: 2
make replicas без аргумента возвращает число из .env (по умолчанию
2): лишняя реплика остановлена graceful и удалена, её слот снова
свободен.