Реализовала лабораторную 3 на оценку 4

This commit is contained in:
MacBook
2026-10-16 12:42:16 +03:00
parent 0ab3a341aa
commit c1d62f7f23
32 changed files with 2141 additions and 35 deletions
+24
View File
@@ -0,0 +1,24 @@
INSERT 0 1
INSERT 0 1
INSERT 0 1
DELETE 0
INSERT 0 10000
ANALYZE
fixture_messages
------------------
10000
(1 row)
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.41..20.19 rows=50 width=84) (actual time=0.006..0.018 rows=50 loops=1)
Buffers: shared hit=53
-> Index Scan using messages_chat_history_idx on messages (cost=0.41..4018.79 rows=10160 width=84) (actual time=0.005..0.015 rows=50 loops=1)
Index Cond: (chat_id = '00000000-0000-4000-8000-000000000002'::uuid)
Buffers: shared hit=53
Planning:
Buffers: shared hit=20
Planning Time: 0.069 ms
Execution Time: 0.028 ms
(9 rows)
+21
View File
@@ -0,0 +1,21 @@
{
"workload": "single-client closed-loop POST messages",
"runs": [
{
"stopped_instance": "api-1",
"duration_seconds": 8.001,
"successful_requests": 5147,
"failed_requests": 0,
"successful_rps": 643.321,
"first_survivor_success_seconds": 0.22
},
{
"stopped_instance": "api-2",
"duration_seconds": 8.001,
"successful_requests": 5453,
"failed_requests": 0,
"successful_rps": 681.546,
"first_survivor_success_seconds": 0.237
}
]
}
+9
View File
@@ -0,0 +1,9 @@
{
"parallel_requests": 12,
"instances": [
"api-1",
"api-2"
],
"unique_message_ids": 1,
"conflicting_reuse_status": 409
}
+75
View File
@@ -0,0 +1,75 @@
# Результаты проверок лабораторной 3
Повторная проверка: 2026-10-16. Платформа: Docker Desktop на macOS arm64. Ветка: `solution/BVT2303-Merkulova`.
## Сборка и контракт
```text
$ go test ./...
ok mtusi-messenger/internal/messenger
$ go vet ./...
(ошибок нет)
$ make check
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
$ make test
PASS: lab3 public API scenario; infrastructure and grading evidence remain separate.
```
Шесть последовательных запросов через единственный публичный порт Nginx вернули `api-2`, `api-1`, `api-2`, `api-1`, `api-2`, `api-1`.
## Persistence и официальный failover
```text
$ ACTION_SCRIPT=./scripts/restart.sh make test-persistence
PASS: persistence preserved confirmed data and existing session.
```
Официальный failover после исправлений: две реплики наблюдались до отказа, 130 записей успешны, ошибок 0, first recovery 0.734 s. После этого `failover_experiment.py` последовательно остановил `api1` и `api2`, каждый раз восстанавливая предыдущую реплику. `docker compose ps -a` в прежней проверке подтвердил `Exited (0)` у выбранной реплики.
## Собственные проверки уровня 4
```text
$ python3 student-tests/verify_idempotency.py
PASS: 12 parallel requests; instances api-1/api-2; one unique message; conflict=409
$ python3 student-tests/failover_experiment.py
PASS: api-1 5147/0, 643.321 RPS, 0.220 s
PASS: api-2 5453/0, 681.546 RPS, 0.237 s
$ python3 student-tests/rolling_update_experiment.py
PASS: 24198 successful, 0 failed, 1572.196 RPS
p50=2.246 ms p95=4.140 ms p99=6.926 ms
instances=api-1,api-2
```
Сырые безопасные summaries: `idempotency.json`, `failover-grade4.json`, `rolling-update.json`.
## Сохранённые проверки lab2
```text
$ python3 student-tests/verify_grade4.py
PASS: registration race, transaction rollback, bad password and logout
$ python3 student-tests/verify_expiry.py
PASS: two-second Redis session expired and was rejected
$ python3 student-tests/verify_dependencies.py
PASS: Redis/PostgreSQL failures returned 503; anonymous access stayed 401; state recovered
```
## Ресурсные limits
```text
api1 cpu=500000000 memory=201326592
api2 cpu=500000000 memory=201326592
nginx cpu=250000000 memory=67108864
postgres cpu=1000000000 memory=536870912
redis cpu=250000000 memory=134217728
```
## SQL-план
`./scripts/explain_history.sh` создал 10 000 сообщений. PostgreSQL выбрал `Index Scan using messages_chat_history_idx`; execution time данного локального запуска с прогретым cache — 0.028 ms. Полный вывод находится в `explain-history.txt`.
+16
View File
@@ -0,0 +1,16 @@
{
"workload": "four-client closed-loop POST messages",
"elapsed_seconds": 15.391,
"successful_requests": 24198,
"failed_requests": 0,
"successful_rps": 1572.196,
"latency_ms_successes": {
"p50": 2.246,
"p95": 4.14,
"p99": 6.926
},
"instances": [
"api-1",
"api-2"
]
}