set max connections and max php children based on available hardware

Signed-off-by: szaimen <szaimen@e.mail.de>
This commit is contained in:
szaimen 2022-08-17 19:10:54 +02:00
parent b307c39f70
commit 5804f68824
4 changed files with 18 additions and 6 deletions

View file

@ -198,15 +198,17 @@ RUN set -ex; \
git \
postgresql-client \
tzdata \
mawk \
; \
rm -rf /var/lib/apt/lists/*
RUN set -ex; \
grep -q '^pm = dynamic' /usr/local/etc/php-fpm.d/www.conf; \
sed -i 's/^pm.max_children =.*/pm.max_children = 100/' /usr/local/etc/php-fpm.d/www.conf; \
sed -i 's/^pm.start_servers =.*/pm.start_servers = 25/' /usr/local/etc/php-fpm.d/www.conf; \
sed -i 's/^pm.min_spare_servers =.*/pm.min_spare_servers = 25/' /usr/local/etc/php-fpm.d/www.conf; \
sed -i 's/^pm.max_spare_servers =.*/pm.max_spare_servers = 75/' /usr/local/etc/php-fpm.d/www.conf
sed -i 's/^pm = dynamic/pm = ondemand/' /usr/local/etc/php-fpm.d/www.conf; \
sed -i 's/^pm.max_children =.*/pm.max_children = ${PHP_MAX_CHILDREN}/' /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; \
sed -i 's/^pm.min_spare_servers =.*/pm.min_spare_servers = 1/' /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
RUN set -ex; \
rm -rf /tmp/nextcloud-aio && \

View file

@ -10,7 +10,7 @@ directory_empty() {
[ -z "$(ls -A "$1/")" ]
}
echo "Configuring Redis as session handler"
echo "Configuring Redis as session handler..."
cat << REDIS_CONF > /usr/local/etc/php/conf.d/redis-session.ini
session.save_handler = redis
session.save_path = "tcp://${REDIS_HOST}:${REDIS_HOST_PORT:=6379}?auth=${REDIS_HOST_PASSWORD}"
@ -21,6 +21,11 @@ redis.session.lock_retries = -1
redis.session.lock_wait_time = 10000
REDIS_CONF
echo "Setting php max children..."
MEMORY=$(mawk '/MemTotal/ {printf "%d", $2/1024}' /proc/meminfo)
PHP_MAX_CHILDREN=$((MEMORY/50))
export PHP_MAX_CHILDREN
# Check permissions in ncdata
touch "/mnt/ncdata/this-is-a-test-file"
if ! [ -f "/mnt/ncdata/this-is-a-test-file" ]; then

View file

@ -1,7 +1,7 @@
# From https://github.com/docker-library/postgres/blob/master/13/alpine/Dockerfile
FROM postgres:14.5-alpine
RUN apk add --update --no-cache bash openssl shadow netcat-openbsd grep
RUN apk add --update --no-cache bash openssl shadow netcat-openbsd grep mawk
# We need to use the same gid and uid as on old installations
RUN set -ex; \

View file

@ -110,6 +110,11 @@ if ! [ -f "$DATADIR/PG_VERSION" ] && ! [ -f "$DUMP_FILE" ]; then
rm -rf "${DATADIR:?}/"*
fi
echo "Setting max connections..."
MEMORY=$(mawk '/MemTotal/ {printf "%d", $2/1024}' /proc/meminfo)
MAX_CONNECTIONS=$((MEMORY/50+3))
sed -i "s|^max_connections =.*|max_connections = $MAX_CONNECTIONS|" "/var/lib/postgresql/data/postgresql.conf"
# Catch docker stop attempts
trap 'true' SIGINT SIGTERM