From fceec6f23e145ca852d9bf5434906c7aa3299926 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Apr 2026 15:39:58 +0000 Subject: [PATCH] feat: improve Redis container performance - Disable RDB persistence (--save "") since Redis is used as a pure cache and lock store; snapshotting causes fork/CoW pressure and I/O spikes - Set --maxmemory-policy allkeys-lru to enable LRU eviction and prevent unbounded memory growth - Enable lazyfree background deletions (--lazyfree-lazy-*) to move key eviction, expiry, and DEL operations off the main event loop thread - Enable active memory defragmentation (--activedefrag yes) for long-running instances - Increase background task frequency to --hz 15 for faster key expiry - Add Transparent Huge Pages (THP) startup warning, consistent with the existing vm.overcommit_memory check - Refactor start.sh to build arguments via a bash array, avoiding eval and safely handling the empty-string --save "" and the password argument - Remove the pre-existing unreachable exec "$@" at the end of start.sh - Add timeout and read_timeout (1.5s) to standalone Redis config in redis.config.php to prevent PHP workers from hanging indefinitely Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/e68c1986-419f-49b4-9cd0-c1f0efda0351 Co-Authored-By: Simon L. Co-Authored-By: szaimen <42591237+szaimen@users.noreply.github.com> --- Containers/nextcloud/config/redis.config.php | 2 ++ Containers/redis/start.sh | 33 +++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Containers/nextcloud/config/redis.config.php b/Containers/nextcloud/config/redis.config.php index 12b5a64b..94bedcf5 100644 --- a/Containers/nextcloud/config/redis.config.php +++ b/Containers/nextcloud/config/redis.config.php @@ -7,6 +7,8 @@ if (getenv('REDIS_MODE') !== 'rediscluster') { if (getenv('REDIS_HOST')) { $CONFIG['redis']['host'] = (string) getenv('REDIS_HOST'); + $CONFIG['redis']['timeout'] = 1.5; + $CONFIG['redis']['read_timeout'] = 1.5; } if (getenv('REDIS_HOST_PASSWORD')) { diff --git a/Containers/redis/start.sh b/Containers/redis/start.sh index 69764c1a..5454e468 100644 --- a/Containers/redis/start.sh +++ b/Containers/redis/start.sh @@ -6,12 +6,31 @@ if [ "$(sysctl -n vm.overcommit_memory)" != "1" ]; then echo "See https://github.com/nextcloud/all-in-one/discussions/1731 how to enable overcommit" fi -# Run redis with a password if provided -echo "Redis has started" -if [ -n "$REDIS_HOST_PASSWORD" ]; then - exec redis-server --requirepass "$REDIS_HOST_PASSWORD" --loglevel warning -else - exec redis-server --loglevel warning +# Warn if Transparent Huge Pages are enabled (causes latency spikes) +if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then + if grep -q '\[always\]' /sys/kernel/mm/transparent_hugepage/enabled; then + echo "WARNING: Transparent Huge Pages (THP) are enabled. This can cause latency and memory issues with Redis." + echo "Consider disabling THP by running: echo never > /sys/kernel/mm/transparent_hugepage/enabled" + fi fi -exec "$@" +# Build the redis-server argument list. +REDIS_ARGS=( + --loglevel warning + --save "" # Disable RDB persistence (Redis is used as a pure cache/lock store) + --maxmemory-policy allkeys-lru # Evict least-recently-used keys when memory is full + --lazyfree-lazy-eviction yes # Perform evictions in a background thread + --lazyfree-lazy-expire yes # Expire keys in a background thread + --lazyfree-lazy-server-del yes # DEL/UNLINK in background thread + --replica-lazy-flush yes # Flush replica dataset in background thread + --activedefrag yes # Reclaim fragmented memory without restart + --hz 15 # Run background tasks 15×/s (default 10) for faster key expiry +) + +if [ -n "$REDIS_HOST_PASSWORD" ]; then + REDIS_ARGS+=(--requirepass "$REDIS_HOST_PASSWORD") +fi + +# Run redis with a password if provided +echo "Redis has started" +exec redis-server "${REDIS_ARGS[@]}"