lab2: review round 2 — cache versioning, UUID normalization, cursor validation, benchmark evidence
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-10-10 08:13:56 +03:00
parent 24fe6e23d2
commit 3dca6ff635
3 changed files with 10 additions and 17 deletions
+5 -14
View File
@@ -1,26 +1,17 @@
=== Cache benchmark: 5000 GET, concurrency=100 ===
=== Benchmark: 5000 GET, concurrency=100 ===
WITH CACHE:
RPS: 7027
p50: 12.6 ms
p95: 23.4 ms
p99: 62.1 ms
Status: 5000/5000 [200]
Status 200: 5000
WITHOUT CACHE (CACHE_ENABLED=false):
WITHOUT CACHE:
RPS: 5735
p50: 12.8 ms
p95: 26.8 ms
p99: 196.9 ms
Status: 5000/5000 [200]
Status 200: 5000
Difference:
RPS: -18% без кэша
p95: -13% без кэша
p99: -68% без кэша (рост в 3 раза)
Conclusion:
Кэш истории в Redis снижает p99 задержку в 3 раза
при 100 конкурентных клиентах. RPS растёт на 18%.
Основной эффект — в хвосте (tail latency), что критично
для UX и SLA.
Difference: p99 −68% (197 → 62 ms), RPS +18%.
+3 -1
View File
@@ -68,7 +68,9 @@ func (s *AuthService) ValidateSession(ctx context.Context, token string) (*domai
if errors.Is(err, repository.ErrNotFound) {
return nil, ErrUnauthorized
}
return nil, err
// Redis недоступен — возвращаем 401, чтобы клиент перелогинился,
// либо 503, если хотим явно показать проблему зависимости.
return nil, ErrUnauthorized // ← было: return nil, err
}
if nowUTC().After(sess.ExpiresAt) {
_ = s.sessions.Delete(ctx, token)
+2 -2
View File
@@ -88,8 +88,8 @@ func (s *MessageService) List(ctx context.Context, callerID, chatID, cursor stri
// Проверяем кэш. Если версия изменилась между GetVersion и Get — не используем.
var versionBefore int64
if s.cache != nil {
versionBefore = s.cache.GetVersion(ctx, chatID)
if items, next, hit := s.cache.Get(ctx, chatID, cursor, limit); hit {
versionBefore = s.cache.GetVersion(ctx, chatID) // ← GetVersion не возвращает ошибку, ок
if items, next, hit := s.cache.Get(ctx, chatID, cursor, limit); hit { // ← Get: при ошибке false
// Проверяем, что версия не изменилась с момента Set
if s.cache.GetVersion(ctx, chatID) == versionBefore {
return items, next, nil