Files
mtusi2026lab2/evidence/cache-track5.txt
T
2026-11-13 21:16:52 +03:00

53 lines
3.0 KiB
Plaintext

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.