ЛР 2: исследовать и ограничить cache stampede — на 5

This commit is contained in:
2026-10-25 15:42:14 +03:00
parent b5b35682c2
commit 799f56c513
116 changed files with 76270 additions and 91 deletions
+4
View File
@@ -0,0 +1,4 @@
python3 scripts/check_contract.py
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
python3 scripts/validate_openapi.py
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
+7
View File
@@ -0,0 +1,7 @@
PASS: concurrent same username: 12 requests, 1 x 201, 11 x 409
PASS: unknown member FK after parent INSERT rolls back chat and memberships; duplicate/missing owner -> 400
PASS: NUL in display_name/title/text -> 400; PostgreSQL readiness remains 200
PASS: strict types/extra fields, malformed JSON, UUID, limits/cursors, blank/oversized text, outsider isolation
PASS: 40 concurrent writes; tied timestamp UUID ordering; complete keyset traversal, scoped cursors, changing limit, read-after-write
PASS: malformed Basic, wrong/unknown credentials uniform 401, X-User-Id ignored, 128-code-point UTF8 colon password, stored Argon2id
PASS: real Valkey GET hits, TTL <=60 without sliding; expiry/refill; logout rejects cached profile and repeated logout
+1
View File
@@ -0,0 +1 @@
PASS: SESSION_TTL_SECONDS=2: immediate authentication succeeds; after 2.25s cached profile cannot bypass expiry/logout
+33
View File
@@ -0,0 +1,33 @@
Rows in test chat: 10000
Position: 0
Limit (cost=0.29..4.17 rows=51 width=70) (actual time=0.017..0.041 rows=51 loops=1)
Buffers: shared hit=3
-> Index Scan using messages_history on messages (cost=0.29..762.53 rows=10000 width=70) (actual time=0.016..0.032 rows=51 loops=1)
Index Cond: (chat_id = '618d27f6-266c-47a9-8d5f-37203cdd6861'::uuid)
Buffers: shared hit=3
Planning:
Buffers: shared hit=20
Planning Time: 0.208 ms
Execution Time: 0.065 ms
Position: 5000
Limit (cost=0.29..5.44 rows=51 width=70) (actual time=0.011..0.023 rows=51 loops=1)
Buffers: shared hit=4
-> Index Scan using messages_history on messages (cost=0.29..503.80 rows=4981 width=70) (actual time=0.010..0.018 rows=51 loops=1)
Index Cond: ((chat_id = '618d27f6-266c-47a9-8d5f-37203cdd6861'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.005001+00'::timestamp with time zone, '670bebbc-8919-425e-8a27-81c9b3bd2180'::uuid)))
Buffers: shared hit=4
Planning Time: 0.140 ms
Execution Time: 0.053 ms
Position: 9900
Limit (cost=0.29..68.56 rows=51 width=70) (actual time=0.015..0.028 rows=51 loops=1)
Buffers: shared hit=3
-> Index Scan using messages_history on messages (cost=0.29..135.50 rows=101 width=70) (actual time=0.014..0.023 rows=51 loops=1)
Index Cond: ((chat_id = '618d27f6-266c-47a9-8d5f-37203cdd6861'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.009901+00'::timestamp with time zone, '5d58dc9e-45f6-448f-8316-182dd9f07504'::uuid)))
Buffers: shared hit=3
Planning Time: 0.079 ms
Execution Time: 0.043 ms
PostgreSQL: 16.8 (Debian 16.8-1.pgdg120+1)
Durability: on on
PASS: actual EXPLAIN ANALYZE BUFFERS at first/middle/tail; API traversal 10000 rows, 100 pages, 2.130s
@@ -0,0 +1,4 @@
PASS: Valkey stopped: ready=200, authenticated read/write via PG, unknown/missing/revoked=401, outsider=404; scenario 0.616s
PASS: PostgreSQL stopped: ready/auth/write=503, live=200, no credentials=401, no cached authentication; scenario 0.165s
PASS: PostgreSQL recovery 2.607s, same valid token/data survive, revoked token remains revoked, rejected write absent
PASS: all 22 HTTP requests bounded below 4.5s; maximum 0.272s
@@ -0,0 +1,3 @@
PASS: versioned migrations applied (already applied versions skipped)
PASS: versioned migrations applied (already applied versions skipped)
PASS: two repeated migrations; all table counts and absolute session expiries unchanged: {'users': 9, 'chats': 3, 'chat_members': 5, 'messages': 43, 'sessions': 6, 'schema_migrations': 1}
@@ -0,0 +1,9 @@
/lab2-g5-20261025-clean-api-1 2026-10-24T23:05:44.433989766Z sha256:345a85414a671b5ad0a154d5b726f71744796937db95d2406eedd7cb107ab2e9
/lab2-g5-20261025-clean-postgres-1 2026-10-24T23:07:33.392983752Z sha256:301bcb60b8a3ee4ab7e147932723e3abd1cef53516ce5210b39fd9fe5e3602ae
/lab2-g5-20261025-clean-valkey-1 2026-10-24T23:07:30.251989711Z sha256:752ba000a58bc8925d11ee863a39b5225617cd2cb3dbc9ec8ac65268b65ebb6d
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://api:8080"
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
/lab2-g5-20261025-clean-api-1 2026-10-24T23:07:42.985481562Z sha256:345a85414a671b5ad0a154d5b726f71744796937db95d2406eedd7cb107ab2e9
/lab2-g5-20261025-clean-postgres-1 2026-10-24T23:07:43.115246938Z sha256:301bcb60b8a3ee4ab7e147932723e3abd1cef53516ce5210b39fd9fe5e3602ae
/lab2-g5-20261025-clean-valkey-1 2026-10-24T23:07:42.972426707Z sha256:752ba000a58bc8925d11ee863a39b5225617cd2cb3dbc9ec8ac65268b65ebb6d
@@ -0,0 +1 @@
PASS: same opaque token authenticates after all services restart; absolute PG expires_at unchanged; only 32-byte token hash stored
+2
View File
@@ -0,0 +1,2 @@
python3 tests/smoke.py --base-url "http://api:8080"
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.