From ce8749d264e3d24b6f941f07070f96439bbadbf2 Mon Sep 17 00:00:00 2001 From: masha Date: Sat, 3 Oct 2026 11:14:52 +0300 Subject: [PATCH] Lab2 --- REPORT.md | 2 +- evidence/explain.txt | 50 ++++++++++++++++++++-------------------- evidence/load.json | 12 +++++----- evidence/load.txt | 12 +++++----- evidence/persistence.txt | 12 +++++----- 5 files changed, 44 insertions(+), 44 deletions(-) diff --git a/REPORT.md b/REPORT.md index 0d28b80..95c5d74 100644 --- a/REPORT.md +++ b/REPORT.md @@ -4,7 +4,7 @@ PostgreSQL, серверные сессии и Valkey - Автор, группа: Максимова Мария, БВТ2303 - Целевая оценка: 4 -- Commit / PR: 02dfecc +- Commit / PR: e78c103 - Использованные средства: Python 3.12.7 (в Docker), FastAPI, SQLAlchemy 2 (async) + asyncpg, argon2-cffi, redis-py 5 (клиент Valkey), PostgreSQL 16.4, Valkey 8.0.1, Docker Desktop + WSL2. - Источники: документация PostgreSQL (EXPLAIN, сравнение строк/row comparison, транзакции, WAL), документация Valkey (persistence, `SET NX`, `EX`), RFC 7617 (HTTP Basic), документация FastAPI и SQLAlchemy. - Помощь ИИ: Claude Code и Perplexity использовались для части реализации кэша, тестов уровня 4, диагностики окружения и оформления отчёта. Все команды, тесты и измерения я запускала локально сама, результаты сохранены в `evidence/`. diff --git a/evidence/explain.txt b/evidence/explain.txt index ee267b1..9bbd948 100644 --- a/evidence/explain.txt +++ b/evidence/explain.txt @@ -5,64 +5,64 @@ PASS: chat row was rolled back together with members PASS: no chats without members exist in the database == EXPLAIN for message history pagination -messages total: 59232; in explained chat: 10000 +messages total: 67882; in explained chat: 10000 PASS: explained chat has >= 10 000 messages -- first page -Limit (actual time=0.009..0.015 rows=51 loops=1) +Limit (actual time=0.013..0.018 rows=51 loops=1) Buffers: shared hit=4 - -> Index Scan using messages_keyset_idx on messages (actual time=0.009..0.012 rows=51 loops=1) + -> Index Scan using messages_keyset_idx on messages (actual time=0.012..0.015 rows=51 loops=1) Index Cond: (chat_id = 'bc6206c8-0e5d-48f3-94ea-a5fe15e0a9e5'::uuid) Buffers: shared hit=4 Planning: Buffers: shared hit=6 -Planning Time: 0.067 ms -Execution Time: 0.031 ms +Planning Time: 0.102 ms +Execution Time: 0.037 ms -- keyset page after position 9000 -Limit (actual time=0.012..0.020 rows=51 loops=1) +Limit (actual time=0.013..0.022 rows=51 loops=1) Buffers: shared hit=5 - -> Index Scan using messages_keyset_idx on messages (actual time=0.011..0.017 rows=51 loops=1) + -> Index Scan using messages_keyset_idx on messages (actual time=0.012..0.019 rows=51 loops=1) Index Cond: ((chat_id = 'bc6206c8-0e5d-48f3-94ea-a5fe15e0a9e5'::uuid) AND (ROW(created_at, id) > ROW('2026-10-01 19:08:45.800971+00'::timestamp with time zone, '6f9dad83-2a94-400a-877b-7202790747a3'::uuid))) Buffers: shared hit=5 -Planning Time: 0.051 ms -Execution Time: 0.069 ms +Planning Time: 0.050 ms +Execution Time: 0.078 ms -- OFFSET 9000 (not used by the API) -Limit (actual time=3.472..3.479 rows=51 loops=1) +Limit (actual time=3.380..3.385 rows=51 loops=1) Buffers: shared hit=208 - -> Sort (actual time=2.992..3.279 rows=9051 loops=1) + -> Sort (actual time=2.876..3.174 rows=9051 loops=1) Sort Key: created_at, id Sort Method: quicksort Memory: 1713kB Buffers: shared hit=208 - -> Bitmap Heap Scan on messages (actual time=0.190..0.756 rows=10000 loops=1) + -> Bitmap Heap Scan on messages (actual time=0.226..0.807 rows=10000 loops=1) Recheck Cond: (chat_id = 'bc6206c8-0e5d-48f3-94ea-a5fe15e0a9e5'::uuid) Heap Blocks: exact=134 Buffers: shared hit=208 - -> Bitmap Index Scan on messages_keyset_idx (actual time=0.177..0.178 rows=10000 loops=1) + -> Bitmap Index Scan on messages_keyset_idx (actual time=0.212..0.212 rows=10000 loops=1) Index Cond: (chat_id = 'bc6206c8-0e5d-48f3-94ea-a5fe15e0a9e5'::uuid) Buffers: shared hit=74 -Planning Time: 0.046 ms -Execution Time: 3.653 ms +Planning Time: 0.041 ms +Execution Time: 3.564 ms -- keyset page WITHOUT messages_keyset_idx (rolled back) -Limit (actual time=2.135..2.140 rows=51 loops=1) - Buffers: shared hit=783 - -> Sort (actual time=2.133..2.135 rows=51 loops=1) +Limit (actual time=2.474..2.478 rows=51 loops=1) + Buffers: shared hit=891 + -> Sort (actual time=2.472..2.474 rows=51 loops=1) Sort Key: created_at, id Sort Method: top-N heapsort Memory: 31kB - Buffers: shared hit=783 - -> Seq Scan on messages (actual time=0.349..2.058 rows=999 loops=1) + Buffers: shared hit=891 + -> Seq Scan on messages (actual time=0.405..2.402 rows=999 loops=1) Filter: ((chat_id = 'bc6206c8-0e5d-48f3-94ea-a5fe15e0a9e5'::uuid) AND (ROW(created_at, id) > ROW('2026-10-01 19:08:45.800971+00'::timestamp with time zone, '6f9dad83-2a94-400a-877b-7202790747a3'::uuid))) - Rows Removed by Filter: 58233 - Buffers: shared hit=783 + Rows Removed by Filter: 66883 + Buffers: shared hit=891 Planning: Buffers: shared hit=4 -Planning Time: 0.092 ms -Execution Time: 2.168 ms +Planning Time: 0.097 ms +Execution Time: 2.504 ms PASS: first page reads the index in order, no Sort PASS: keyset cursor is an Index Cond, not a filter over the history PASS: keyset deep page touches fewer buffers than OFFSET (5 < 208) -PASS: index reduces buffers for the deep page (5 < 783) +PASS: index reduces buffers for the deep page (5 < 891) PASS: db checks diff --git a/evidence/load.json b/evidence/load.json index 74e47f7..1d4f2a7 100644 --- a/evidence/load.json +++ b/evidence/load.json @@ -2,16 +2,16 @@ "lab": 2, "workload": "closed-loop POST messages; no automatic retries", "requested_duration_seconds": 15.0, - "elapsed_seconds": 15.019, + "elapsed_seconds": 15.018, "concurrency": 4, - "successful_requests": 4071, + "successful_requests": 3970, "failed_requests": 0, "error_ratio": 0.0, - "successful_rps": 271.065, + "successful_rps": 264.341, "successful_latency_ms": { - "p50": 13.402, - "p95": 22.878, - "p99": 31.89 + "p50": 13.83, + "p95": 23.53, + "p99": 32.665 }, "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." } diff --git a/evidence/load.txt b/evidence/load.txt index 74e47f7..1d4f2a7 100644 --- a/evidence/load.txt +++ b/evidence/load.txt @@ -2,16 +2,16 @@ "lab": 2, "workload": "closed-loop POST messages; no automatic retries", "requested_duration_seconds": 15.0, - "elapsed_seconds": 15.019, + "elapsed_seconds": 15.018, "concurrency": 4, - "successful_requests": 4071, + "successful_requests": 3970, "failed_requests": 0, "error_ratio": 0.0, - "successful_rps": 271.065, + "successful_rps": 264.341, "successful_latency_ms": { - "p50": 13.402, - "p95": 22.878, - "p99": 31.89 + "p50": 13.83, + "p95": 23.53, + "p99": 32.665 }, "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." } diff --git a/evidence/persistence.txt b/evidence/persistence.txt index 61373e1..93279d1 100644 --- a/evidence/persistence.txt +++ b/evidence/persistence.txt @@ -1,14 +1,14 @@ ## containers before restart hook -api running Up 6 minutes 2026-10-03 10:50:58 +0300 MSK -api_short_ttl running Up 7 minutes 2026-10-03 10:50:58 +0300 MSK +api running Up 7 minutes 2026-10-03 10:50:58 +0300 MSK +api_short_ttl running Up 21 minutes 2026-10-03 10:50:58 +0300 MSK db running Up 6 minutes (healthy) 2026-10-02 21:00:15 +0300 MSK -migrate exited Exited (0) 7 minutes ago 2026-10-03 10:50:58 +0300 MSK -valkey running Up 6 minutes (healthy) 2026-10-02 21:09:53 +0300 MSK +migrate exited Exited (0) 21 minutes ago 2026-10-03 10:50:58 +0300 MSK +valkey running Up 7 minutes (healthy) 2026-10-02 21:09:53 +0300 MSK Executing explicit persistence hook; hook output suppressed to avoid leaking secrets. PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence. ## containers after restart hook (Status shows new uptime) api running Up 1 second 2026-10-03 10:50:58 +0300 MSK -api_short_ttl running Up 7 minutes 2026-10-03 10:50:58 +0300 MSK +api_short_ttl running Up 21 minutes 2026-10-03 10:50:58 +0300 MSK db running Up 2 seconds (health: starting) 2026-10-02 21:00:15 +0300 MSK -migrate exited Exited (0) 7 minutes ago 2026-10-03 10:50:58 +0300 MSK +migrate exited Exited (0) 21 minutes ago 2026-10-03 10:50:58 +0300 MSK valkey running Up 2 seconds (health: starting) 2026-10-02 21:09:53 +0300 MSK