From f63e801608768957c86e7da9df8d3405b00cc22d Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sat, 25 Jun 2022 09:00:59 +0000 Subject: [PATCH] auto scale uwsgi workers based on load --- docker/containers/tactical/entrypoint.sh | 20 ++++++++++---------- install.sh | 22 +++++++++++----------- restore.sh | 23 +++++++++++------------ update.sh | 22 +++++++++++----------- 4 files changed, 43 insertions(+), 44 deletions(-) diff --git a/docker/containers/tactical/entrypoint.sh b/docker/containers/tactical/entrypoint.sh index 13855444..22fd1a29 100644 --- a/docker/containers/tactical/entrypoint.sh +++ b/docker/containers/tactical/entrypoint.sh @@ -111,22 +111,12 @@ EOF echo "${localvars}" > ${TACTICAL_DIR}/api/tacticalrmm/local_settings.py - numprocs=$(nproc) - uwsgiprocs=4 - if [[ "$numprocs" == "1" ]]; then - uwsgiprocs=2 - else - uwsgiprocs=$numprocs - fi - uwsgiconf="$(cat << EOF [uwsgi] chdir = /opt/tactical/api module = tacticalrmm.wsgi home = /opt/venv master = true -processes = ${uwsgiprocs} -threads = ${uwsgiprocs} enable-threads = true socket = 0.0.0.0:8080 harakiri = 300 @@ -136,6 +126,16 @@ vacuum = true die-on-term = true max-requests = 500 disable-logging = true +cheaper-algo = busyness +cheaper = 4 +cheaper-initial = 4 +workers = 20 +cheaper-step = 2 +cheaper-overload = 3 +cheaper-busyness-min = 5 +cheaper-busyness-max = 10 +# stats = /tmp/stats.socket # uncomment when debugging +# cheaper-busyness-verbose = true # uncomment when debugging EOF )" diff --git a/install.sh b/install.sh index 65a3fe2a..cf7774e2 100644 --- a/install.sh +++ b/install.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -SCRIPT_VERSION="63" +SCRIPT_VERSION="64" SCRIPT_URL='https://raw.githubusercontent.com/amidaware/tacticalrmm/master/install.sh' sudo apt install -y curl wget dirmngr gnupg lsb-release @@ -382,22 +382,12 @@ python manage.py generate_barcode ${RANDBASE} ${djangousername} ${frontenddomain deactivate read -n 1 -s -r -p "Press any key to continue..." -echo 'Optimizing for number of processors' -uwsgiprocs=4 -if [[ "$numprocs" == "1" ]]; then - uwsgiprocs=2 -else - uwsgiprocs=$numprocs -fi - uwsgini="$(cat << EOF [uwsgi] chdir = /rmm/api/tacticalrmm module = tacticalrmm.wsgi home = /rmm/api/env master = true -processes = ${uwsgiprocs} -threads = ${uwsgiprocs} enable-threads = true socket = /rmm/api/tacticalrmm/tacticalrmm.sock harakiri = 300 @@ -407,6 +397,16 @@ vacuum = true die-on-term = true max-requests = 500 disable-logging = true +cheaper-algo = busyness +cheaper = 4 +cheaper-initial = 4 +workers = 20 +cheaper-step = 2 +cheaper-overload = 3 +cheaper-busyness-min = 5 +cheaper-busyness-max = 10 +# stats = /tmp/stats.socket # uncomment when debugging +# cheaper-busyness-verbose = true # uncomment when debugging EOF )" echo "${uwsgini}" > /rmm/api/tacticalrmm/app.ini diff --git a/restore.sh b/restore.sh index 64164a3b..8e44b5df 100755 --- a/restore.sh +++ b/restore.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -SCRIPT_VERSION="37" +SCRIPT_VERSION="38" SCRIPT_URL='https://raw.githubusercontent.com/amidaware/tacticalrmm/master/restore.sh' sudo apt update @@ -245,23 +245,12 @@ npm install meshcentral@${MESH_VER} print_green 'Restoring the backend' -echo 'Optimize for number of processors' -numprocs=$(nproc) -uwsgiprocs=4 -if [[ "$numprocs" == "1" ]]; then - uwsgiprocs=2 -else - uwsgiprocs=$numprocs -fi - uwsgini="$(cat << EOF [uwsgi] chdir = /rmm/api/tacticalrmm module = tacticalrmm.wsgi home = /rmm/api/env master = true -processes = ${uwsgiprocs} -threads = ${uwsgiprocs} enable-threads = true socket = /rmm/api/tacticalrmm/tacticalrmm.sock harakiri = 300 @@ -271,6 +260,16 @@ vacuum = true die-on-term = true max-requests = 500 disable-logging = true +cheaper-algo = busyness +cheaper = 4 +cheaper-initial = 4 +workers = 20 +cheaper-step = 2 +cheaper-overload = 3 +cheaper-busyness-min = 5 +cheaper-busyness-max = 10 +# stats = /tmp/stats.socket # uncomment when debugging +# cheaper-busyness-verbose = true # uncomment when debugging EOF )" echo "${uwsgini}" > /rmm/api/tacticalrmm/app.ini diff --git a/update.sh b/update.sh index 2635109b..976c41d3 100644 --- a/update.sh +++ b/update.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -SCRIPT_VERSION="135" +SCRIPT_VERSION="136" SCRIPT_URL='https://raw.githubusercontent.com/amidaware/tacticalrmm/master/update.sh' LATEST_SETTINGS_URL='https://raw.githubusercontent.com/amidaware/tacticalrmm/master/api/tacticalrmm/tacticalrmm/settings.py' YELLOW='\033[1;33m' @@ -114,22 +114,12 @@ done rm -f /rmm/api/tacticalrmm/app.ini -numprocs=$(nproc) -uwsgiprocs=4 -if [[ "$numprocs" == "1" ]]; then - uwsgiprocs=2 -else - uwsgiprocs=$numprocs -fi - uwsgini="$(cat << EOF [uwsgi] chdir = /rmm/api/tacticalrmm module = tacticalrmm.wsgi home = /rmm/api/env master = true -processes = ${uwsgiprocs} -threads = ${uwsgiprocs} enable-threads = true socket = /rmm/api/tacticalrmm/tacticalrmm.sock harakiri = 300 @@ -139,6 +129,16 @@ vacuum = true die-on-term = true max-requests = 500 disable-logging = true +cheaper-algo = busyness +cheaper = 4 +cheaper-initial = 4 +workers = 20 +cheaper-step = 2 +cheaper-overload = 3 +cheaper-busyness-min = 5 +cheaper-busyness-max = 10 +# stats = /tmp/stats.socket # uncomment when debugging +# cheaper-busyness-verbose = true # uncomment when debugging EOF )" echo "${uwsgini}" > /rmm/api/tacticalrmm/app.ini