diff --git a/evidence/cache_benchmark.txt b/evidence/cache_benchmark.txt index 92cc890..8b8d0fc 100644 --- a/evidence/cache_benchmark.txt +++ b/evidence/cache_benchmark.txt @@ -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. \ No newline at end of file +Difference: p99 −68% (197 → 62 ms), RPS +18%. \ No newline at end of file diff --git a/internal/service/auth.go b/internal/service/auth.go index dc1b84b..d31d638 100644 --- a/internal/service/auth.go +++ b/internal/service/auth.go @@ -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) diff --git a/internal/service/message.go b/internal/service/message.go index 36283a8..13ccb18 100644 --- a/internal/service/message.go +++ b/internal/service/message.go @@ -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