diff --git a/docker/init_scripts/init b/docker/init_scripts/init index fc0617d7a..cf335971b 100755 --- a/docker/init_scripts/init +++ b/docker/init_scripts/init @@ -18,6 +18,11 @@ ENABLE_SYNC_FOLDER_WATCHER="${ENABLE_SYNC_FOLDER_WATCHER:="false"}" # if REDIS_HOST is set, we assume that an external redis is used REDIS_HOST="${REDIS_HOST:=""}" +# snapshot policy of the internal valkey, as " " pairs. Saving +# hourly keeps a graceful shutdown lossless while a hard crash can only lose an +# hour of sessions and cached metadata. Set to an empty value to never snapshot. +REDIS_SAVE_POLICY="${REDIS_SAVE_POLICY:="3600 1"}" + # logger colors RED='\033[0;31m' LIGHTMAGENTA='\033[0;95m' @@ -164,6 +169,16 @@ start_bin_nginx() { start_bin_valkey-server() { info_log "Starting internal valkey" + # Most of the keyspace is bulky, rebuildable metadata (Switch TitleDB, + # LaunchBox), so every snapshot rewrites hundreds of MB of dump.rdb. Valkey's + # stock policy does that every few minutes even on an idle instance, which + # adds up to gigabytes of disk writes per hour. + local -a save_flags=(--save "") + if [[ -n ${REDIS_SAVE_POLICY} ]]; then + # shellcheck disable=SC2206 # each " " token is its own argument + save_flags=(--save ${REDIS_SAVE_POLICY}) + fi + if [[ -f /usr/local/etc/valkey/valkey.conf ]]; then if [[ ${LOGLEVEL} == "DEBUG" ]]; then valkey-server /usr/local/etc/valkey/valkey.conf & @@ -172,9 +187,9 @@ start_bin_valkey-server() { fi else if [[ ${LOGLEVEL} == "DEBUG" ]]; then - valkey-server --dir /redis-data & + valkey-server --dir /redis-data "${save_flags[@]}" & else - valkey-server --dir /redis-data >/dev/null 2>&1 & + valkey-server --dir /redis-data "${save_flags[@]}" >/dev/null 2>&1 & fi fi diff --git a/docs/BACKEND_ARCHITECTURE.md b/docs/BACKEND_ARCHITECTURE.md index d1509c592..81a2c58b5 100644 --- a/docs/BACKEND_ARCHITECTURE.md +++ b/docs/BACKEND_ARCHITECTURE.md @@ -1537,14 +1537,15 @@ Falls back to `FakeRedis` in test mode. #### Redis -| Variable | Default | Description | -| ---------------- | ----------- | --------------------- | -| `REDIS_HOST` | `127.0.0.1` | Redis host | -| `REDIS_PORT` | `6379` | Redis port | -| `REDIS_USERNAME` | | Redis username (ACL) | -| `REDIS_PASSWORD` | | Redis password | -| `REDIS_DB` | `0` | Redis database number | -| `REDIS_SSL` | `false` | Enable SSL | +| Variable | Default | Description | +| ------------------- | ----------- | --------------------------------------------------------------------------- | +| `REDIS_HOST` | `127.0.0.1` | Redis host | +| `REDIS_PORT` | `6379` | Redis port | +| `REDIS_USERNAME` | | Redis username (ACL) | +| `REDIS_PASSWORD` | | Redis password | +| `REDIS_DB` | `0` | Redis database number | +| `REDIS_SSL` | `false` | Enable SSL | +| `REDIS_SAVE_POLICY` | `3600 1` | Internal Valkey snapshot policy, `" "` pairs (empty: off) | #### Authentication diff --git a/env.template b/env.template index c0b61a114..37fe72a78 100644 --- a/env.template +++ b/env.template @@ -22,6 +22,7 @@ REDIS_USERNAME= # Username for the Redis/Valkey instance REDIS_PASSWORD= # Password for the Redis/Valkey instance REDIS_DB=0 # Database number for the Redis/Valkey instance REDIS_SSL=false # Enable SSL (rediss://) for the Redis/Valkey connection +REDIS_SAVE_POLICY=3600 1 # Snapshot policy of the internal Valkey, as " " pairs (empty to never snapshot) # Authentication ROMM_AUTH_SECRET_KEY= # App secret, generate with `openssl rand -hex 32` [REQUIRED]