mirror of
https://github.com/nextcloud/all-in-one.git
synced 2026-05-28 06:20:14 +00:00
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. <szaimen@e.mail.de> Co-Authored-By: szaimen <42591237+szaimen@users.noreply.github.com>
This commit is contained in:
committed by
Simon L.
parent
56462e7945
commit
fceec6f23e
@@ -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')) {
|
||||
|
||||
@@ -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[@]}"
|
||||
|
||||
Reference in New Issue
Block a user