fix memory usage redis

This commit is contained in:
Mateusz Gruszczyński
2026-08-16 22:43:06 +02:00
parent 40474cdc59
commit 074d17be89
22 changed files with 1377 additions and 382 deletions
+17 -5
View File
@@ -88,6 +88,9 @@ class Config:
session_hours: int
session_cookie_secure: bool
analytics_snapshot_interval_seconds: int
traffic_archive_interval_seconds: int
traffic_archive_lag_seconds: int
traffic_archive_batch_size: int
redis_url: str
redis_managed: bool
redis_data_dir: str
@@ -194,15 +197,20 @@ class Config:
analytics_snapshot_interval_seconds=max(
15, _int("ANALYTICS_SNAPSHOT_INTERVAL_SECONDS", 60)
),
traffic_archive_interval_seconds=max(1, _int("TRAFFIC_ARCHIVE_INTERVAL_SECONDS", 5)),
traffic_archive_lag_seconds=max(2, _int("TRAFFIC_ARCHIVE_LAG_SECONDS", 10)),
traffic_archive_batch_size=max(100, min(5000, _int("TRAFFIC_ARCHIVE_BATCH_SIZE", 1000))),
redis_url=os.getenv("REDIS_URL", "redis://127.0.0.1:6379/0"),
redis_managed=_bool("REDIS_MANAGED", True),
redis_data_dir=os.getenv("REDIS_DATA_DIR", "/data/redis"),
redis_port=_int("REDIS_PORT", 6379),
# Managed Redis is the sole traffic-history store. Do not evict by
# count/memory; retention time is the authoritative bound.
redis_maxmemory_mb=0,
redis_snapshot_seconds=_int("REDIS_SNAPSHOT_SECONDS", 1800),
redis_aof=_bool("REDIS_AOF", True),
# Redis is only a short-lived ingestion buffer. Keep a hard memory
# ceiling so a stalled archive worker cannot trigger host OOMK.
redis_maxmemory_mb=max(32, _int("REDIS_MAXMEMORY_MB", 128) or 128),
# Durable history lives in SQLite, so Redis persistence is optional
# and disabled by default to avoid RDB/AOF fork memory spikes.
redis_snapshot_seconds=max(0, _int("REDIS_SNAPSHOT_SECONDS", 0)),
redis_aof=_bool("REDIS_AOF", False),
traffic_retention_hours=_int("TRAFFIC_RETENTION_HOURS", 24),
traffic_max_events=0,
traffic_memory_events=0,
@@ -257,8 +265,12 @@ class Config:
"admin_username": self.admin_username,
"session_hours": self.session_hours,
"analytics_snapshot_interval_seconds": self.analytics_snapshot_interval_seconds,
"traffic_archive_interval_seconds": self.traffic_archive_interval_seconds,
"traffic_archive_lag_seconds": self.traffic_archive_lag_seconds,
"traffic_archive_batch_size": self.traffic_archive_batch_size,
"traffic_retention_hours": self.traffic_retention_hours,
"redis_managed": self.redis_managed,
"redis_maxmemory_mb": self.redis_maxmemory_mb,
"redis_snapshot_seconds": self.redis_snapshot_seconds,
"redis_aof": self.redis_aof,
"traffic_max_events": self.traffic_max_events,