forked from mtusi2026/mtusi2026lab2
Реализовать лабораторную 2: API мессенджера с PostgreSQL и кэшем сессий
FastAPI-сервис с opaque-сессиями (Argon2id, SHA-256 фингерпринт), PostgreSQL как источником истины, Valkey как кэшем сессий, keyset-пагинацией, пулом соединений и таймаутами. Добавлены миграции, compose-стенд, скрипт рестарта, студенческие проверки и evidence.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
PASS: wrong password -> 401 with Basic challenge
|
||||
PASS: X-User-Id ignored for authentication
|
||||
PASS: logout revokes the session
|
||||
PASS: concurrent registration -> one 201 and seven 409
|
||||
PASS: authentication survives a cache outage
|
||||
PASS: student lab2 checks completed
|
||||
@@ -0,0 +1 @@
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
@@ -0,0 +1,7 @@
|
||||
== postgres stopped ==
|
||||
{"status":"ok"} [HTTP 200]
|
||||
{"error":{"code":"unavailable","message":"Хранилище недоступно","request_id":"d4ff2da4d2ca40f59b9a3e9986f8fbe2"}} [HTTP 503]
|
||||
{"error":{"code":"unavailable","message":"Хранилище недоступно","request_id":"7a513917f13846c89194b62f5c1f5e2f"}} [HTTP 503]
|
||||
== postgres restarted ==
|
||||
{"status":"ok"} [HTTP 200]
|
||||
{"error":{"code":"unauthorized","message":"Требуется аутентификация","request_id":"6ce854c975964caab1cf0c6d65adabc5"}} [HTTP 401]
|
||||
@@ -0,0 +1,6 @@
|
||||
PASS: wrong password -> 401 with Basic challenge
|
||||
PASS: X-User-Id ignored for authentication
|
||||
PASS: logout revokes the session
|
||||
PASS: concurrent registration -> one 201 and seven 409
|
||||
PASS: session expired after 2s TTL
|
||||
PASS: student lab2 checks completed
|
||||
@@ -0,0 +1,37 @@
|
||||
INSERT 0 0
|
||||
INSERT 0 0
|
||||
INSERT 0 0
|
||||
INSERT 0 10000
|
||||
ANALYZE
|
||||
=== message count ===
|
||||
messages
|
||||
----------
|
||||
10000
|
||||
(1 row)
|
||||
|
||||
=== EXPLAIN (ANALYZE, BUFFERS): keyset page in the middle of history ===
|
||||
QUERY PLAN
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.42..17.91 rows=50 width=70) (actual time=0.006..0.014 rows=50 loops=1)
|
||||
Buffers: shared hit=5
|
||||
-> Index Scan using messages_chat_created_id_idx on messages (cost=0.42..1719.51 rows=4913 width=70) (actual time=0.006..0.011 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = '00000000-0000-4000-8000-0000000000aa'::uuid) AND (ROW(created_at, id) > ROW((now() - '01:23:20'::interval), '00000000-0000-4000-8000-000000000000'::uuid)))
|
||||
Buffers: shared hit=5
|
||||
Planning:
|
||||
Buffers: shared hit=20
|
||||
Planning Time: 0.056 ms
|
||||
Execution Time: 0.028 ms
|
||||
(9 rows)
|
||||
|
||||
=== EXPLAIN (ANALYZE, BUFFERS): first page (no cursor) ===
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.41..11.29 rows=50 width=70) (actual time=21.930..21.937 rows=50 loops=1)
|
||||
Buffers: shared hit=266 read=126 dirtied=126
|
||||
-> Index Scan using messages_chat_created_id_idx on messages (cost=0.41..2176.76 rows=10000 width=70) (actual time=21.929..21.933 rows=50 loops=1)
|
||||
Index Cond: (chat_id = '00000000-0000-4000-8000-0000000000aa'::uuid)
|
||||
Buffers: shared hit=266 read=126 dirtied=126
|
||||
Planning Time: 0.022 ms
|
||||
Execution Time: 21.948 ms
|
||||
(7 rows)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
SET
|
||||
SET
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=903.23..903.36 rows=50 width=70) (actual time=2.525..2.529 rows=50 loops=1)
|
||||
Buffers: shared hit=361
|
||||
-> Sort (cost=903.23..915.49 rows=4903 width=70) (actual time=2.525..2.526 rows=50 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: top-N heapsort Memory: 38kB
|
||||
Buffers: shared hit=361
|
||||
-> Seq Scan on messages (cost=0.00..740.36 rows=4903 width=70) (actual time=0.617..2.086 rows=4982 loops=1)
|
||||
Filter: ((chat_id = '00000000-0000-4000-8000-0000000000aa'::uuid) AND (ROW(created_at, id) > ROW((now() - '01:23:20'::interval), '00000000-0000-4000-8000-000000000000'::uuid)))
|
||||
Rows Removed by Filter: 12145
|
||||
Buffers: shared hit=355
|
||||
Planning:
|
||||
Buffers: shared hit=106
|
||||
Planning Time: 0.203 ms
|
||||
Execution Time: 2.550 ms
|
||||
(14 rows)
|
||||
|
||||
RESET
|
||||
RESET
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"lab": 2,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 15.0,
|
||||
"elapsed_seconds": 15.016,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 3553,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 236.614,
|
||||
"successful_latency_ms": {
|
||||
"p50": 16.0,
|
||||
"p95": 32.0,
|
||||
"p99": 47.0
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1 @@
|
||||
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
|
||||
Reference in New Issue
Block a user