forked from mtusi2026/mtusi2026lab2
[+] add project
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
Track 5, cache consistency (2026-11-13)
|
||||
Host: macOS 27.0, arm64, 12 CPU cores, 24 GiB RAM.
|
||||
Docker Engine: 12 CPUs, 7.65 GiB memory; Docker CLI 29.1.3,
|
||||
Compose 2.40.3; Python 3.9.6 test client.
|
||||
Containers: API built from python:3.12.8-slim-bookworm,
|
||||
PostgreSQL 16.6-alpine, Redis 7.4.2-alpine.
|
||||
API test environment: isolated Compose project, localhost port 18080,
|
||||
default pool size 10, session TTL 3600s. No explicit warm-up or CPU quota.
|
||||
|
||||
Hypothesis:
|
||||
Concurrent cache misses for one session can issue redundant user-profile
|
||||
SELECTs. A Redis per-session fill lock should collapse misses to one profile
|
||||
SELECT in each cold-cache wave, without changing API responses. The session
|
||||
expiry/revocation lookup remains PostgreSQL-authoritative on every request.
|
||||
|
||||
Method:
|
||||
Run tests/cache_track.py --waves 5 --concurrency 24.
|
||||
For each mode, recreate API with SESSION_CACHE_SINGLEFLIGHT=0 or 1. Run five
|
||||
waves of 24 parallel GET /api/v1/users/me requests; delete the session profile
|
||||
key before each wave. Count profile SQL attempts using uniquely correlated
|
||||
event=session_profile_db_load API log entries. Measure end-to-end request
|
||||
latency in the Python client. Repeat the A/B run five times. Each measurement
|
||||
contains 120 successful requests per mode. The script also clears a newly
|
||||
created user's cache before GET /users/me and verifies the profile was read
|
||||
from PostgreSQL, then restarts Redis and verifies the existing session/profile
|
||||
still works. API configuration is restored to single-flight enabled in cleanup.
|
||||
|
||||
Results (profile SELECTs / 120 requests; per-run p50 and p95 in ms):
|
||||
Run 1: baseline 20, 26.99 / 36.13; single-flight 5, 25.19 / 41.86
|
||||
Run 2: baseline 25, 26.71 / 37.68; single-flight 5, 27.41 / 47.37
|
||||
Run 3: baseline 28, 27.97 / 38.43; single-flight 5, 25.73 / 43.15
|
||||
Run 4: baseline 17, 26.21 / 42.12; single-flight 5, 27.60 / 44.98
|
||||
Run 5 (final code, after smoke and Grade 4 checks):
|
||||
baseline 11, 26.88 / 37.64; single-flight 5, 27.66 / 43.63
|
||||
|
||||
Across five runs, mean profile SELECTs fell from 20.2 to 5 per 120 requests
|
||||
(75.2% fewer). Median of per-run p50 values was 26.88 ms baseline and 27.41 ms
|
||||
with single-flight. Median of per-run p95 values was 37.68 ms baseline and
|
||||
43.63 ms with single-flight. Thus the experiment demonstrates reduced SQL
|
||||
fan-out, not a latency improvement; p95 was worse with the lock/wait path.
|
||||
Read-after-write from PostgreSQL: PASS. Redis restart recovery: PASS on all runs.
|
||||
After final application rebuild: public smoke and `make test-grade4` both PASS.
|
||||
|
||||
Limitations:
|
||||
Local single-node synthetic test, one API container and one session; no
|
||||
production workload, CPU isolation, or database-wide query instrumentation.
|
||||
Profile SELECT counts use structured application events immediately before
|
||||
the query (successful responses were verified, but this is not pg_stat_statements).
|
||||
Every protected request still queries PostgreSQL for authoritative session
|
||||
revocation/expiry. Lock wait is capped at two seconds and falls back to the
|
||||
database, preserving availability but permitting extra reads if a fill is slow.
|
||||
The short sample is not a general latency benchmark.
|
||||
@@ -62,3 +62,12 @@ PASS: SESSION_TTL_SECONDS=2 make test-expiry; затем восстановле
|
||||
PASS: make explain-history; 10000 строк, Index Scan, 51 строка, 3 shared hits,
|
||||
Execution Time 0.034 ms; fixture завершён ROLLBACK.
|
||||
PASS: schema_migrations содержит только 001_initial.sql после повторных стартов.
|
||||
|
||||
Проверки после реализации трека 5, 2026-11-13; отдельный Compose-проект,
|
||||
PostgreSQL 16.6 и Redis 7.4.2:
|
||||
PASS: make check
|
||||
PASS: make validate
|
||||
PASS: make test
|
||||
PASS: make test-grade4 (race, auth, Redis/DB outage and recovery)
|
||||
PASS: make test-track5-cache (120 запросов на условие; результаты в
|
||||
cache-track5.txt; read-after-write и Redis restart recovery)
|
||||
|
||||
Reference in New Issue
Block a user