Check that worker_processes will not occupy more than half of RAM

This commit is contained in:
Evgeniy Antonyuk 2024-01-19 17:54:27 +07:00
parent 71d343c016
commit 024d937ee0
1 changed files with 6 additions and 1 deletions

View File

@ -33,6 +33,7 @@ DOCKER_ENABLED=${DOCKER_ENABLED:-true};
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
NGINX_CONF_DIR="/etc/nginx/sites-enabled"
CPU_PROCESSOR_COUNT=${CPU_PROCESSOR_COUNT:-$(cat /proc/cpuinfo | grep -i processor | awk '{print $1}' | grep -i processor | wc -l)};
RANDOM_ACCESS_MEMORY=$(free -k | awk '/^Mem:/ {print $2}')
NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-$(ulimit -n)};
SERVICE_SSO_AUTH_HOST_ADDR=${SERVICE_SSO_AUTH_HOST_ADDR:-${CONTROL_PANEL_PORT_80_TCP_ADDR}};
DEFAULT_APP_CORE_MACHINEKEY="$(sudo sed -n '/"core.machinekey"/s!.*value\s*=\s*"\([^"]*\)".*!\1!p' ${APP_ROOT_DIR}/web.appsettings.config)";
@ -286,7 +287,11 @@ fi
cp ${NGINX_ROOT_DIR}/includes/onlyoffice-communityserver-nginx.conf.template ${NGINX_ROOT_DIR}/nginx.conf
sed 's/^worker_processes.*/'"worker_processes ${CPU_PROCESSOR_COUNT};"'/' -i ${NGINX_ROOT_DIR}/nginx.conf
# Check that worker_processes will not occupy more than half of RAM
NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-$((RANDOM_ACCESS_MEMORY / 2 < NGINX_WORKER_CONNECTIONS * CPU_PROCESSOR_COUNT ? RANDOM_ACCESS_MEMORY / 1048576 / 2 : CPU_PROCESSOR_COUNT))};
NGINX_WORKER_PROCESSES=$((NGINX_WORKER_PROCESSES < 1 ? 1 : NGINX_WORKER_PROCESSES))
sed 's/^worker_processes.*/'"worker_processes ${NGINX_WORKER_PROCESSES};"'/' -i ${NGINX_ROOT_DIR}/nginx.conf
sed 's/worker_connections.*/'"worker_connections ${NGINX_WORKER_CONNECTIONS};"'/' -i ${NGINX_ROOT_DIR}/nginx.conf
cp ${NGINX_ROOT_DIR}/includes/onlyoffice-communityserver-common-init.conf.template ${NGINX_CONF_DIR}/onlyoffice