Skip to content

Instantly share code, notes, and snippets.

@arturAtDeliveroo
arturAtDeliveroo / pr1136-URGENT-performance-fix.txt
Created October 31, 2025 10:24
PR #1136 URGENT: Async update + deep copy kill performance
# PR #1136 - CRITICAL Performance Issues
## Problem Statement
- Connections increased 4-5x
- Hit rate only 65% (expected: 95%+)
- Cache latency 80ms (expected: microseconds)
## Root Causes Found
### 🔥 CRITICAL #1: Async Cache Update (lines 355-358)
@arturAtDeliveroo
arturAtDeliveroo / pr1136-fix1-double-counting.patch
Created October 31, 2025 10:12
PR #1136 fixes: 1) Double-counting, 2) Metric consistency, 3) Atomic memory
--- a/pkg/redisconn/generic_swr_cache.go
+++ b/pkg/redisconn/generic_swr_cache.go
@@ -213,10 +213,9 @@ func (c *GenericSWRCache) GetBulk(keys []string) (results map[string]*GenericCac
}
// Check if entry is invalid (> InvalidAfterSeconds)
if !entry.IsValid(invalidAfter) {
// Invalid entries are treated as missing - must fetch from Redis
missing = append(missing, key)
- misses++
@arturAtDeliveroo
arturAtDeliveroo / enhanced_metrics.go
Created October 29, 2025 17:01
SWR Cache: Global Queue Deduplication + Enhanced Memory Metrics by State
// File: pkg/redisconn/generic_swr_cache.go
// Surgical change: Add memory breakdown metrics by cache state
// In reportDataFreshness method (around line 808), REPLACE entire function:
func (c *GenericSWRCache) reportDataFreshness() {
now := time.Now()
staleThreshold := time.Duration(c.config.StaleAfterSeconds) * time.Second
invalidThreshold := time.Duration(c.config.InvalidAfterSeconds) * time.Second
zombieThreshold := 5 * time.Minute
@arturAtDeliveroo
arturAtDeliveroo / config_changes.go
Created October 29, 2025 15:12
Surgical SWR Cache Fixes - Three-State Logic with Deduplication
// File: app/config/config.go
// Changes: Add InvalidAfterSeconds field, adjust StaleAfterSeconds default
type GenericCache struct {
MaxMemoryMB int `envconfig:"CACHE_MAX_MEMORY_MB" default:"300"`
// StaleAfterSeconds: Time after which cached data is stale (served instantly, queued for refresh)
// Default: 5 seconds
StaleAfterSeconds int `envconfig:"CACHE_STALE_AFTER_SECONDS" default:"5"`