From 66236c1a2e5956c42205715d3a0e12abb1d3921a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Apr 2026 13:16:41 +0000 Subject: [PATCH] nextcloud: switch PHP-FPM to dynamic mode and add max_requests to recycle stale workers Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/29135c39-9a45-49bd-85fe-8d3eea344450 Signed-off-by: Simon L. docs: add per-setting inline comments to PHP-FPM sed block in Dockerfile Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/398bb2f7-e5be-4ffc-942a-7ab10dbaa1be Co-Authored-By: szaimen <42591237+szaimen@users.noreply.github.com> --- Containers/nextcloud/Dockerfile | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Containers/nextcloud/Dockerfile b/Containers/nextcloud/Dockerfile index dec33837..1229c001 100644 --- a/Containers/nextcloud/Dockerfile +++ b/Containers/nextcloud/Dockerfile @@ -244,12 +244,27 @@ RUN set -ex; \ imagemagick-tiff \ coreutils; \ \ - grep -q '^pm = dynamic' /usr/local/etc/php-fpm.d/www.conf; \ - sed -i 's/^pm = dynamic/pm = ondemand/' /usr/local/etc/php-fpm.d/www.conf; \ -# Sync this with max db connections and MaxRequestWorkers -# We don't actually expect so many children but don't want to limit it artificially because people will report issues otherwise. -# Also children will usually be terminated again after the process is done due to the ondemand setting +# Use dynamic pm mode: spare workers stay alive between requests so every request is served immediately +# without waiting for a new process to spawn (unlike ondemand which forks on every request when idle). +# pm.max_children: upper bound on worker processes; synced with max DB connections and MaxRequestWorkers. +# Set high so users never hit an artificial limit under peak load — spare-server bounds keep idle memory usage low. sed -i 's/^pm.max_children =.*/pm.max_children = 5000/' /usr/local/etc/php-fpm.d/www.conf; \ +# pm.start_servers: number of workers pre-forked at container startup. +# Having 2 workers ready immediately means the first requests after boot are served without any spawn delay. + sed -i '/^;pm.start_servers/s/^;//' /usr/local/etc/php-fpm.d/www.conf; \ + sed -i 's/^pm.start_servers =.*/pm.start_servers = 2/' /usr/local/etc/php-fpm.d/www.conf; \ +# pm.min_spare_servers: floor of idle workers kept alive at all times. +# Guarantees at least 1 ready worker so a sudden burst of requests is handled without any fork wait. + sed -i '/^;pm.min_spare_servers/s/^;//' /usr/local/etc/php-fpm.d/www.conf; \ + sed -i 's/^pm.min_spare_servers =.*/pm.min_spare_servers = 1/' /usr/local/etc/php-fpm.d/www.conf; \ +# pm.max_spare_servers: ceiling of idle workers kept alive during quiet periods. +# Capping at 3 limits idle memory consumption while still keeping a small ready pool. + sed -i '/^;pm.max_spare_servers/s/^;//' /usr/local/etc/php-fpm.d/www.conf; \ + sed -i 's/^pm.max_spare_servers =.*/pm.max_spare_servers = 3/' /usr/local/etc/php-fpm.d/www.conf; \ +# pm.max_requests: recycle each worker after handling 500 requests. +# PHP extensions and apps can leak memory over time; recycling prevents those leaks from accumulating indefinitely. + sed -i '/^;pm.max_requests/s/^;//' /usr/local/etc/php-fpm.d/www.conf; \ + sed -i 's/^pm.max_requests =.*/pm.max_requests = 500/' /usr/local/etc/php-fpm.d/www.conf; \ sed -i 's|access.log = /proc/self/fd/2|access.log = /proc/self/fd/1|' /usr/local/etc/php-fpm.d/docker.conf; \ \ echo "[ -n \"\$TERM\" ] && [ -f /root.motd ] && cat /root.motd" >> /root/.bashrc; \