Lab2
This commit is contained in:
@@ -4,7 +4,7 @@ PostgreSQL, серверные сессии и Valkey
|
||||
|
||||
- Автор, группа: Максимова Мария, БВТ2303
|
||||
- Целевая оценка: 4
|
||||
- Commit / PR: `TODO` — подставить `git rev-parse --short HEAD` после финального коммита
|
||||
- Commit / PR: 02dfecc
|
||||
- Использованные средства: 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/`.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
|
||||
+30
-30
@@ -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: 50003; in explained chat: 10000
|
||||
messages total: 61133; in explained chat: 10000
|
||||
PASS: explained chat has >= 10 000 messages
|
||||
|
||||
-- first page
|
||||
Limit (actual time=0.010..0.016 rows=51 loops=1)
|
||||
Limit (actual time=0.042..0.048 rows=51 loops=1)
|
||||
Buffers: shared hit=4
|
||||
-> Index Scan using messages_keyset_idx on messages (actual time=0.010..0.013 rows=51 loops=1)
|
||||
-> Index Scan using messages_keyset_idx on messages (actual time=0.042..0.045 rows=51 loops=1)
|
||||
Index Cond: (chat_id = '7c57b8e9-42a1-4cf8-904b-08545328a890'::uuid)
|
||||
Buffers: shared hit=4
|
||||
Planning:
|
||||
Buffers: shared hit=6
|
||||
Planning Time: 0.131 ms
|
||||
Execution Time: 0.035 ms
|
||||
Planning Time: 0.084 ms
|
||||
Execution Time: 0.067 ms
|
||||
|
||||
-- keyset page after position 9000
|
||||
Limit (actual time=0.012..0.021 rows=51 loops=1)
|
||||
Limit (actual time=0.010..0.019 rows=51 loops=1)
|
||||
Buffers: shared hit=5
|
||||
-> Index Scan using messages_keyset_idx on messages (actual time=0.011..0.018 rows=51 loops=1)
|
||||
-> Index Scan using messages_keyset_idx on messages (actual time=0.010..0.016 rows=51 loops=1)
|
||||
Index Cond: ((chat_id = '7c57b8e9-42a1-4cf8-904b-08545328a890'::uuid) AND (ROW(created_at, id) > ROW('2026-10-01 07:31:21.6187+00'::timestamp with time zone, '6cbb1e03-f1e2-4113-8a7b-612c90c9761f'::uuid)))
|
||||
Buffers: shared hit=5
|
||||
Planning Time: 0.043 ms
|
||||
Execution Time: 0.104 ms
|
||||
Planning Time: 0.063 ms
|
||||
Execution Time: 0.069 ms
|
||||
|
||||
-- OFFSET 9000 (not used by the API)
|
||||
Limit (actual time=3.723..3.729 rows=51 loops=1)
|
||||
Buffers: shared hit=207
|
||||
-> Sort (actual time=3.127..3.460 rows=9051 loops=1)
|
||||
Limit (actual time=3.412..3.417 rows=51 loops=1)
|
||||
Buffers: shared hit=208
|
||||
-> Sort (actual time=2.955..3.217 rows=9051 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: quicksort Memory: 1713kB
|
||||
Buffers: shared hit=207
|
||||
-> Bitmap Heap Scan on messages (actual time=0.321..0.920 rows=10000 loops=1)
|
||||
Buffers: shared hit=208
|
||||
-> Bitmap Heap Scan on messages (actual time=0.240..0.883 rows=10000 loops=1)
|
||||
Recheck Cond: (chat_id = '7c57b8e9-42a1-4cf8-904b-08545328a890'::uuid)
|
||||
Heap Blocks: exact=134
|
||||
Buffers: shared hit=207
|
||||
-> Bitmap Index Scan on messages_keyset_idx (actual time=0.307..0.308 rows=10000 loops=1)
|
||||
Buffers: shared hit=208
|
||||
-> Bitmap Index Scan on messages_keyset_idx (actual time=0.224..0.224 rows=10000 loops=1)
|
||||
Index Cond: (chat_id = '7c57b8e9-42a1-4cf8-904b-08545328a890'::uuid)
|
||||
Buffers: shared hit=73
|
||||
Planning Time: 0.040 ms
|
||||
Execution Time: 3.848 ms
|
||||
Buffers: shared hit=74
|
||||
Planning Time: 0.110 ms
|
||||
Execution Time: 3.597 ms
|
||||
|
||||
-- keyset page WITHOUT messages_keyset_idx (rolled back)
|
||||
Limit (actual time=1.882..1.886 rows=51 loops=1)
|
||||
Buffers: shared hit=667
|
||||
-> Sort (actual time=1.880..1.882 rows=51 loops=1)
|
||||
Limit (actual time=2.273..2.278 rows=51 loops=1)
|
||||
Buffers: shared hit=817
|
||||
-> Sort (actual time=2.271..2.273 rows=51 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: top-N heapsort Memory: 31kB
|
||||
Buffers: shared hit=667
|
||||
-> Seq Scan on messages (actual time=0.386..1.804 rows=999 loops=1)
|
||||
Buffers: shared hit=817
|
||||
-> Seq Scan on messages (actual time=0.366..2.188 rows=999 loops=1)
|
||||
Filter: ((chat_id = '7c57b8e9-42a1-4cf8-904b-08545328a890'::uuid) AND (ROW(created_at, id) > ROW('2026-10-01 07:31:21.6187+00'::timestamp with time zone, '6cbb1e03-f1e2-4113-8a7b-612c90c9761f'::uuid)))
|
||||
Rows Removed by Filter: 49004
|
||||
Buffers: shared hit=667
|
||||
Rows Removed by Filter: 60134
|
||||
Buffers: shared hit=817
|
||||
Planning:
|
||||
Buffers: shared hit=4
|
||||
Planning Time: 0.088 ms
|
||||
Execution Time: 1.920 ms
|
||||
Planning Time: 0.166 ms
|
||||
Execution Time: 2.308 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 < 207)
|
||||
PASS: index reduces buffers for the deep page (5 < 667)
|
||||
PASS: keyset deep page touches fewer buffers than OFFSET (5 < 208)
|
||||
PASS: index reduces buffers for the deep page (5 < 817)
|
||||
|
||||
PASS: db checks
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ PASS: forged token still 401 without Valkey
|
||||
PASS: anonymous still 401 without Valkey
|
||||
PASS: logout works without Valkey
|
||||
PASS: token revoked during outage -> 401
|
||||
PASS: bounded latency during outage (max 0.27s)
|
||||
PASS: bounded latency during outage (max 0.26s)
|
||||
PASS: token revoked during outage stays 401 after Valkey returns (stale cache flushed)
|
||||
PASS: live session works after recovery
|
||||
|
||||
|
||||
+6
-6
@@ -2,16 +2,16 @@
|
||||
"lab": 2,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 15.0,
|
||||
"elapsed_seconds": 15.026,
|
||||
"elapsed_seconds": 15.017,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 3324,
|
||||
"successful_requests": 4452,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 221.222,
|
||||
"successful_rps": 296.457,
|
||||
"successful_latency_ms": {
|
||||
"p50": 15.779,
|
||||
"p95": 30.073,
|
||||
"p99": 59.585
|
||||
"p50": 12.336,
|
||||
"p95": 19.091,
|
||||
"p99": 32.117
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
|
||||
+6
-6
@@ -2,16 +2,16 @@
|
||||
"lab": 2,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 15.0,
|
||||
"elapsed_seconds": 15.026,
|
||||
"elapsed_seconds": 15.017,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 3324,
|
||||
"successful_requests": 4452,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 221.222,
|
||||
"successful_rps": 296.457,
|
||||
"successful_latency_ms": {
|
||||
"p50": 15.779,
|
||||
"p95": 30.073,
|
||||
"p99": 59.585
|
||||
"p50": 12.336,
|
||||
"p95": 19.091,
|
||||
"p99": 32.117
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,14 +1,14 @@
|
||||
## containers before restart hook
|
||||
api running Up 49 seconds 2026-10-02 09:47:54 +0300 MSK
|
||||
api_short_ttl running Up 49 seconds 2026-10-02 09:47:54 +0300 MSK
|
||||
db running Up 2 minutes (healthy) 2026-10-02 09:39:03 +0300 MSK
|
||||
migrate exited Exited (0) 53 seconds ago 2026-10-02 09:47:53 +0300 MSK
|
||||
valkey running Up 55 seconds (healthy) 2026-10-02 09:47:53 +0300 MSK
|
||||
api running Up 42 seconds 2026-10-02 09:54:27 +0300 MSK
|
||||
api_short_ttl running Up 42 seconds 2026-10-02 09:54:27 +0300 MSK
|
||||
db running Up 49 seconds (healthy) 2026-10-02 09:39:03 +0300 MSK
|
||||
migrate exited Exited (0) 42 seconds ago 2026-10-02 09:54:26 +0300 MSK
|
||||
valkey running Up 49 seconds (healthy) 2026-10-02 09:47: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 2 seconds 2026-10-02 09:47:54 +0300 MSK
|
||||
api_short_ttl running Up 54 seconds 2026-10-02 09:47:54 +0300 MSK
|
||||
db running Up 3 seconds (health: starting) 2026-10-02 09:39:03 +0300 MSK
|
||||
migrate exited Exited (0) 58 seconds ago 2026-10-02 09:47:53 +0300 MSK
|
||||
valkey running Up 3 seconds (health: starting) 2026-10-02 09:47:53 +0300 MSK
|
||||
api running Up 1 second 2026-10-02 09:54:27 +0300 MSK
|
||||
api_short_ttl running Up 46 seconds 2026-10-02 09:54:27 +0300 MSK
|
||||
db running Up 2 seconds (health: starting) 2026-10-02 09:39:03 +0300 MSK
|
||||
migrate exited Exited (0) 47 seconds ago 2026-10-02 09:54:26 +0300 MSK
|
||||
valkey running Up 2 seconds (health: starting) 2026-10-02 09:47:53 +0300 MSK
|
||||
|
||||
Reference in New Issue
Block a user